Skip to content

Instantly share code, notes, and snippets.

@michiel
Last active August 29, 2015 13:58
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 michiel/9970400 to your computer and use it in GitHub Desktop.
Save michiel/9970400 to your computer and use it in GitHub Desktop.
observers in coffeescript
_watch = (prop, fn) ->
subs[prop] = [] unless subs[prop]
subs[prop].push fn
_notify = (prop, val) ->
if subs[prop]
subs[prop].forEach (cb) ->
cb val
_compare = (a, b) ->
JSON.stringify(a) is JSON.stringify(b)
_change = (prop, val) ->
unless _compare(val, save[prop])
save[prop] = val
_notify prop, val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment