Skip to content

Instantly share code, notes, and snippets.

@ehynds
Forked from benpickles/blah.js
Created March 1, 2011 14:45
Show Gist options
  • Save ehynds/849218 to your computer and use it in GitHub Desktop.
Save ehynds/849218 to your computer and use it in GitHub Desktop.
////////////////
// IN CONSOLE //
////////////////
Blah = Model("blah", {
persistence: Model.localStorage(),
find_by_uid: function(uid) {
return this.detect(function() {
return this.uid == uid
})
}
})
blah = new Blah({ name: "Blah" })
blah.uid
// => "blah-1298988849274-662"
blah.save()
Blah.all()
// => [blah]
//////////////////
// REFRESH PAGE //
//////////////////
Blah = Model("blah", {
persistence: Model.localStorage(),
find_by_uid: function(uid) {
return this.detect(function() {
return this.uid == uid
})
}
})
Blah.all()
// => []
Blah.load()
Blah.all()
// => [blah]
// Use the uid returned earlier.
Blah.find_by_uid("blah-1298988849274-662")
// => blah
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment