Last active
August 29, 2015 14:00
-
-
Save Kequc/11083050 to your computer and use it in GitHub Desktop.
Obj update in jQuery coffeescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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