fix(core): update

This commit is contained in:
Philipp Kunz 2023-10-03 13:19:38 +02:00
parent 776eba09e9
commit d3332ccb3f
2 changed files with 14 additions and 5 deletions

View File

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

View File

@ -1,6 +1,8 @@
import * as plugins from './smartstate.plugins.js';
import { StatePart } from './smartstate.classes.statepart.js';
export type TInitMode = 'soft' | 'mandatory' | 'force' | 'persistent';
/**
* Smartstate takes care of providing state
*/
@ -21,7 +23,7 @@ export class Smartstate<StatePartNameType> {
public getStatePart<PayloadType>(
statePartNameArg: string & StatePartNameType,
initialArg?: PayloadType,
initMode?: 'soft' | 'mandatory' | 'force' | 'persistent'
initMode?: TInitMode
): StatePart<StatePartNameType, PayloadType> {
if (this.statePartMap[statePartNameArg as any]) {
if (initialArg && (!initMode || initMode !== 'soft')) {
@ -36,7 +38,7 @@ export class Smartstate<StatePartNameType> {
`${statePartNameArg} does not yet exist, yet you don't provide an initial state`
);
}
return this.createStatePart<PayloadType>(statePartNameArg, initialArg);
return this.createStatePart<PayloadType>(statePartNameArg, initialArg, initMode);
}
}
@ -47,9 +49,16 @@ export class Smartstate<StatePartNameType> {
*/
private createStatePart<PayloadType>(
statePartName: StatePartNameType,
initialPayloadArg: PayloadType
initialPayloadArg: PayloadType,
initMode?: TInitMode
): StatePart<StatePartNameType, PayloadType> {
const newState = new StatePart<StatePartNameType, PayloadType>(statePartName);
const newState = new StatePart<StatePartNameType, PayloadType>(
statePartName,
initMode === 'persistent' ? {
dbName: 'smartstate',
storeName: statePartName as any,
} : null
);
newState.setState(initialPayloadArg);
this.statePartMap[statePartName as any] = newState;
return newState;