commented functions

This commit is contained in:
mrjvs 2021-10-24 23:32:47 +02:00
parent f6a4f59adb
commit 23b8b816dd
1 changed files with 22 additions and 0 deletions

View File

@ -38,6 +38,12 @@ function buildStoreObject(data) {
// updates succesful, return // updates succesful, return
return obj; return obj;
}, },
/*
* get a instance of a stored item
* will be migrated to the latest version on fetch
* call .save() on it put the new modified data back
*/
get() { get() {
// get from storage api // get from storage api
const store = this; const store = this;
@ -94,10 +100,22 @@ export function versionedStoreBuilder() {
versions: {}, versions: {},
storageString: null, storageString: null,
}, },
/*
* set key of localstorage item, must be unique
*/
setKey(str) { setKey(str) {
this._data.storageString = str; this._data.storageString = str;
return this; return this;
}, },
/*
* add a version to the store
*
* version: version number
* migrate: function to update from previous version to this version
* create: function to return an empty storage item from this version (in correct syntax)
*/
addVersion({ version, migrate, create }) { addVersion({ version, migrate, create }) {
// input checking // input checking
if (version < 0) if (version < 0)
@ -128,6 +146,10 @@ export function versionedStoreBuilder() {
} }
return this; return this;
}, },
/*
* returns function store based on what has been set
*/
build() { build() {
// check if version list doesnt skip versions // check if version list doesnt skip versions
const versionListSorted = this._data.versionList.sort((a,b)=>a-b); const versionListSorted = this._data.versionList.sort((a,b)=>a-b);