Comments (6)
It depends on what storage mechanism you're referring to. Each browser implements them differently.
localStorage
localStorage has no "I'm full" event, and no way to determine remaining space cross-browser. When Sticky attempts to set an item in localStorage that lacks the capacity, Chrome and Firefox will throw an exception, Sticky will catch it and log it to the console. It looks like this:
Chrome:
DOMException:
code: 22
message: "QUOTA_EXCEEDED_ERR: DOM Exception 22"
name: "QUOTA_EXCEEDED_ERR"
Firefox:
DOMException:
code: 1014
message: "Persistent storage maximum size reached"
name: "NS_ERROR_DOM_QUOTA_REACHED"
Older versions of safari will crash, newer ones throw the chrome exception. IE9 should also throw an exception. Not sure about older version of IE though.
indexedDB / webDB
IndexedDB or webDB will fail to open a connection to the database if there is no capacity, and Sticky will write an error about it to the console. In addition, Sticky will return false as the argument to a callback passed to Sticky.set() if the request fails. There will also be an error message in the console.
store.get('foo', function(item) {
console.log(item); // outputs `false` if indexedDB request fails
});
from sticky.
Thanks for the explanations for now. I'll do some testing soon and might get back to that issue.
from sticky.
I hope my reply wasn't confusing. I'll answer your question directly: There are no events in Sticky, only callbacks: The callback for when the store is repopulated and ready, and the callback for each store method.
It might be a good idea to add events for errors instead of logging them to the console. I'd be open to that if you want to do it. I would prefer it to work as such:
var store = new StickyStore();
store.on('error', function(msg) {
console.log(msg);
});
If we're going to adopt that style of event registration, it would be good to replace the store ready callback with an event as well:
store.on('ready', function(store) {
console.log(store);
});
from sticky.
I couldn't help myself and added events tonight. I've updated the documentation, check out "events" towards the bottom. Thanks for the suggestion :)
I improved error handling and replaced the console messages with error
events. There's also events ready
, get
, set
, and remove
.
Use them like this:
var store = new StickyStore();
store.on('error', function(err, item) {
console.log(error); // Returns the error message
console.log(item); // Returns the item, if applicable
});
from sticky.
Thanks for getting back to that issue.
I always prefere callbacks (function(err[, item])
) over events, since I want to have the error corresponding to the actual API call I'm doing.
Also I'm wondering if there is the need to more granular errors. I.e. I would be very interested if the error was a QUOTA or a general one (I havent worked with indexDB and webSQL so far, is there really no quota error callback?).
I'm somewhat sorry, for opening this ticket without playing around with sticky first. I'll do exactly that in the next days. Maybe I can provide a pull request then... :)
from sticky.
Neither localStorage, indexedDB, or webSQL include the space remaining in error messages, or methods to check how much storage is remaining. It's pathetic and frustrating.
Except for IE8, which implements a window.localStorage.remainingSpace method to get the space remaining, but it's not implemented in other browsers.
The only way to keep track of space used would be to calculate it when StickyStore.set() is called. I doubt there's a way to do it accurately.
from sticky.
Related Issues (14)
- StickyStore.get should support a 'default' argument HOT 1
- Performance Comparison... HOT 5
- indexeddb future compat
- IndexedDB without serialization HOT 1
- Defining adapters causes error... HOT 10
- Impossible to save falsy values (empty string, number 0) HOT 1
- List/getAll function HOT 1
- Different users and init HOT 1
- Other mobile browser are supported? HOT 1
- 数据同步 HOT 2
- Performance of memory cache HOT 1
- Error on FireFox10 HOT 3
- tests? HOT 3
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 sticky.