Skip to content

Instantly share code, notes, and snippets.

@Kequc
Last active August 29, 2015 14:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kequc/11083050 to your computer and use it in GitHub Desktop.
Save Kequc/11083050 to your computer and use it in GitHub Desktop.
Obj update in jQuery coffeescript
class MyApp.Update
constructor: (@obj, @attrs={}) ->
@obj.data ?= {}
@obj.isOwned = false
$.extend @attrs,
ownerId: (v) =>
@obj.isOwned = MyApp.account.signedIn v
set: (k, v) =>
if @obj.data[k] != v
@obj.data[k] = v
@run k, v
@obj
all: (data) =>
c = {}
$.each data, (k, v) =>
if @obj.data[k] != v
@obj.data[k] = v
c[k] = v
true
$.each c, (k, v) =>
@run k, v
true
@obj
run: (k, v) =>
if @attrs[k] && $.isFunction(@attrs[k])
@attrs[k](v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment