Skip to content

Instantly share code, notes, and snippets.

@ovcharik
Created April 28, 2015 06:24
Show Gist options
  • Save ovcharik/15a3d40f2da61a0cc9d4 to your computer and use it in GitHub Desktop.
Save ovcharik/15a3d40f2da61a0cc9d4 to your computer and use it in GitHub Desktop.
Reactive property mixin for meteor
@PropertyMixin =
property: (prop, options) ->
Object.defineProperty @prototype, prop, options
reactiveProperty: (name) ->
@property name,
get: ->
dep = @["_#{name}_dep"] ?= new Tracker.Dependency
dep.depend()
@["_#{name}"]
set: (v) ->
dep = @["_#{name}_dep"] ?= new Tracker.Dependency
@["_#{name}"] = v
dep.changed()
v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment