Skip to content

Instantly share code, notes, and snippets.

@ORESoftware
Last active September 6, 2015 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ORESoftware/a274c36b844e1cfede46 to your computer and use it in GitHub Desktop.
Save ORESoftware/a274c36b844e1cfede46 to your computer and use it in GitHub Desktop.
hotReloadHandler
define([
'socketio',
'#allCollections',
'#allCSS',
'#hotReload',
'app/js/cssAdder'
],
function (io, collections, allCSS, hotReload, cssAdder) {
var socketHotReload = null;
function getConnection() {
if (socketHotReload == null) {
socketHotReload = io.connect('http://127.0.0.1:3002');
//you should implement io.on 'error', on 'connect' and on 'disconnect' etc
socketHotReload.on('.jsx transform error', function (data) {
throw new Error(data)); //you need to implement window.onerror to prevent error from crashing front-end and to let yourself know why the transform failed
});
socketHotReload.on('hot-reload (.jsx)', function (data) {
hotReload.hotReloadSimple(data,function(err,result){
if(err){
alert(err);
return;
}
var filename = reconcilePath(data); //you need to implement reconcilePath
require(['#allViews'],function(allViews){ //I have a module '#allViews' that contains all my front-end views
allViews[filename] = result;
Backbone.history.loadUrl(Backbone.history.fragment); //reload the current page (don't need to worry about any other pages)
});
});
});
}
return socketHotReload;
}
return {
getConnection: getConnection,
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment