Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

live update style changes

  • Loading branch information...
commit 7d0cc4cc42bb8d85218656329a4b6e1a512aaa20 1 parent e225313
@floating floating authored
View
17 lib/browser_client/system_modules/socketstream.js
@@ -70,3 +70,20 @@ server.on('__ss:reload', function() {
console.log('Reloading as files have changed...');
return window.location.reload();
});
+
+server.on('__ss:update', function() {
+ var h, tag, _i, _len, _ref, _results;
+ console.log('Updating as files have changed...');
+ _ref = document.getElementsByTagName("link");
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ tag = _ref[_i];
+ if (tag.rel.toLowerCase().indexOf("stylesheet") >= 0 && tag.href) {
+ h = tag.href.replace(/(&|%5C?)\d+/, "");
+ _results.push(tag.href = h + (h.indexOf("?") >= 0 ? "&" : "?") + (new Date().valueOf()));
+ } else {
+ _results.push(void 0);
+ }
+ }
+ return _results;
+});
View
25 lib/client_asset_manager/live_reload.js
@@ -12,10 +12,17 @@ lastReload = Date.now();
exports.init = function(root, ss) {
var allPaths, assetsToWatch, detectNewFiles, handleFileChange, watch;
- handleFileChange = function() {
+ handleFileChange = function(action) {
if ((Date.now() - lastReload) > 1000) {
- console.log(''.green, 'Client files changed. Reloading browser...'.grey);
- ss.publish.all('__ss:reload');
+ switch (action) {
+ case "update":
+ console.log(''.green, 'Client files changed. Updating browser...'.grey);
+ ss.publish.all('__ss:update');
+ break;
+ case "reload":
+ console.log(''.green, 'Client files changed. Reloading browser...'.grey);
+ ss.publish.all('__ss:reload');
+ }
return lastReload = Date.now();
}
};
@@ -30,7 +37,17 @@ exports.init = function(root, ss) {
return fs.watch(dir, detectNewFiles);
});
return paths.files.forEach(function(file) {
- return fs.watch(file, handleFileChange);
+ var extension;
+ extension = file.split('.')[file.split('.').length - 1];
+ if (extension === 'styl' || extension === 'css') {
+ return fs.watch(file, function(event, filename) {
+ return handleFileChange('update');
+ });
+ } else {
+ return fs.watch(file, function(event, filename) {
+ return handleFileChange('reload');
+ });
+ }
});
};
detectNewFiles = function() {
View
10 src/browser_client/system_modules/socketstream.coffee
@@ -57,4 +57,12 @@ exports.load =
# Reload browser if reload system event receieved
server.on '__ss:reload', ->
console.log('Reloading as files have changed...')
- window.location.reload()
+ window.location.reload()
+
+# Update browser is update system event receieved
+server.on '__ss:update', ->
+ console.log('Updating as files have changed...')
+ for tag in document.getElementsByTagName("link")
+ if tag.rel.toLowerCase().indexOf("stylesheet") >= 0 and tag.href
+ h = tag.href.replace(/(&|%5C?)\d+/, "")
+ tag.href = h + (if h.indexOf("?") >= 0 then "&" else "?") + (new Date().valueOf())
View
18 src/client_asset_manager/live_reload.coffee
@@ -11,10 +11,15 @@ lastReload = Date.now()
exports.init = (root, ss) ->
- handleFileChange = ->
+ handleFileChange = (action)->
if (Date.now() - lastReload) > 1000 # Reload browser max once per second
- console.log(''.green, 'Client files changed. Reloading browser...'.grey)
- ss.publish.all('__ss:reload')
+ switch action
+ when "update"
+ console.log(''.green, 'Client files changed. Updating browser...'.grey)
+ ss.publish.all('__ss:update')
+ when "reload"
+ console.log(''.green, 'Client files changed. Reloading browser...'.grey)
+ ss.publish.all('__ss:reload')
lastReload = Date.now()
assetsToWatch = ->
@@ -25,7 +30,12 @@ exports.init = (root, ss) ->
watch = (paths) ->
paths.dirs.forEach (dir) -> fs.watch(dir, detectNewFiles)
- paths.files.forEach (file) -> fs.watch(file, handleFileChange)
+ paths.files.forEach (file) ->
+ extension = file.split('.')[file.split('.').length-1]
+ if extension is 'styl' or extension is 'css'
+ fs.watch file, (event, filename) -> handleFileChange('update')
+ else
+ fs.watch file, (event, filename) -> handleFileChange('reload')
detectNewFiles = ->
pathsNow = assetsToWatch()

0 comments on commit 7d0cc4c

Please sign in to comment.
Something went wrong with that request. Please try again.