A Simple LocalStorage Model
When creating an extension, you'll likely want to store some data. The HTML5 WebStorage spec allows a site (or extension in this case) to store simple key value pairs. This is ideal for extensions looking to keep track of simple things such as user preferences. It shouldn't be used for complex data or data that you'll be expecting to search over. Use IndexedDb for that.
The following is a simple mechanism which can be used in an extension to store and retrieve data using
localStorage. It provides no data validation or verification other than returning null if no data is found and storing values as JSON.
Stored properties are added by calling the
settings.implementfunction. The function will take any number of parameters, so additional properties can be added with ease. Properties are checked to see if they already exist before being created.
Leave a Comment
Your email address will not be published. Required fields are marked *