Comments (9)
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.
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.
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.
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.
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.
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.
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.
Having callback(error, value) doesn't break that interface. Check Q documentation.
from localforage.
FYI: I created a wrapper around localForage with support of node-style callbacks https://github.com/ask11/storage
from localforage.
Related Issues (20)
- require not defined in Electron-forge HOT 1
- Turning on "Block all cookies" in Brave browser makes localforage.ready() never resolve
- Sessions and Cookies in localForage?
- Doesn't work in electron environment when offline HOT 1
- How to add items without a key in localForage api?
- Make a new release with latest code HOT 3
- npm module
- A more efficient way of encoding binary data as strings in localStorage
- Why not use the textencoder api in the source code HOT 1
- LocalForage prevents sites from going to sleep
- Add a warning or an error message when setItem crash ? HOT 1
- Add src and more files to npmignore
- Error: Uncaught (in promise): VersionError: The operation failed because the stored database is a higher version than the version requested. HOT 2
- Local forage completely breaks my application
- vulnerability in localForage HOT 2
- Store and retrieve javascript objects?
- Is this repository still alive? HOT 1
- TypeError: Cannot read properties of null (reading 'db') HOT 1
- When is version and indexing supported?
- Can it support setting a validity period for the cache? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from localforage.