Last active
December 20, 2015 11:09
-
-
Save kristoferjoseph/6120902 to your computer and use it in GitHub Desktop.
Backbone Memento Example
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
createMemento: function (hash) { | |
var memento = new Memento({ | |
originator: this, | |
state: this.changedAttributes(hash) | |
}); | |
return memento; | |
}, | |
//Sets a memento object to restore state. | |
// Override this function to supply your own way to restore state. | |
setMemento: function (memento) { | |
var state = memento.state; | |
if (this.set) { | |
this.set(state); | |
} | |
return this; | |
}, | |
//Creates a memento and sends it along with an event to be stored then calls set | |
store: function (hash) { | |
//Checks to see if there is anything in the hash before doing any work | |
if ( !_.isEmpty(hash) ) { | |
this.eventMap.trigger("Memento:Store", this.createMemento(hash)); | |
//Calls set after storing the delta | |
this.set(hash); | |
} | |
return this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment