fix(core): update

This commit is contained in:
Philipp Kunz 2023-10-03 19:19:54 +02:00
parent 83976fa3f4
commit 99cb86258e
3 changed files with 9 additions and 7 deletions

View File

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

View File

@ -59,6 +59,7 @@ export class Smartstate<StatePartNameType> {
storeName: statePartName as any, storeName: statePartName as any,
} : null } : null
); );
await newState.init();
const currentState = newState.getState(); const currentState = newState.getState();
await newState.setState({ await newState.setState({
...initialPayloadArg, ...initialPayloadArg,

View File

@ -7,23 +7,24 @@ export class StatePart<TStatePartName, TStatePayload> {
public stateStore: TStatePayload; public stateStore: TStatePayload;
private cumulativeDeferred = plugins.smartpromise.cumulativeDefer(); private cumulativeDeferred = plugins.smartpromise.cumulativeDefer();
private webStoreOptions: plugins.webstore.IWebStoreOptions;
private webStore: plugins.webstore.WebStore<TStatePayload> | null = null; // Add WebStore instance private webStore: plugins.webstore.WebStore<TStatePayload> | null = null; // Add WebStore instance
constructor(nameArg: TStatePartName, webStoreOptions?: plugins.webstore.IWebStoreOptions) { constructor(nameArg: TStatePartName, webStoreOptionsArg?: plugins.webstore.IWebStoreOptions) {
this.name = nameArg; this.name = nameArg;
// Initialize WebStore if webStoreOptions are provided // Initialize WebStore if webStoreOptions are provided
if (webStoreOptions) { if (webStoreOptionsArg) {
this.webStore = new plugins.webstore.WebStore<TStatePayload>(webStoreOptions); this.webStoreOptions = webStoreOptionsArg;
this.initWebStore();
} }
} }
/** /**
* initializes the webstore * initializes the webstore
*/ */
private async initWebStore() { public async init() {
if (this.webStore) { if (this.webStoreOptions) {
this.webStore = new plugins.webstore.WebStore<TStatePayload>(this.webStoreOptions);
await this.webStore.init(); await this.webStore.init();
const storedState = await this.webStore.get(String(this.name)); const storedState = await this.webStore.get(String(this.name));
if (storedState) { if (storedState) {