fix: Remove ImperativeState type restriction.

This commit is contained in:
Sidharth Vinod
2024-04-13 11:50:19 +05:30
parent 12bd301401
commit 866d9416b4
2 changed files with 7 additions and 8 deletions

View File

@@ -1,5 +1,6 @@
import { getConfig } from '../../diagram-api/diagramAPI.js'; import { getConfig } from '../../diagram-api/diagramAPI.js';
import { log } from '../../logger.js'; import { log } from '../../logger.js';
import { ImperativeState } from '../../utils/imperativeState.js';
import { sanitizeText } from '../common/common.js'; import { sanitizeText } from '../common/common.js';
import { import {
clear as commonClear, clear as commonClear,
@@ -10,11 +11,9 @@ import {
setAccTitle, setAccTitle,
setDiagramTitle, setDiagramTitle,
} from '../common/commonDb.js'; } from '../common/commonDb.js';
import { ImperativeState } from '../../utils/imperativeState.js';
import type { Actor, AddMessageParams, Box, Message, Note } from './types.js'; import type { Actor, AddMessageParams, Box, Message, Note } from './types.js';
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions interface SequenceState {
type State = {
prevActor?: string; prevActor?: string;
actors: Record<string, Actor>; actors: Record<string, Actor>;
createdActors: Record<string, number>; createdActors: Record<string, number>;
@@ -27,9 +26,9 @@ type State = {
currentBox?: Box; currentBox?: Box;
lastCreated?: Actor; lastCreated?: Actor;
lastDestroyed?: Actor; lastDestroyed?: Actor;
}; }
const state = new ImperativeState<State>(() => ({ const state = new ImperativeState<SequenceState>(() => ({
prevActor: undefined, prevActor: undefined,
actors: {}, actors: {},
createdActors: {}, createdActors: {},

View File

@@ -2,11 +2,11 @@
* Resettable state storage. * Resettable state storage.
* @example * @example
* ``` * ```
* const state = new ImperativeState(() => { * const state = new ImperativeState(() => ({
* foo: undefined as string | undefined, * foo: undefined as string | undefined,
* bar: [] as number[], * bar: [] as number[],
* baz: 1 as number | undefined, * baz: 1 as number | undefined,
* }); * }));
* *
* state.records.foo = "hi"; * state.records.foo = "hi";
* console.log(state.records.foo); // prints "hi"; * console.log(state.records.foo); // prints "hi";
@@ -21,7 +21,7 @@
* // } * // }
* ``` * ```
*/ */
export class ImperativeState<S extends Record<string, unknown>> { export class ImperativeState<S> {
public records: S; public records: S;
/** /**