Last active
November 17, 2018 10:09
-
-
Save StevenLangbroek/b0ab80650c40a9622ff3 to your computer and use it in GitHub Desktop.
Fetch a model with options unless it has an attribute. Return promise and resolve with instance so you can easily feed it further into your controllers.
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 Backbone.Model | |
fetchUnless: (key, options = {}) -> | |
defer = $.Deferred() | |
if @has(key) | |
defer.resolve(@) | |
else | |
@fetch(options).done => | |
defer.resolve(@) | |
defer.promise() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment