This is the local-storage plugin for the IMA.js application. You can visit our site imajs.io.
npm install @ima/plugin-local-storage --save
// /app/build.js
var vendors = {
common: [
'@ima/plugin-local-storage'
]
};
// /app/config/bind.js
import { LocalStorage } from '@ima/plugin-local-storage';
oc.bind('LocalStorage', LocalStorage);
// /app/config/service.js
const localStorage = oc.get('LocalStorage');
if ($window.isClient()) {
...
// initializes local storage
localStorage.init();
...
}
The localStorage class extends ima storage interface. You can easy use common storage methods like has, get, set, delete, clear, etc.
const exist = localStorage.has('key');
if (!exist) {
localStorage.set('key', { some: 'value' }, { expired: 24 * 60 * 60 });
}
const value = localStorage.get('key');
// some logic
localStorage.delete('key');