Created
November 21, 2012 21:12
-
-
Save tsgautier/4127755 to your computer and use it in GitHub Desktop.
auto-refresh in an express/angular project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
watcher.watch __dirname + '/../public' | |
watcher.watch __dirname + '/../views' | |
io.sockets.on 'connection', (socket) -> | |
watcher.on 'changed', -> socket.emit 'cmd:refresh' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function products($rootScope, $scope, $http, socket) { | |
socket.on("cmd:refresh", function() { window.location.reload(true); }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Watcher extends EventEmitter | |
constructor: -> | |
@watchers = [] | |
watch: (directory) => | |
fs.exists directory, => | |
finder = findit.find directory | |
watchit = (f) => | |
@watchers.push fs.watch f, => @emit 'changed' | |
finder.on 'directory', watchit | |
finder.on 'file', watchit | |
stop: => | |
_.each @watchers, (w) -> w.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment