From aa92eb1440abdff3e6c50abe8b2794019898d3df Mon Sep 17 00:00:00 2001 From: Lucas Ciruzzi Date: Tue, 20 Nov 2018 20:26:00 -0300 Subject: [PATCH 1/2] Added types. --- index.d.ts | 10 ++++++++++ worker.d.ts | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 index.d.ts create mode 100644 worker.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..4245769 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,10 @@ +import { WorkerStore } from "./worker"; +import { Store } from "unistore"; + +/** + * Create a new store based on a Worker. + * @param worker Instance of WorkerStore. + */ +export default function createStore( + worker: WorkerStore +): Store; diff --git a/worker.d.ts b/worker.d.ts new file mode 100644 index 0000000..9ba29f1 --- /dev/null +++ b/worker.d.ts @@ -0,0 +1,55 @@ +import { Action, Store } from "unistore"; + +/** + * Actions object. + */ +export interface Actions { + [action: string]: Action; +} + +/** + * Types of actions received by registerActions. + */ +export type ActionRegister = ( + store: WorkerStore +) => Actions | Actions; + +/** + * Enhanced unistore store. + */ +export interface WorkerStore extends Store { + + /** + * Creates a new instance of WorkerStore. + */ + new(): WorkerStore; + + /** + * List of registered actions. + */ + actions: Actions; + + /** + * Register new actions. + * @param newActions Object or callback function. + */ + registerActions(newActions: ActionRegister): void; + + /** + * Queue all additional processing until unfrozen. + */ + freeze(): void; + + /** + * Remove a freeze lock and process queued work + */ + unfreeze(): void; +} + +/** + * Creates a WebWorker unistore instance. + * @param initialState Initial state to populate. + */ +export default function createWorkerStore( + initialState: WorkerState +): WorkerStore; From 23a024b660e3d8939997a81f7ced679f968e4546 Mon Sep 17 00:00:00 2001 From: Lucas Ciruzzi Date: Tue, 20 Nov 2018 20:46:21 -0300 Subject: [PATCH 2/2] Added fixes for stockroom action method --- index.d.ts | 2 +- worker.d.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 4245769..cf6e03f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -7,4 +7,4 @@ import { Store } from "unistore"; */ export default function createStore( worker: WorkerStore -): Store; +): WorkerStore; diff --git a/worker.d.ts b/worker.d.ts index 9ba29f1..1782831 100644 --- a/worker.d.ts +++ b/worker.d.ts @@ -24,6 +24,12 @@ export interface WorkerStore extends Store { */ new(): WorkerStore; + /** + * Retrieves the given action. + * @param action Action to retrieve (Worker actions take strings). + */ + action(action: Action | string): (...params: any[]) => void; + /** * List of registered actions. */