edata-store
v1.1.5
Published
build global store and get namespaced edata
Downloads
3
Readme
edata-store
Easily use global store with edata.
Install
You can install from NPM.
npm install --save edata-store
Usage
- Initialize store using
initStore
(normally at your entry file)
import {initStore} from 'edata-store'
initStore() // `'default'` namespace
// OR
initStore(`xx_space`)
- call
getStore()
, and you get an edata instance. (normally at your component file)
// any where in your source
import {getStore} from 'edata-store'
getStore().set('xx', 1) // `'default'` namespace
getStore().get('xx').toJSON() // 1
Or pass the namespace
arg:
getStore('xx_space').set('xx', 2) // `'xx_space'` namespace
getStore('xx_space').get('xx').toJSON() // 2
Above create a separate edata
under xx_space
namespace.
API
The typescript definition as below:
/**
* Initialize store for namespace, after that you can call getStore
* @param namespace {string} The namespace of cacheStore, empty for 'default'
* @param initData {any} The edata initData
* @param edataOptions {IOptions} The edata Initialize IOptions
* @returns {edataRoot} The edata root instance
*/
export declare function initStore(namespace?: string, initData?: any, edataOptions?: Partial<IOptions>): edataRoot;
/**
* Get store using namespace from cacheStore
* @param namespace {string} The namespace of cacheStore, empty for 'default'
* @returns {edataRoot} The edata root instance
*/
export declare function getStore(namespace?: string): edataRoot;