parent
b0c8d10fc2
commit
de72184c20
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue