Skip to content

Instantly share code, notes, and snippets.

@mlrawlings
Created July 11, 2012 20:42
Show Gist options
  • Save mlrawlings/3093247 to your computer and use it in GitHub Desktop.
Save mlrawlings/3093247 to your computer and use it in GitHub Desktop.
SS LiveReload onChange
onChange = (path, event) ->
takeAction = (action) ->
if (Date.now() - lastRun[action]) > 1000 # Reload browser max once per second
console.log('✎'.green, consoleMessage[action].grey)
ss.publish.all('__ss:' + action)
lastRun[action] = Date.now()
action = if pathlib.extname(path) in cssExtensions then 'updateCSS' else 'reload'
if event is 'added' or event is 'changed'
fs.readFile path, (err, data) ->
if data.toString() != '' then takeAction(action)
else setTimeout (-> takeAction(action)), 300
else takeAction(action)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment