Created
December 21, 2011 01:18
-
-
Save mitchlloyd/1504102 to your computer and use it in GitHub Desktop.
Some ideas for fetching/finding with spine and callbacks.
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 characters
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