-
-
Save fermion/3948185 to your computer and use it in GitHub Desktop.
Revisions
-
gf3 revised this gist
Oct 24, 2012 . 1 changed file with 0 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ @instance_store = {} class App.Model extends Backbone.Model @@ -24,10 +23,6 @@ class App.Model extends Backbone.Model _getJsonRoot: -> @jsonRoot ||= @constructor.toString().match(/^function ([\w]+)/i)[1].toLowerCase() #-------------------------------------------- # INSTANCE STORE #-------------------------------------------- -
gf3 created this gist
Oct 24, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ @instance_store = {} class App.Model extends Backbone.Model cache_enabled: false cache_key: "id" constructor: (attr) -> @on "destroy", @_removeFromStore return super unless attr?.id id = attr.id klass = @_getJsonRoot() instance_store[klass] ||= {} return( if instance_store[klass][id] instance_store[klass][id] else super instance_store[klass][id] = this) _getJsonRoot: -> @jsonRoot ||= @constructor.toString().match(/^function ([\w]+)/i)[1].toLowerCase() _parseDate: (str) -> return str if _.isDate str new Date Date.parse(str) #-------------------------------------------- # INSTANCE STORE #-------------------------------------------- _removeFromStore: => klass = @_getJsonRoot() delete instance_store[klass]?[@id] return