Comments (7)
For future reader, try this.
npm i @types/store
src/@types/store.d.ts
interface StoreJsAPI {
// expirePlugin
set(key: string, value: any, expiration: number): any;
}
import * as engine from 'store/src/store-engine';
import * as expirePlugin from 'store/plugins/expire';
const myStore = engine.createStore([], [expirePlugin]);
myStore.set('foo', 'bar', new Date().getTime() + 3000);
I hope this helps.
from store.js.
ts中,添加了过期时间插件,set方法由于声明的类型缺少第三个参数,导致无法使用set方法
from store.js.
@damianon I want to know this as well, specifically for expire.js. Were you able to find a fix? Maybe create your own ts definition file for the parts you use?
from store.js.
No, I ended up creating my on wrapper to expire entries
from store.js.
@damianon could you please share your solution?
from store.js.
Don't have the code at hand currently, but basically I wrapped the object and added an expiration timestamp. Upon reading the value I checked the timestamp and if expired returned null
from store.js.
posting the solution to my problem for more convenience:
import engine from "store/src/store-engine";
import expirePlugin from "store/plugins/expire";
declare global {
interface StoreJsAPI {
// expirePlugin
set(key: string, value: any, expiration: number): any;
}
}
const store = engine.createStore([], [expirePlugin]);
const storeKey = "form-data";
const formExpiryDuration = 1000 * 60 * 60; // 1 Hour
export function getFormData() {
return store.get(storeKey) || {};
}
export function setFormData(data: any) {
store.set(
storeKey,
Object.assign(getFormData(), data),
new Date().getTime() + formExpiryDuration,
);
}
export function clearFormData() {
store.set(storeKey, {});
}
from store.js.
Related Issues (20)
- Chinese characters when encoding HOT 3
- Ignore me
- how do i read specifically items from session storage HOT 1
- Uncaught TypeError: t.charCodeAt is not a function HOT 2
- Error on Ubuntu: Cannot read property 'documentElement' of undefined HOT 1
- the json format data becomes a json string HOT 1
- how to use store.js with expire?
- Support Subdomains HOT 1
- Open facebook event in new window/tab HOT 1
- there is no Issues just question about security!!! HOT 7
- How to store a file? HOT 13
- clearAll() per namespace? HOT 4
- expire broken HOT 1
- Race conditions HOT 1
- Store instance
- store.js use in memory(localstorage) or physical disk( indexedDB)? what is size limit? HOT 1
- Expiry not set in cookieStorage.js HOT 2
- 存int数组,取值丢失精度 HOT 1
- global namespace
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from store.js.