fix(core): update
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user