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 = {
name: '@push.rocks/smartstate',
version: '2.0.14',
version: '2.0.15',
description: 'a package that handles state in a good way'
}

View File

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

View File

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