Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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<WorkerState>(
worker: WorkerStore<WorkerState>
): WorkerStore<WorkerState>;
61 changes: 61 additions & 0 deletions worker.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Action, Store } from "unistore";

/**
* Actions object.
*/
export interface Actions<WorkerState> {
[action: string]: Action<WorkerState>;
}

/**
* Types of actions received by registerActions.
*/
export type ActionRegister<WorkerState> = (
store: WorkerStore<WorkerState>
) => Actions<WorkerState> | Actions<WorkerState>;

/**
* Enhanced unistore store.
*/
export interface WorkerStore<WorkerState> extends Store<WorkerState> {

/**
* Creates a new instance of WorkerStore.
*/
new(): WorkerStore<WorkerState>;

/**
* Retrieves the given action.
* @param action Action to retrieve (Worker actions take strings).
*/
action(action: Action<WorkerState> | string): (...params: any[]) => void;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one is already defined on Store, right?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @developit, no worries about the time to review (with the recent release of Preact X, I understand). About your question, Unistore's action doesn't work exactly like Stockroom's action. Stockroom takes an Action or a string, and Unistore (afaik) only takes an Action. Also Stockroom returns void where Unistore returns the BoundAction.


/**
* List of registered actions.
*/
actions: Actions<WorkerState>;

/**
* Register new actions.
* @param newActions Object or callback function.
*/
registerActions(newActions: ActionRegister<WorkerState>): 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<WorkerState>(
initialState: WorkerState
): WorkerStore<WorkerState>;