Revert figwheel-bridge.js. Applied suggestions.

Former-commit-id: d009f038e5
This commit is contained in:
Adrian Tiberius 2016-05-07 15:13:03 +03:00
parent 04cc73b068
commit 765e80f0a1
4 changed files with 60 additions and 54 deletions

View File

@ -31,7 +31,6 @@ A Clojure library designed to ... well, that part is up to you.
adb reverse tcp:3449 tcp:3449 adb reverse tcp:3449 tcp:3449
react-native run-android react-native run-android
>>>>>>> origin/develop
## License ## License

View File

@ -5,7 +5,6 @@
*/ */
var CLOSURE_UNCOMPILED_DEFINES = null; var CLOSURE_UNCOMPILED_DEFINES = null;
var debugEnabled = false;
var config = { var config = {
basePath: "target/", basePath: "target/",
@ -14,24 +13,13 @@ var config = {
}; };
var React = require('react-native'); var React = require('react-native');
var WebSocket = require('WebSocket');
var self; var self;
var scriptQueue = []; var scriptQueue = [];
var serverHost = null; // will be set dynamically var serverHost = null; // will be set dynamically
var fileBasePath = 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 evaluate = eval; // This is needed, direct calls to eval does not work (RN packager???)
var externalModules = {}; var externalModules = {};
var evalListeners = [ // Functions to be called after each js file is loaded and evaluated var evalListeners = []; // functions to be called when a script is evaluated
function (url) {
if (url.indexOf('jsloader') > -1) {
shimJsLoader();
}
},
function (url) {
if (url.indexOf('/figwheel/client/socket') > -1) {
setCorrectWebSocketImpl();
}
}];
var figwheelApp = function (platform, devHost) { var figwheelApp = function (platform, devHost) {
return React.createClass({ return React.createClass({
@ -52,7 +40,7 @@ var figwheelApp = function (platform, devHost) {
componentDidMount: function () { componentDidMount: function () {
var app = this; var app = this;
if (typeof goog === "undefined") { if (typeof goog === "undefined") {
loadApp(platform, devHost, function (appRoot) { loadApp(platform, devHost, function(appRoot) {
app.setState({root: appRoot, loaded: true}) 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 // evaluates js code ensuring proper ordering
function customEval(url, javascript, success, error) { function customEval(url, javascript, success, error) {
if (scriptQueue.length > 0) { if (scriptQueue.length > 0) {
if (scriptQueue[0] === url) { if (scriptQueue[0] === url) {
try { try {
evaluate(javascript); evaluate(javascript);
logDebug('Evaluated: ' + url); console.info('Evaluated: ' + url);
scriptQueue.shift(); scriptQueue.shift();
evalListeners.forEach(function (listener) { evalListeners.forEach(function (listener) {
listener(url) listener(url)
@ -99,7 +81,7 @@ var isChrome = function () {
}; };
function asyncImportScripts(url, success, error) { function asyncImportScripts(url, success, error) {
logDebug('(asyncImportScripts) Importing: ' + url); console.info('(asyncImportScripts) Importing: ' + url);
scriptQueue.push(url); scriptQueue.push(url);
fetch(url) fetch(url)
.then(function (response) { .then(function (response) {
@ -118,7 +100,7 @@ function asyncImportScripts(url, success, error) {
function syncImportScripts(url, success, error) { function syncImportScripts(url, success, error) {
try { try {
importScripts(url); importScripts(url);
logDebug('Evaluated: ' + url); console.info('Evaluated: ' + url);
evalListeners.forEach(function (listener) { evalListeners.forEach(function (listener) {
listener(url) listener(url)
}); });
@ -141,7 +123,7 @@ function importJs(src, success, error) {
var file = fileBasePath + '/' + src; var file = fileBasePath + '/' + src;
logDebug('(importJs) Importing: ' + file); console.info('(importJs) Importing: ' + file);
if (isChrome()) { if (isChrome()) {
syncImportScripts(serverBaseUrl("localhost") + '/' + file, success, error); syncImportScripts(serverBaseUrl("localhost") + '/' + file, success, error);
} else { } else {
@ -161,49 +143,43 @@ function interceptRequire() {
}; };
} }
function compileWarningsToYellowBox() { // do not show debug messages in yellow box
var log = window.console.log; function debugToLog() {
var compileWarningRx = /Figwheel: Compile/; console.debug = console.log;
window.console.log = function (msg) {
if (compileWarningRx.test(msg)) {
console.warn(msg);
} else {
log.apply(window.console, arguments);
}
};
} }
function serverBaseUrl(host) { function serverBaseUrl(host) {
return "http://" + host + ":" + config.serverPort return "http://" + host + ":" + config.serverPort
} }
function setCorrectWebSocketImpl() {
figwheel.client.socket.get_websocket_imp = function () {
return WebSocket;
};
}
function loadApp(platform, devHost, onLoadCb) { function loadApp(platform, devHost, onLoadCb) {
serverHost = devHost; serverHost = devHost;
fileBasePath = config.basePath + platform; fileBasePath = config.basePath + platform;
evalListeners.push(function (url) {
if (url.indexOf('jsloader') > -1) {
shimJsLoader();
}
});
// callback when app is ready to get the reloadable component // callback when app is ready to get the reloadable component
var mainJs = '/env/' + platform + '/main.js'; var mainJs = '/env/' + platform + '/main.js';
evalListeners.push(function (url) { evalListeners.push(function (url) {
if (url.indexOf(mainJs) > -1) { if (url.indexOf(mainJs) > -1) {
onLoadCb(env[platform].main.root_el); onLoadCb(env[platform].main.root_el);
console.info('Done loading Clojure app'); console.log('Done loading Clojure app');
} }
}); });
if (typeof goog === "undefined") { if (typeof goog === "undefined") {
console.info('Loading Closure base.'); console.log('Loading Closure base.');
interceptRequire(); interceptRequire();
compileWarningsToYellowBox();
importJs('goog/base.js', function () { importJs('goog/base.js', function () {
shimBaseGoog(); shimBaseGoog();
fakeLocalStorageAndDocument();
importJs('cljs_deps.js'); importJs('cljs_deps.js');
importJs('goog/deps.js', function () { importJs('goog/deps.js', function () {
debugToLog();
// This is needed because of RN packager // This is needed because of RN packager
// seriously React packager? why. // seriously React packager? why.
var googreq = goog.require; var googreq = goog.require;
@ -233,6 +209,39 @@ function shimBaseGoog() {
importJs(src); importJs(src);
return true; 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 // Figwheel fixes

View File

@ -56,11 +56,10 @@
gap (get-gap state) gap (get-gap state)
page-offset (+ prop-page-width gap) page-offset (+ prop-page-width gap)
current-position (get-current-position event) current-position (get-current-position event)
direction (if (> current-position (+ starting-position scroll-threshold)) direction (cond
1 (> current-position (+ starting-position scroll-threshold)) 1
(if (< current-position (- starting-position scroll-threshold)) (< current-position (- starting-position scroll-threshold)) -1
-1 :else 0)
0))
current-page (+ (quot starting-position page-offset) direction) current-page (+ (quot starting-position page-offset) direction)
] ]
(log/debug "on-scroll-end: prop-page-width=" prop-page-width (log/debug "on-scroll-end: prop-page-width=" prop-page-width
@ -133,10 +132,8 @@
:bounces false :bounces false
:decelerationRate 0.9 :decelerationRate 0.9
:horizontal true :horizontal true
:onScrollBeginDrag (fn [event] :onScrollBeginDrag #(reset! starting-position (get-current-position %))
(let [] :onScrollEndDrag #(on-scroll-end % component @starting-position)
(reset! starting-position (get-current-position event))))
:onScrollEndDrag (fn [event] (on-scroll-end event component @starting-position))
:showsHorizontalScrollIndicator false :showsHorizontalScrollIndicator false
:ref (fn [c] (set! (.-scrollView component) c)) :ref (fn [c] (set! (.-scrollView component) c))
} }

View File

@ -1,5 +1,6 @@
(ns syng-im.persistence.realm (ns syng-im.persistence.realm
(:require [cljs.reader :refer [read-string]] (:require [cljs.reader :refer [read-string]]
[syng-im.utils.logging :as log]
[syng-im.utils.types :refer [to-string]]) [syng-im.utils.types :refer [to-string]])
(:refer-clojure :exclude [exists?])) (:refer-clojure :exclude [exists?]))
@ -147,7 +148,7 @@
(.-length objs)) (.-length objs))
(defn get-list [schema-name] (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 (comment