UNPKG

pushinka

Version:

Pushinka: Transactional, Reactive, and Asynchronous State Management

128 lines (127 loc) 5.53 kB
import { LogCtx } from "./Log"; import { Member } from "./Member"; import { XRecord } from "./Record"; import { XHandle } from "./Handle"; import { XMonitor } from "./Monitor"; export declare function state(proto: object, prop?: PropertyKey): any; export declare function stateless(proto: object, prop: PropertyKey): any; export declare function transaction(proto: object, prop: PropertyKey, pd: TypedPropertyDescriptor<F<any>>): any; export declare function separateTransaction(proto: object, prop: PropertyKey, pd: TypedPropertyDescriptor<F<any>>): any; export declare function reaction(proto: object, prop: PropertyKey, pd: TypedPropertyDescriptor<F<any>>): any; export declare type F<T> = (...args: any[]) => T; export declare class Transaction { private static id; static snapshot: number; static running?: Transaction; static stack: Transaction[]; static history: Transaction[]; static historyCapacity: number; readonly id: number; readonly hint: string; readonly snapshot: number; readonly error: any; private _snapshot; private changeset; private pending; private sealed; private _error; private resultPromise?; private resultResolve; private resultReject; private conflicts?; private reactions; private effect; constructor(hint: string); static readonly current: Transaction | undefined; run<T>(func: F<T>, ...args: any[]): T; commit(): void; seal(): Transaction; discard(error?: any): Transaction; finished(): boolean; whenFinished(includingReactions: boolean): Promise<void>; undo(): void; static run<T>(func: F<T>, ...args: any[]): T; static runAs<T>(hint: string, root: boolean, func: F<T>, ...args: any[]): T; private _run; private static seal; getRelevant(h: Handle): Record | undefined; static getForView(h: Handle): Record; static tryGetForEdit(h: Handle, prop: PropertyKey, value: any): Record | undefined; static getForEdit(h: Handle, prop: PropertyKey): Record; private checkConflictsResolved; private tryResolveConflicts; static determineConflicts(ours: Record, head: Record, conflicts: Map<PropertyKey, Record>): boolean; static formatConflictsSummary(conflicts: Record[]): string; static formatConflictingProperty(prop: PropertyKey, ours: Record, theirs: Record): string; private acquireSnapshot; private releaseSnapshot; private performCommit; private performDiscard; static applyChanges(success: boolean, changeset: Map<Handle, Record>): void; static acquireHandle(obj: any): Handle; private acquirePromise; private cleanup; static _wrap<T>(t: Transaction, c: Cache | undefined, inc: boolean, dec: boolean, func: F<T>): F<T>; } export declare abstract class Reaction { abstract latency: number; abstract monitor: Monitor | undefined; abstract readonly cachedResult: any; abstract readonly cachedAsyncResult: any; abstract readonly cachedError: any; abstract readonly invalidator: string | undefined; abstract invalidate(invalidator: string | undefined): boolean; readonly isInvalidated: boolean; static get(method: F<any>): Reaction; static dismissAll(...objects: any[]): Transaction; } declare class Handle extends XHandle<Transaction, Cache> { } declare class Record extends XRecord<Transaction, Cache> { } export declare class Monitor extends XMonitor { constructor(name: string); } declare class Cache { static running?: Cache; readonly margin: number; readonly owner: Handle; readonly member: Member; readonly actionId: number; latency: number; monitor?: Monitor; args?: any[]; cachedResult: any; cachedAsyncResult: any; cachedError: any; invalidator?: string; readonly observables: Map<PropertyKey, Set<Record>>; constructor(owner: Handle, member: Member, actionId: number, latency: number, monitor?: Monitor); readonly hint: string; static run<T>(c: Cache | undefined, func: F<T>, ...args: any[]): T; wrap<T>(func: F<T>): F<T>; ensureUpToDate(now: boolean, ...args: any[]): void; static registerPropView(r: Record, prop: PropertyKey): void; static registerPropEdit(r: Record, prop: PropertyKey, edited: boolean, valueHint: string): void; static propagateChanges(changeset: Map<Handle, Record>, reactions: Cache[]): void; static acquireSetOfObservers(r: Record, prop: PropertyKey): Set<Cache>; private linkWithAllObservables; static retainPrevObservers(r: Record, prop: PropertyKey, prev: Record, prevObservers: Set<Cache>): Set<Cache>; invalidate(invalidator: string, reactions: Cache[]): void; static enforceInvalidation(c: Cache, invalidator: string, latency: number): boolean; static markOverwritten(self: Record | undefined, prop: PropertyKey, reactions: Cache[]): void; static ensureAllUpToDate(hint: string, reactions: Cache[], effect: { tran?: Transaction; }): void; static trap(h: Handle, m: Member): F<any>; static enterMonitor(monitor?: Monitor): void; static leaveMonitor(monitor?: Monitor): void; static freeze(c: Cache): void; static dismiss(c: Cache): void; static logCtx(op: string): LogCtx; } export declare class Tools { static setHint<T, C>(obj: object, hint: string): void; static equal(oldValue: any, newValue: any): boolean; } export {};