-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change pattern for callbacks to node-style error first #55
Comments
I’ve always disliked that node.js What method calls are we talking about failing? |
I think we've had this discussion before... when Jen suggested using node style callbacks in order to check for error values. The conclusion was that it broke the expected return value. But given that we're not using this in the same way that localStorage is used (we don't just use the return value, but send in a callback), we might be able to change that too (and @ednapiranha would be happier). That said, the version number should be bumped or make a giant CHANGELOG item that warns people that the methods have changed their signature. |
All of the available API functions (setItem, getItem, ...). E.g. the
I do not know. Putting the error first is a little bit annoying when On 14/02/14 00:24, Matthew Riley MacPherson wrote:
|
If it's localStorage-specific, always return a null error on callback? Otherwise, return an error if it fails on async storage. I don't think putting the error first is annoying - it's a standard practice that is done these days. |
I actually think what I'd like to see is an error callback and a failure callback, particularly because that maps to promises nicer than a single callback with an So let's say we should implement an error callback as the second argument, and use that same error callback as the promise rejection callback. |
Libraries that implement promises on the browser like Q expect a node style callback. I like the approach and also works as expected by other libraries. Thumbs up for the change. |
localForage uses ES6-style, Promises-spec promises. They don’t expect an error value in their success callbacks, they just offer a |
Having callback(error, value) doesn't break that interface. Check Q documentation. |
FYI: I created a wrapper around localForage with support of node-style callbacks https://github.com/ask11/storage |
The callbacks to
getItem(...)
etc. contain the result value as first argument. If the method call fails, there is no way to get hold of this information from just using the callback.Therefore, I propose to change the signature of the callbacks to be:
similar to the style used in node.js.
The text was updated successfully, but these errors were encountered: