mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-19 05:03:32 +08:00
Merge pull request #24277 from kimamula/export-storejs-plugins
[@types/storejs] add declarations of store.js plugins
This commit is contained in:
31
types/storejs/index.d.ts
vendored
31
types/storejs/index.d.ts
vendored
@@ -15,8 +15,8 @@ interface StoreJsAPI {
|
||||
each(callback: (val: any, namespacedKey: string) => void): void;
|
||||
clearAll(): void;
|
||||
hasNamespace(namespace: string): boolean;
|
||||
createStore(plugins?: any[], namespace?: string): StoreJsAPI;
|
||||
addPlugin(plugin: any): void;
|
||||
createStore(plugins?: Function[], namespace?: string): StoreJsAPI;
|
||||
addPlugin(plugin: Function): void;
|
||||
namespace(namespace: string): StoreJsAPI;
|
||||
}
|
||||
|
||||
@@ -33,3 +33,30 @@ declare const engine: StoreJsEngine;
|
||||
declare module 'store/src/store-engine' {
|
||||
export = engine;
|
||||
}
|
||||
declare module 'store/plugins/all' {
|
||||
export = Function;
|
||||
}
|
||||
declare module 'store/plugins/default' {
|
||||
export = Function;
|
||||
}
|
||||
declare module 'store/plugins/dump' {
|
||||
export = Function;
|
||||
}
|
||||
declare module 'store/plugins/events' {
|
||||
export = Function;
|
||||
}
|
||||
declare module 'store/plugins/expire' {
|
||||
export = Function;
|
||||
}
|
||||
declare module 'store/plugins/observe' {
|
||||
export = Function;
|
||||
}
|
||||
declare module 'store/plugins/operations' {
|
||||
export = Function;
|
||||
}
|
||||
declare module 'store/plugins/update' {
|
||||
export = Function;
|
||||
}
|
||||
declare module 'store/plugins/v1-backcompat' {
|
||||
export = Function;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
// Tests for storagejs.d.ts
|
||||
import * as store from 'store';
|
||||
import * as engine from 'store/src/store-engine';
|
||||
import * as allPlugin from 'store/plugins/all';
|
||||
import * as defaultPlugin from 'store/plugins/default';
|
||||
import * as dumpPlugin from 'store/plugins/dump';
|
||||
import * as eventsPlugin from 'store/plugins/events';
|
||||
import * as expirePlugin from 'store/plugins/expire';
|
||||
import * as observePlugin from 'store/plugins/observe';
|
||||
import * as operationsPlugin from 'store/plugins/operations';
|
||||
import * as updatePlugin from 'store/plugins/update';
|
||||
import * as v1BackcompatPlugin from 'store/plugins/v1-backcompat';
|
||||
|
||||
// https://github.com/marcuswestin/store.js/blob/master/README-More.md#storeenabled-flag
|
||||
console.log('storage is supported: ', store.enabled === true);
|
||||
@@ -52,6 +61,8 @@ store.set('foo', 'bar 1');
|
||||
store.set('foo', 'bar 2');
|
||||
store.getHistory('foo');
|
||||
|
||||
store.addPlugin(expirePlugin);
|
||||
|
||||
// https://github.com/marcuswestin/store.js/#make-your-own-build
|
||||
|
||||
// Example custom build usage:
|
||||
@@ -66,9 +77,16 @@ var storages: any[] = [
|
||||
//require('store/storages/localStorage'),
|
||||
//require('store/storages/cookieStorage')
|
||||
];
|
||||
var plugins: any[] = [
|
||||
//require('store/plugins/defaults'),
|
||||
//require('store/plugins/expire')
|
||||
var plugins = [
|
||||
allPlugin,
|
||||
defaultPlugin,
|
||||
dumpPlugin,
|
||||
eventsPlugin,
|
||||
expirePlugin,
|
||||
observePlugin,
|
||||
operationsPlugin,
|
||||
updatePlugin,
|
||||
v1BackcompatPlugin,
|
||||
];
|
||||
var myStore = engine.createStore(storages, plugins);
|
||||
myStore.set('foo', 'bar', new Date().getTime() + 3000); // Using expire plugin to expire in 3 seconds
|
||||
|
||||
Reference in New Issue
Block a user