Compare commits

...

8 Commits

Author SHA1 Message Date
5f5f9db884 2.0.11 2023-10-03 12:47:13 +02:00
876042b446 fix(core): update 2023-10-03 12:47:12 +02:00
df2924577b 2.0.10 2023-10-03 07:53:29 +02:00
4abaea84f8 fix(core): update 2023-10-03 07:53:28 +02:00
de454b4c8d 2.0.9 2023-09-11 18:39:53 +02:00
961685b5bd fix(core): update 2023-09-11 18:39:52 +02:00
c622396d50 2.0.8 2023-07-27 15:20:48 +02:00
d130c1c6fd fix(core): update 2023-07-27 15:20:47 +02:00
8 changed files with 1574 additions and 861 deletions

View File

@ -119,6 +119,6 @@ jobs:
run: |
npmci node install stable
npmci npm install
pnpm install -g @gitzone/tsdoc
pnpm install -g @git.zone/tsdoc
npmci command tsdoc
continue-on-error: true

View File

@ -1,6 +1,6 @@
{
"name": "@push.rocks/smartstate",
"version": "2.0.7",
"version": "2.0.11",
"private": false,
"description": "a package that handles state in a good way",
"main": "dist_ts/index.js",
@ -14,19 +14,20 @@
"buildDocs": "tsdoc"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.66",
"@gitzone/tsbundle": "^2.0.8",
"@gitzone/tsrun": "^1.2.44",
"@gitzone/tstest": "^1.0.77",
"@push.rocks/tapbundle": "^5.0.12",
"@types/node": "^20.4.5"
"@git.zone/tsbuild": "^2.1.70",
"@git.zone/tsbundle": "^2.0.8",
"@git.zone/tsrun": "^1.2.46",
"@git.zone/tstest": "^1.0.81",
"@push.rocks/tapbundle": "^5.0.15",
"@types/node": "^20.8.0"
},
"dependencies": {
"@push.rocks/isohash": "^2.0.1",
"@push.rocks/lik": "^6.0.3",
"@push.rocks/smartjson": "^5.0.6",
"@push.rocks/lik": "^6.0.5",
"@push.rocks/smartjson": "^5.0.10",
"@push.rocks/smartpromise": "^4.0.3",
"@push.rocks/smartrx": "^3.0.6"
"@push.rocks/smartrx": "^3.0.6",
"@push.rocks/webstore": "^2.0.13"
},
"files": [
"ts/**/*",

2358
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartstate',
version: '2.0.7',
version: '2.0.11',
description: 'a package that handles state in a good way'
}

View File

@ -21,7 +21,7 @@ export class Smartstate<StatePartNameType> {
public getStatePart<PayloadType>(
statePartNameArg: string & StatePartNameType,
initialArg?: PayloadType,
initMode?: 'soft' | 'mandatory' | 'force'
initMode?: 'soft' | 'mandatory' | 'force' | 'persistent'
): StatePart<StatePartNameType, PayloadType> {
if (this.statePartMap[statePartNameArg as any]) {
if (initialArg && (!initMode || initMode !== 'soft')) {

View File

@ -7,8 +7,30 @@ export class StatePart<TStatePartName, TStatePayload> {
public stateStore: TStatePayload;
private cumulativeDeferred = plugins.smartpromise.cumulativeDefer();
constructor(nameArg: TStatePartName) {
private webStore: plugins.webstore.WebStore<TStatePayload> | null = null; // Add WebStore instance
constructor(nameArg: TStatePartName, webStoreOptions?: plugins.webstore.IWebStoreOptions) {
this.name = nameArg;
// Initialize WebStore if webStoreOptions are provided
if (webStoreOptions) {
this.webStore = new plugins.webstore.WebStore<TStatePayload>(webStoreOptions);
this.initWebStore();
}
}
/**
* initializes the webstore
*/
private async initWebStore() {
if (this.webStore) {
await this.webStore.init();
const storedState = await this.webStore.get(String(this.name));
if (storedState) {
this.stateStore = storedState;
this.notifyChange();
}
}
}
/**
@ -22,9 +44,14 @@ export class StatePart<TStatePartName, TStatePayload> {
* sets the stateStore to the new state
* @param newStateArg
*/
public setState(newStateArg: TStatePayload) {
public async setState(newStateArg: TStatePayload) {
this.stateStore = newStateArg;
this.notifyChange();
// Save state to WebStore if initialized
if (this.webStore) {
await this.webStore.set(String(this.name), newStateArg);
}
}
/**
@ -89,10 +116,11 @@ export class StatePart<TStatePartName, TStatePayload> {
/**
* dispatches an action on the statepart level
*/
public async dispatchAction<T>(stateAction: StateAction<TStatePayload, T>, actionPayload: T) {
public async dispatchAction<T>(stateAction: StateAction<TStatePayload, T>, actionPayload: T): Promise<TStatePayload> {
await this.cumulativeDeferred.promise;
const newState = await stateAction.actionDef(this, actionPayload);
this.setState(newState);
await this.setState(newState);
return this.getState();
}
/**

View File

@ -2,5 +2,6 @@ import * as isohash from '@push.rocks/isohash';
import * as smartjson from '@push.rocks/smartjson';
import * as smartpromise from '@push.rocks/smartpromise';
import * as smartrx from '@push.rocks/smartrx';
import * as webstore from '@push.rocks/webstore';
export { isohash, smartjson, smartpromise, smartrx };
export { isohash, smartjson, smartpromise, smartrx, webstore };

View File

@ -3,9 +3,12 @@
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true,
}
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}