Last active
December 27, 2015 04:29
-
-
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.
This file contains 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 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