Skip to content

Instantly share code, notes, and snippets.

@anaisbetts
Created November 8, 2014 00:36
Show Gist options
  • Save anaisbetts/02be1aecdb5699cebb99 to your computer and use it in GitHub Desktop.
Save anaisbetts/02be1aecdb5699cebb99 to your computer and use it in GitHub Desktop.
Livereload in Atom Shell
fs = require 'fs'
remote = require 'remote'
require 'fs-plus'
Notify = require 'fs.notify'
rx = require 'rx'
module.exports =
class LiveReload
constructor: (dirs...) ->
@dirs = dirs
traverseTreeObservable: (dir) ->
rx.Observable.create (subj) ->
fs.traverseTree(dir, subj.onNext, ( ->), subj.onCompleted)
return rx.Disposable.empty
watchObservable: (files) ->
rx.Observable.Create (subj) ->
notify = new Notify(files)
return rx.Node.fromEvent(notify, 'change').subscribe(subj)
watchAll: ->
rx.Observable.fromArray(@dirs)
.selectMany (x) => @traverseTreeObservable(x)
.selectMany (x) => @watchObservable(x)
attach: ->
@watchAll().throttle(250).subscribe ->
remote.getCurrentWindow().reload()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment