storax
v1.0.3
Published
Universal store on typescript
Downloads
5
Readme
Storax - universal store service
This store supported ts and provide 100% typed store-manager. Easy start with react, vue2/3, angular, svelte and other.
Install storax
npm: npm install storax
yarn: yarn add storax
Store module example
Simple store example: without actions, watchers, tasks
// @src/storage/demo/DemoStorage.ts
import StoreInstance, { StoreModule } from "storax"
type DemoStore = { name: string }
const store = { name: "demoName" }
class DemoSetters extends StoreModule<DemoStore> {
set setName(name: string) {
this.store.name = name
}
}
class DemoGetters extends StoreModule<DemoStore> {
get getName(): string {
return this.store.name
}
}
export const getters = new DemoGetters({ store })
export const setters = new DemoSetters({ store })
const DemoStorage = new StoreInstance<DemoStore, DemoGetters, DemoSetters> ({
name: "demo",
getters,
setters
})
export default DemoStorage
Use as store instance module
//@src/app.ts
import DemoStorage from '@src/storage/demo/DemoStorage.ts'
const setDemoName = (name: string): void => {
DemoStorage.setters.setName = name
}
setDemoName("test name")
console.log(DemoStorage.getters.getName)
Use as local dependency
//@src/app.ts
import { getters, setters } from '@src/storage/demo/DemoStorage.ts'
const setDemoName = (name: string): void => {
getters.setName = name
}
setDemoName("test name")
console.log(getters.getName)