mirror of
https://github.com/robonen/tools.git
synced 2026-03-20 02:44:45 +00:00
chore(core/stdlib): fix lint
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
import type { MaybePromise } from '../../../types';
|
import type { MaybePromise } from '../../../types';
|
||||||
|
|
||||||
export type Command = {
|
export interface Command {
|
||||||
execute: () => void;
|
execute: () => void;
|
||||||
undo: () => void;
|
undo: () => void;
|
||||||
};
|
}
|
||||||
|
|
||||||
export type AsyncCommand = {
|
export interface AsyncCommand {
|
||||||
execute: () => MaybePromise<void>;
|
execute: () => MaybePromise<void>;
|
||||||
undo: () => MaybePromise<void>;
|
undo: () => MaybePromise<void>;
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
export class BaseStateMachine<
|
export class BaseStateMachine<
|
||||||
States extends string,
|
States extends string,
|
||||||
Events extends string,
|
_Events extends string,
|
||||||
Context,
|
Context,
|
||||||
NodeConfig,
|
NodeConfig,
|
||||||
> {
|
> {
|
||||||
|
|||||||
@@ -7,18 +7,18 @@ import type { MaybePromise } from '../../../types';
|
|||||||
* @template Guard - Guard return type (boolean or MaybePromise\<boolean\>)
|
* @template Guard - Guard return type (boolean or MaybePromise\<boolean\>)
|
||||||
* @template Action - Action return type (void or MaybePromise\<void\>)
|
* @template Action - Action return type (void or MaybePromise\<void\>)
|
||||||
*/
|
*/
|
||||||
export type TransitionConfig<
|
export interface TransitionConfig<
|
||||||
Context,
|
Context,
|
||||||
Guard = boolean,
|
Guard = boolean,
|
||||||
Action = void,
|
Action = void,
|
||||||
> = {
|
> {
|
||||||
/** Target state to transition to */
|
/** Target state to transition to */
|
||||||
target: string;
|
target: string;
|
||||||
/** Guard condition — transition only occurs if this returns true */
|
/** Guard condition — transition only occurs if this returns true */
|
||||||
guard?: (context: Context) => Guard;
|
guard?: (context: Context) => Guard;
|
||||||
/** Side effect executed during transition (before entering target state) */
|
/** Side effect executed during transition (before entering target state) */
|
||||||
action?: (context: Context) => Action;
|
action?: (context: Context) => Action;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A transition can be a target state name or a detailed configuration
|
* A transition can be a target state name or a detailed configuration
|
||||||
@@ -36,18 +36,18 @@ export type Transition<
|
|||||||
* @template Guard - Guard return type
|
* @template Guard - Guard return type
|
||||||
* @template Hook - Hook return type (entry/exit/action)
|
* @template Hook - Hook return type (entry/exit/action)
|
||||||
*/
|
*/
|
||||||
export type StateNodeConfig<
|
export interface StateNodeConfig<
|
||||||
Context,
|
Context,
|
||||||
Guard = boolean,
|
Guard = boolean,
|
||||||
Hook = void,
|
Hook = void,
|
||||||
> = {
|
> {
|
||||||
/** Map of event names to transitions */
|
/** Map of event names to transitions */
|
||||||
on?: Record<string, Transition<Context, Guard, Hook>>;
|
on?: Record<string, Transition<Context, Guard, Hook>>;
|
||||||
/** Hook called when entering this state */
|
/** Hook called when entering this state */
|
||||||
entry?: (context: Context) => Hook;
|
entry?: (context: Context) => Hook;
|
||||||
/** Hook called when exiting this state */
|
/** Hook called when exiting this state */
|
||||||
exit?: (context: Context) => Hook;
|
exit?: (context: Context) => Hook;
|
||||||
};
|
}
|
||||||
|
|
||||||
/** Sync state node config — guards return boolean, hooks return void */
|
/** Sync state node config — guards return boolean, hooks return void */
|
||||||
export type SyncStateNodeConfig<Context> = StateNodeConfig<Context, boolean, void>;
|
export type SyncStateNodeConfig<Context> = StateNodeConfig<Context, boolean, void>;
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export class BinaryHeap<T> implements BinaryHeapLike<T> {
|
|||||||
constructor(initialValues?: T[] | T, options?: BinaryHeapOptions<T>) {
|
constructor(initialValues?: T[] | T, options?: BinaryHeapOptions<T>) {
|
||||||
this.comparator = options?.comparator ?? defaultComparator;
|
this.comparator = options?.comparator ?? defaultComparator;
|
||||||
|
|
||||||
if (initialValues != null) {
|
if (initialValues !== null && initialValues !== undefined) {
|
||||||
const items = isArray(initialValues) ? initialValues : [initialValues];
|
const items = isArray(initialValues) ? initialValues : [initialValues];
|
||||||
this.heap.push(...items);
|
this.heap.push(...items);
|
||||||
this.heapify();
|
this.heapify();
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export class CircularBuffer<T> implements CircularBufferLike<T> {
|
|||||||
* @private
|
* @private
|
||||||
* @type {(T | undefined)[]}
|
* @type {(T | undefined)[]}
|
||||||
*/
|
*/
|
||||||
private buffer: (T | undefined)[];
|
private buffer: Array<T | undefined>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The index of the front element
|
* The index of the front element
|
||||||
@@ -53,7 +53,7 @@ export class CircularBuffer<T> implements CircularBufferLike<T> {
|
|||||||
const requested = Math.max(items.length, initialCapacity ?? 0);
|
const requested = Math.max(items.length, initialCapacity ?? 0);
|
||||||
const cap = Math.max(MIN_CAPACITY, nextPowerOfTwo(requested));
|
const cap = Math.max(MIN_CAPACITY, nextPowerOfTwo(requested));
|
||||||
|
|
||||||
this.buffer = new Array(cap);
|
this.buffer = Array.from<T | undefined>({ length: cap });
|
||||||
|
|
||||||
for (const item of items)
|
for (const item of items)
|
||||||
this.pushBack(item);
|
this.pushBack(item);
|
||||||
@@ -190,7 +190,7 @@ export class CircularBuffer<T> implements CircularBufferLike<T> {
|
|||||||
* @returns {this}
|
* @returns {this}
|
||||||
*/
|
*/
|
||||||
clear() {
|
clear() {
|
||||||
this.buffer = new Array(MIN_CAPACITY);
|
this.buffer = Array.from<T | undefined>({ length: MIN_CAPACITY });
|
||||||
this.head = 0;
|
this.head = 0;
|
||||||
this.count = 0;
|
this.count = 0;
|
||||||
|
|
||||||
@@ -203,7 +203,7 @@ export class CircularBuffer<T> implements CircularBufferLike<T> {
|
|||||||
* @returns {T[]}
|
* @returns {T[]}
|
||||||
*/
|
*/
|
||||||
toArray() {
|
toArray() {
|
||||||
const result = new Array<T>(this.count);
|
const result = Array.from<T>({ length: this.count });
|
||||||
|
|
||||||
for (let i = 0; i < this.count; i++)
|
for (let i = 0; i < this.count; i++)
|
||||||
result[i] = this.buffer[(this.head + i) & (this.buffer.length - 1)] as T;
|
result[i] = this.buffer[(this.head + i) & (this.buffer.length - 1)] as T;
|
||||||
@@ -246,7 +246,7 @@ export class CircularBuffer<T> implements CircularBufferLike<T> {
|
|||||||
*/
|
*/
|
||||||
private grow() {
|
private grow() {
|
||||||
const newCapacity = this.buffer.length << 1;
|
const newCapacity = this.buffer.length << 1;
|
||||||
const newBuffer = new Array<T | undefined>(newCapacity);
|
const newBuffer = Array.from<T | undefined>({ length: newCapacity });
|
||||||
|
|
||||||
for (let i = 0; i < this.count; i++)
|
for (let i = 0; i < this.count; i++)
|
||||||
newBuffer[i] = this.buffer[(this.head + i) & (this.buffer.length - 1)];
|
newBuffer[i] = this.buffer[(this.head + i) & (this.buffer.length - 1)];
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export class LinkedList<T> implements LinkedListLike<T> {
|
|||||||
* @private
|
* @private
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
private count: number = 0;
|
private count = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The first node in the list
|
* The first node in the list
|
||||||
@@ -54,7 +54,7 @@ export class LinkedList<T> implements LinkedListLike<T> {
|
|||||||
* @param {(T[] | T)} [initialValues] The initial values to add to the list
|
* @param {(T[] | T)} [initialValues] The initial values to add to the list
|
||||||
*/
|
*/
|
||||||
constructor(initialValues?: T[] | T) {
|
constructor(initialValues?: T[] | T) {
|
||||||
if (initialValues != null) {
|
if (initialValues !== null && initialValues !== undefined) {
|
||||||
const items = isArray(initialValues) ? initialValues : [initialValues];
|
const items = isArray(initialValues) ? initialValues : [initialValues];
|
||||||
|
|
||||||
for (const item of items)
|
for (const item of items)
|
||||||
@@ -258,7 +258,7 @@ export class LinkedList<T> implements LinkedListLike<T> {
|
|||||||
* @returns {T[]} Array of values from head to tail
|
* @returns {T[]} Array of values from head to tail
|
||||||
*/
|
*/
|
||||||
public toArray(): T[] {
|
public toArray(): T[] {
|
||||||
const result = new Array<T>(this.count);
|
const result = Array.from<T>({ length: this.count });
|
||||||
let current = this.first;
|
let current = this.first;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user