Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class fn
- @id = 0
- @observable = []
- @watch: (val = null) ->
- value = @observable[@id++]
- class getSet
- constructor: (val) ->
- value or=
- value: undefined
- before: []
- after: []
- return if val?
- fn value.value, val for fn in value.before
- value.value = val
- fn value.value, val for fn in value.after
- else
- value.value
- @before: (cb) ->
- value.before.push cb
- @
- @after: (cb) ->
- value.after.push cb
- @
- @subscribe: (cb) -> @after(cb)
- if val? then getSet(val)
- return getSet
- window.watch = fn.watch
- a = fn.watch 42
- b = fn.watch 111111
- console.log 'a: ' + a()
- b(2222222)
- a(23)
- console.log 'b: ' + b()
- console.log 'a: ' + a()
- a.before (from, to) ->
- alert 'change from: ' + from + ' to: ' + to
- a(55)
- console.log 'a: ' + a()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement