Giter Site home page Giter Site logo

Comments (9)

tofumatt avatar tofumatt commented on May 22, 2024

I’ve always disliked that node.js (error, value) -> style, at the very least I’d like error to follow value, but what’s the convention in browser-land?

What method calls are we talking about failing?

from localforage.

sole avatar sole commented on May 22, 2024

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.

from localforage.

jviereck avatar jviereck commented on May 22, 2024

What method calls are we talking about failing?

All of the available API functions (setItem, getItem, ...). E.g. the
WebSQL driver might fail on any API function being used as there is an
error with the underlaying WebSQL database.

but what’s the convention in browser-land?

I do not know. Putting the error first is a little bit annoying when
writing the callback, but on the other hand, if the developer ignores
possible errors to be handled in his application, they are doing
something wrong. So by putting the error value as first argument it's a
way to make developers think about error handling, which I think is a
positive point :)

On 14/02/14 00:24, Matthew Riley MacPherson wrote:

I’ve always disliked that node.js (error, value) -> style, at the
very least I’d like error to follow value, but what’s the convention
in browser-land?

What method calls are we talking about failing?


Reply to this email directly or view it on GitHub
#55 (comment).

from localforage.

operatorjen avatar operatorjen commented on May 22, 2024

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.

from localforage.

tofumatt avatar tofumatt commented on May 22, 2024

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 error and value argument. The node-style means that every single callback function then needs to deal with errors internally instead of having a generic error handler (which most of the time would be to do with a storage limit exceeded error). I'd rather an extra callback than every function starting with if (error) which strikes me as boilerplate code and less reusable.

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.

from localforage.

magalhas avatar magalhas commented on May 22, 2024

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.

from localforage.

tofumatt avatar tofumatt commented on May 22, 2024

localForage uses ES6-style, Promises-spec promises. They don’t expect an error value in their success callbacks, they just offer a .then(success, failure) setup.

from localforage.

magalhas avatar magalhas commented on May 22, 2024

Having callback(error, value) doesn't break that interface. Check Q documentation.

from localforage.

alekseykulikov avatar alekseykulikov commented on May 22, 2024

FYI: I created a wrapper around localForage with support of node-style callbacks https://github.com/ask11/storage

from localforage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.