Brands favoured by Brexiters and Remainers
campaignlive.co.uk1 pointsby flashingpumpkin0 comments
curl -s http://random-inc5000.herokuapp.com/ | python -m simplejson.tool
I've got the last bit aliased as `json` though. mainWindow.menu "File", (err, file)->
openMenu err, (err, menu)->
getItem err, "Open", (err, item)->
click err, item, (err)->
getChild err, getChildType("Window"), (err, dialog)->
if err? and err instanceof NoFileError
# do stuff
if err? and err instanceof InvalidClickError
# do other stuff
if err?
throw err
# do stuff with dialog if no err
Each function takes as first argument an error and as last a callback. If there's
an error, the function just passes the error up the callback stack until it gets
dealed with. fun = (err, args..., callback)
You can't pull that off if your code is heavily object oriented though: mainWindow.menu "File", (err, file)->
# If mainWindow.menu errors, file is undefined
# and the call to openMenu throws an error
file.openMenu err, (err, menu)->
# ...
Breaking your code/api up with modules instead into classes fixes that.
This is a lot saner and won't descend into a mess that is keeping multiple settings files around. It's also a lot easier to explain.