Skip to content

Commit

Permalink
refactor: uses native private fields in classes in stead of fake ones
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij committed Dec 26, 2024
1 parent 8cc7b00 commit 8b11f73
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 94 deletions.
6 changes: 3 additions & 3 deletions dist/counter.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions dist/state-machine-model.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<meta property="og:image:type" content="image/png" />
<link rel="canonical" href="https://state-machine-cat.js.org">
<script nonce="known-inline-script">let LOG = false;</script>
<script src="smcat-online-interpreter.min.js" type="module" defer integrity="sha512-M69E3EvXXLoyRDCdiSPk84Pnb7YoMTXRqqH2u5nzRTaxP3PWZw2b1eYhCqsimgWbUaeM5kSCuIxJQhwcNIjf0w=="></script>
<script src="smcat-online-interpreter.min.js" type="module" defer integrity="sha512-JFcPEOL9zVRvLlspORt02ETHoKUWv8R2XhdmBO7VI0c6my3zL0u0xgeZUcaYPQWDMLvoj1SFuFJ+vU+4GupJQA=="></script>
<script defer src="https://code.getmdl.io/1.3.0/material.min.js" async></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="purple">
Expand Down
2 changes: 1 addition & 1 deletion docs/inpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
src="state-machine-cat-inpage.min.js"
type="module"
defer
integrity="sha512-10ptXyICQRHVV4qeTbXjuMxYvHieH1nnDhRH4JEYCtWnb+IkVy88qd1pwNJ0waRbKn9eokgxAJgJCb6jnTsGBA=="
integrity="sha512-52vZVh/elfXk881aqqod5J6ZLaHea1tt7k0RFATXooP+1NCeIRS0NN0GE8rfDIrMAQWUH0FVxCUKwqaSfGVb2Q=="
></script>
<style>
body { font-family: sans-serif; margin: 0 auto; max-width: 799px;
Expand Down
2 changes: 1 addition & 1 deletion docs/smcat-online-interpreter.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/smcat-online-interpreter.min.js.map

Large diffs are not rendered by default.

98 changes: 49 additions & 49 deletions docs/state-machine-cat-inpage.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/state-machine-cat-inpage.min.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/counter.mts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export class Counter {
_lHWM = 0;
#lHWM = 0;

constructor(pStart: number = 0) {
this._lHWM = pStart;
this.#lHWM = pStart;
}

next(): number {
// eslint-disable-next-line no-plusplus
return ++this._lHWM;
return ++this.#lHWM;
}
}
30 changes: 15 additions & 15 deletions src/state-machine-model.mts
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,31 @@ function flattenTransitions(pStateMachine: IStateMachine): ITransition[] {
}

export default class StateMachineModel {
private _flattenedTransitions: ITransition[];
private _flattenedStates: Map<string, IFlattenedState>;
#flattenedTransitions: ITransition[];
#flattenedStates: Map<string, IFlattenedState>;

constructor(pStateMachine: IStateMachine) {
this._flattenedStates = new Map();
flattenStatesToMap(pStateMachine.states ?? [], this._flattenedStates);
this._flattenedTransitions = flattenTransitions(pStateMachine);
this.#flattenedStates = new Map();
flattenStatesToMap(pStateMachine.states ?? [], this.#flattenedStates);
this.#flattenedTransitions = flattenTransitions(pStateMachine);
}

get flattenedTransitions(): ITransition[] {
return this._flattenedTransitions;
return this.#flattenedTransitions;
}

findStateByName(pName: string): IFlattenedState | undefined {
return this._flattenedStates.get(pName);
return this.#flattenedStates.get(pName);
}

findStatesByTypes(pTypes: StateType[]): any[] {
return Array.from(this._flattenedStates.values()).filter((pState) =>
return Array.from(this.#flattenedStates.values()).filter((pState) =>
pTypes.includes(pState.type),
);
}

findExternalSelfTransitions(pStateName: string): ITransition[] {
return this._flattenedTransitions.filter(
return this.#flattenedTransitions.filter(
(pTransition) =>
pTransition.from === pStateName &&
pTransition.to === pStateName &&
Expand All @@ -94,31 +94,31 @@ export default class StateMachineModel {
}

findTransitionsByFrom(pFromStateName: string): ITransition[] {
return this._flattenedTransitions.filter(
return this.#flattenedTransitions.filter(
(pTransition) => pTransition.from === pFromStateName,
);
}

findTransitionsByTo(pToStateName: string): ITransition[] {
return this._flattenedTransitions.filter(
return this.#flattenedTransitions.filter(
(pTransition) => pTransition.to === pToStateName,
);
}

getMaximumTransitionId(): number {
return Math.max(...this._flattenedTransitions.map(({ id }) => id));
return Math.max(...this.#flattenedTransitions.map(({ id }) => id));
}

findTransitionsToSiblings(
pStateName: string,
pExcludeIds: Set<number>,
): ITransition[] {
return this._flattenedTransitions.filter(
return this.#flattenedTransitions.filter(
(pTransition) =>
!pExcludeIds.has(pTransition.id) &&
pTransition.from === pStateName &&
this._flattenedStates.get(pTransition.to)?.parent ===
this._flattenedStates.get(pStateName)?.parent,
this.#flattenedStates.get(pTransition.to)?.parent ===
this.#flattenedStates.get(pStateName)?.parent,
);
}
}

0 comments on commit 8b11f73

Please sign in to comment.