diff --git a/README.md b/README.md index b4afb5a3d5..54b510765e 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,6 @@ A Clojure library designed to ... well, that part is up to you. adb reverse tcp:3449 tcp:3449 react-native run-android ->>>>>>> origin/develop ## License diff --git a/figwheel-bridge.js b/figwheel-bridge.js index 137673ca19..2a7cb1cc2f 100644 --- a/figwheel-bridge.js +++ b/figwheel-bridge.js @@ -5,7 +5,6 @@ */ var CLOSURE_UNCOMPILED_DEFINES = null; -var debugEnabled = false; var config = { basePath: "target/", @@ -14,24 +13,13 @@ var config = { }; var React = require('react-native'); -var WebSocket = require('WebSocket'); var self; var scriptQueue = []; var serverHost = null; // will be set dynamically var fileBasePath = null; // will be set dynamically var evaluate = eval; // This is needed, direct calls to eval does not work (RN packager???) var externalModules = {}; -var evalListeners = [ // Functions to be called after each js file is loaded and evaluated - function (url) { - if (url.indexOf('jsloader') > -1) { - shimJsLoader(); - } - }, - function (url) { - if (url.indexOf('/figwheel/client/socket') > -1) { - setCorrectWebSocketImpl(); - } - }]; +var evalListeners = []; // functions to be called when a script is evaluated var figwheelApp = function (platform, devHost) { return React.createClass({ @@ -52,7 +40,7 @@ var figwheelApp = function (platform, devHost) { componentDidMount: function () { var app = this; if (typeof goog === "undefined") { - loadApp(platform, devHost, function (appRoot) { + loadApp(platform, devHost, function(appRoot) { app.setState({root: appRoot, loaded: true}) }); } @@ -60,19 +48,13 @@ var figwheelApp = function (platform, devHost) { }) }; -function logDebug(msg) { - if (debugEnabled) { - console.log(msg); - } -} - // evaluates js code ensuring proper ordering function customEval(url, javascript, success, error) { if (scriptQueue.length > 0) { if (scriptQueue[0] === url) { try { evaluate(javascript); - logDebug('Evaluated: ' + url); + console.info('Evaluated: ' + url); scriptQueue.shift(); evalListeners.forEach(function (listener) { listener(url) @@ -99,7 +81,7 @@ var isChrome = function () { }; function asyncImportScripts(url, success, error) { - logDebug('(asyncImportScripts) Importing: ' + url); + console.info('(asyncImportScripts) Importing: ' + url); scriptQueue.push(url); fetch(url) .then(function (response) { @@ -118,7 +100,7 @@ function asyncImportScripts(url, success, error) { function syncImportScripts(url, success, error) { try { importScripts(url); - logDebug('Evaluated: ' + url); + console.info('Evaluated: ' + url); evalListeners.forEach(function (listener) { listener(url) }); @@ -141,7 +123,7 @@ function importJs(src, success, error) { var file = fileBasePath + '/' + src; - logDebug('(importJs) Importing: ' + file); + console.info('(importJs) Importing: ' + file); if (isChrome()) { syncImportScripts(serverBaseUrl("localhost") + '/' + file, success, error); } else { @@ -161,49 +143,43 @@ function interceptRequire() { }; } -function compileWarningsToYellowBox() { - var log = window.console.log; - var compileWarningRx = /Figwheel: Compile/; - window.console.log = function (msg) { - if (compileWarningRx.test(msg)) { - console.warn(msg); - } else { - log.apply(window.console, arguments); - } - }; +// do not show debug messages in yellow box +function debugToLog() { + console.debug = console.log; } function serverBaseUrl(host) { return "http://" + host + ":" + config.serverPort } -function setCorrectWebSocketImpl() { - figwheel.client.socket.get_websocket_imp = function () { - return WebSocket; - }; -} - function loadApp(platform, devHost, onLoadCb) { serverHost = devHost; fileBasePath = config.basePath + platform; + evalListeners.push(function (url) { + if (url.indexOf('jsloader') > -1) { + shimJsLoader(); + } + }); + // callback when app is ready to get the reloadable component var mainJs = '/env/' + platform + '/main.js'; evalListeners.push(function (url) { if (url.indexOf(mainJs) > -1) { onLoadCb(env[platform].main.root_el); - console.info('Done loading Clojure app'); + console.log('Done loading Clojure app'); } }); if (typeof goog === "undefined") { - console.info('Loading Closure base.'); + console.log('Loading Closure base.'); interceptRequire(); - compileWarningsToYellowBox(); importJs('goog/base.js', function () { shimBaseGoog(); + fakeLocalStorageAndDocument(); importJs('cljs_deps.js'); importJs('goog/deps.js', function () { + debugToLog(); // This is needed because of RN packager // seriously React packager? why. var googreq = goog.require; @@ -233,6 +209,39 @@ function shimBaseGoog() { importJs(src); return true; }; + goog.inHtmlDocument_ = function () { + return true; + }; +} + +function fakeLocalStorageAndDocument() { + window.localStorage = {}; + window.localStorage.getItem = function () { + return 'true'; + }; + window.localStorage.setItem = function () { + }; + + window.document = {}; + window.document.body = {}; + window.document.body.dispatchEvent = function () { + }; + window.document.createElement = function () { + }; + + if (typeof window.location === 'undefined') { + window.location = {}; + } + console.debug = console.warn; + window.addEventListener = function () { + }; + // make figwheel think that heads-up-display divs are there + window.document.querySelector = function (selector) { + return {}; + }; + window.document.getElementById = function (id) { + return {style:{}}; + }; } // Figwheel fixes diff --git a/src/syng_im/components/carousel.cljs b/src/syng_im/components/carousel.cljs index 1c2c4e495d..5c5904f0f0 100644 --- a/src/syng_im/components/carousel.cljs +++ b/src/syng_im/components/carousel.cljs @@ -56,11 +56,10 @@ gap (get-gap state) page-offset (+ prop-page-width gap) current-position (get-current-position event) - direction (if (> current-position (+ starting-position scroll-threshold)) - 1 - (if (< current-position (- starting-position scroll-threshold)) - -1 - 0)) + direction (cond + (> current-position (+ starting-position scroll-threshold)) 1 + (< current-position (- starting-position scroll-threshold)) -1 + :else 0) current-page (+ (quot starting-position page-offset) direction) ] (log/debug "on-scroll-end: prop-page-width=" prop-page-width @@ -133,10 +132,8 @@ :bounces false :decelerationRate 0.9 :horizontal true - :onScrollBeginDrag (fn [event] - (let [] - (reset! starting-position (get-current-position event)))) - :onScrollEndDrag (fn [event] (on-scroll-end event component @starting-position)) + :onScrollBeginDrag #(reset! starting-position (get-current-position %)) + :onScrollEndDrag #(on-scroll-end % component @starting-position) :showsHorizontalScrollIndicator false :ref (fn [c] (set! (.-scrollView component) c)) } diff --git a/src/syng_im/persistence/realm.cljs b/src/syng_im/persistence/realm.cljs index ad0f070b8b..0770a8f2e4 100644 --- a/src/syng_im/persistence/realm.cljs +++ b/src/syng_im/persistence/realm.cljs @@ -1,5 +1,6 @@ (ns syng-im.persistence.realm (:require [cljs.reader :refer [read-string]] + [syng-im.utils.logging :as log] [syng-im.utils.types :refer [to-string]]) (:refer-clojure :exclude [exists?])) @@ -147,7 +148,7 @@ (.-length objs)) (defn get-list [schema-name] - (vals (js->clj (.slice (.objects realm (to-string schema-name)) 0) :keywordize-keys true))) + (vals (js->clj (.objects realm (to-string schema-name)) :keywordize-keys true))) (comment