Changes between Version 11 and Version 12 of WebInspectorCodingStyleGuide
- Timestamp:
- Aug 10, 2014, 4:35:29 PM (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
WebInspectorCodingStyleGuide
v11 v12 45 45 [http://blog.parse.com/2013/01/29/whats-so-great-about-javascript-promises/ What's so great about Promises?] [http://domenic.me/2012/10/14/youre-missing-the-point-of-promises/ The point of promises is to give us back functional composition] and error bubbling in the async world. They do this by saying that your functions should return a promise, which can do one of two things: 46 46 47 48 47 1. Become __fulfilled__ by a **value** 48 2. Become __rejected__ with an **exception** 49 49 50 50 And, if you have a correctly implemented `then()` function, then fulfillment and rejection will compose just like their synchronous counterparts, with fulfillments flowing up a compositional chain, but being interrupted at any time by a rejection that is only handled by someone who declares they are ready to handle it. … … 60 60 * Use `.catch()` at the end of a chain to perform error handling. 61 61 * To reject a promise, throw an `Error` instance or call the `reject` callback with an `Error` instance. 62 * A `.catch()` block is considered resolved if it does not re-throw an Errorinstance. Re-throw if you want to log an error message and allow other parts of a chain (i.e, an API client) to handle an error condition.63 * Don't directly pass a promise's `resolve` function to Object.addEventListener, as it will leak the promise. Instead, use a single-fire WebInspector.EventListener object defined outside of the promise chain and connect it inside a `.then()` body. Inside the `.catch` block, disconnect the EventListenerif necessary.62 * A `.catch()` block is considered resolved if it does not re-throw an `Error` instance. Re-throw if you want to log an error message and allow other parts of a chain (i.e, an API client) to handle an error condition. 63 * Don't directly pass a promise's `resolve` function to `Object.addEventListener`, as it will leak the promise if the event never fires. Instead, use a single-fire `WebInspector.EventListener` object defined outside of the promise chain and connect it inside a `.then()` body. Inside the `.catch` block, disconnect the `EventListener` if necessary. 64 64 65 65 == New class skeleton