Skip to content

Commit

Permalink
feat(element/state-machine-mixin): add stateUpdated method
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Feb 27, 2023
1 parent 5b8674c commit d599282
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions ui/element/src/mixins/state-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {Constructor} from '@alwatr/type';

export declare class StateMachineMixinInterface<TMachine extends FiniteStateMachine> extends SignalMixinInterface {
protected stateMachine: TMachine;
protected stateUpdated(state: TMachine['state']): void;
protected render_unresolved(): unknown;
protected render_resolving(): unknown;
}
Expand All @@ -28,15 +29,18 @@ export function StateMachineMixin<T extends Constructor<SignalMixinInterface>, T
super.connectedCallback();
this.stateMachine.transition('CONNECTED');
this._signalListenerList.push(
this.stateMachine.signal.subscribe(
() => {
this.requestUpdate();
},
{receivePrevious: 'No'},
),
this.stateMachine.signal.subscribe((state) => this.stateUpdated(state), {receivePrevious: 'NextCycle'}),
);
}

/**
* Subscribe to this.stateMachine.signal event.
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
protected stateUpdated(_state: TMachine['state']): void {
this.requestUpdate();
}

protected override firstUpdated(_changedProperties: PropertyValues<this>): void {
super.firstUpdated(_changedProperties);
this.stateMachine.transition('FIRST_UPDATED');
Expand Down

0 comments on commit d599282

Please sign in to comment.