Store
A simple interface to LocalStorage based on store.js, whose sole purpose is to ensure that any keys you save to LocalStorage come out the same type as when they went in.
Normally when you save something to LocalStorage, it converts it into a string. So if you were to save a number, it would be saved as "12" instead of 12. This means when you retrieved the number, it would now be a string.
let { setStoreItem, getStoreItem } = kontra;
setStoreItem('highScore', 100);
getStoreItem('highScore'); //=> 100import { setStoreItem, getStoreItem } from 'path/to/kontra.mjs';
setStoreItem('highScore', 100);
getStoreItem('highScore'); //=> 100import { setStoreItem, getStoreItem } from 'kontra';
setStoreItem('highScore', 100);
getStoreItem('highScore'); //=> 100Table of Contents
getStoreItem(key)
Retrieve an item from localStorage and convert it back to its original type.
getStoreItem Parameters
-
key String. Name of the key of the item to retrieve.
getStoreItem Return value
The retrieved item.
setStoreItem(key, value)
Save an item to localStorage.
setStoreItem Parameters
-
key String. The name of the key.
-
value Any type. The value to store.