javascript - Handling chrome.storage Array Size Limits -
i'm dealing chrome storage api extensions, , i'm not sure how handle storage size limits.
say have array keeps growing (which another question have performance). need check if i'm out of space. know can compare the actual size quota_bytes, , many other properties analogically.
concerning growing array, thought 2 options:
- when
chrome.storage.{storagearea}.set()fired can check if there error. check if i'm out of storage , something. maybe should consider using index achieve kind of fifo queue. - (i can't remember)
these get , push functions, in i'm not sure how should implement fail callback function, neither redesign way array grows.
var storagearea = chrome.storage.sync; var storagearray = { get: function(key, callback) { storagearea.get(key, function(obj) { var values = obj.hasownproperty(key) ? obj[key] : []; callback(values); }) }, push: function(key, value, success, fail) { storagearea.get(key, function(obj) { var values = obj.hasownproperty(key) ? obj[key] : []; values.push(value); var thekey = key; var myobj = {} myobj[key] = values; storagearea.set(myobj, function() { if (chrome.runtime.lasterror) typeof fail === 'function' && fail(chrome.runtime.lasterror); else typeof success === 'function' && success(); }); }); } }
Comments
Post a Comment