Skip to content

Instantly share code, notes, and snippets.

@mitchlloyd
Created December 21, 2011 01:18
Show Gist options
  • Save mitchlloyd/1504102 to your computer and use it in GitHub Desktop.
Save mitchlloyd/1504102 to your computer and use it in GitHub Desktop.
Some ideas for fetching/finding with spine and callbacks.
class Model extends Spine.Model
# This one always pulls the data from the server.
@fetchAndThen: (id, callback) ->
@fetch(id: id)
@one 'refresh', (docs) -> callback(docs[0])
# This one pulls the data from the server if it isn't cached locally.
@remoteFind: (id, callback) ->
if @exists? id
callback @find(id)
else
# I have a custom persistence library with now.js that has callbacks, but this
# could use an ajax callback or even fetchAndThen() above.
@fetch {id: id, success: callback}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment