Skip to content

Instantly share code, notes, and snippets.

@Enome
Created October 14, 2011 15:46
Show Gist options
  • Save Enome/1287463 to your computer and use it in GitHub Desktop.
Save Enome/1287463 to your computer and use it in GitHub Desktop.
Class that watches a knockout.js viewmodel for changes.
class Observer
constructor : (data, fn, ignore=[])->
@listen = false
result = ko.dependentObservable ->
for key, val of data
if ko.isObservable(val) and key not in ignore
val()
result.subscribe =>
if @listen
fn()
start : -> @listen = true
stop : -> @listen = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment