GaloisInc / FiveUI

Extensible UI Analysis in your browser
Other
29 stars 1 forks source link

Modifies fiveui.RuleSet.load to return promises #22

Closed hallettj closed 10 years ago

hallettj commented 10 years ago

When I work on a codebase I tend to have an urge to refactor callback-based code to use promises instead. Promises are values that represent continuations, and they happen to be monads. In general a function that takes a callback function (or a success and an error function) as an argument can be changed to return a promise instead. Functions that return promises are more easily composed than functions that accept callbacks. In my opinion promise-based code also tends to be more declarative.

There are numerous writeups on promises available. I published one that emphasizes treating promises as monads: http://sitr.us/2012/07/31/promise-pipelines-in-javascript.html