Skip to content

Instantly share code, notes, and snippets.

@danott
Last active December 27, 2015 04:29
Show Gist options
  • Save danott/7266838 to your computer and use it in GitHub Desktop.
Save danott/7266838 to your computer and use it in GitHub Desktop.
For control flow, we have to absolutely know that a promise is resolved. This is a small pattern I've used in isolation that I would like nitpicked.
class BananaStand extends Batman.Object
@accessor 'hasMoney', promise: (deliver) ->
new Batman.Request
url: "/banana_stand/has_money.json" # true, false
success: (json) ->
deliver(null, json)
return undefined
onResolved: (path, callback) ->
if @get(path) == undefined
@observeOnce path, callback
else
callback()
stand = new BananaStand()
stand.onResolved 'hasMoney', =>
if stand.get('hasMoney')
# do stuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment