Skip to content

Instantly share code, notes, and snippets.

@StevenLangbroek
Last active November 17, 2018 10:09
Show Gist options
  • Save StevenLangbroek/b0ab80650c40a9622ff3 to your computer and use it in GitHub Desktop.
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.
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