Skip to content

Commit

Permalink
Add TypeScript definitions for store (fixes #1207)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulBGD committed Mar 5, 2018
1 parent 18d3313 commit e7f448d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions store.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
interface Options {
immutable: boolean;
}

interface ObserveOptions {
defer: boolean;
init: boolean;
}

interface Cancellable {
cancel: () => void;
}

export declare class Store<State> {
constructor(state: State, options?: Options);

public compute(key: string, dependencies: string[]): void;

This comment has been minimized.

Copy link
@bwbroersma

bwbroersma Mar 6, 2018

Contributor

compute always has 3 arguments, but a variable callback parameters (and types), would the following work?

public compute<T>(key: string, dependencies: string[], computeFunction: ((...value: any[]) => T)): void;
public get(): State;
public get<T>(key: string): T;
public observe<T>(key: string, callback: (value: T) => any, options?: ObserveOptions): Cancellable;

This comment has been minimized.

Copy link
@bwbroersma

bwbroersma Mar 6, 2018

Contributor

observe callbacks have 2 callback parameters / docs, so:

callback: (newValue: T, oldValue: T) => any
public onchange(callback: (state: State) => any): Cancellable;
public set(state: State);
}

0 comments on commit e7f448d

Please sign in to comment.