File tree 2 files changed +14
-12
lines changed
2 files changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -53,22 +53,18 @@ Using TypeScript you can pass `State` and `Events` interface to the `createStore
53
53
#### ` store.ts `
54
54
55
55
``` typescript
56
- import { Store , StoreonEvents , createStoreon } from ' storeon'
56
+ import { StoreonModule , createStoreon } from ' storeon'
57
57
58
- // State structure
59
58
interface State {
60
59
count: number
61
60
}
62
61
63
- // Events declaration: map of event names to type of event data
64
- interface Events extends StoreonEvents <State > {
65
- // `inc` event which do not goes with any data
62
+ interface Events {
66
63
' inc' : undefined
67
- // `set` event which goes with number as data
68
64
' set' : number
69
65
}
70
66
71
- let counter = (store : Store <State >) => {
67
+ let counter = (store : StoreonModule <State , Events >) => {
72
68
store .on (' @init' , () => ({ count: 0 }))
73
69
store .on (' inc' , ({ count }) => ({ count: count + 1 }))
74
70
store .on (' set' , (_ , event ) => ({ count: event }))
Original file line number Diff line number Diff line change 1
- import { Store , StoreonEvents , Dispatch } from 'storeon' ;
1
+ import { StoreonStore , StoreonDispatch , createStoreon } from 'storeon' ;
2
+
3
+ type Subscriber < T > = ( value : T ) => void ;
4
+
5
+ type Unsubscriber = ( ) => void ;
2
6
3
7
type Subscribable < State > = {
4
- [ K in keyof State ] : { subscribe : ( run : ( state : State [ K ] ) => void ) => ( ) => void ; } ;
8
+ [ K in keyof State ] : {
9
+ subscribe : ( run : Subscriber < State [ K ] > ) => Unsubscriber ;
10
+ } ;
5
11
}
6
12
7
- export declare function setStore ( store : Store ) : void
8
- export declare function getStore < State , EventsMap extends StoreonEvents < State > = any > ( ...keys : ( keyof State ) [ ] ) : Subscribable < State > & {
9
- dispatch : Dispatch < EventsMap >
13
+ export declare function setStore ( store : StoreonStore ) : void
14
+ export declare function getStore < State , Events = any > ( ...keys : ( keyof State ) [ ] ) : Subscribable < State > & {
15
+ dispatch : StoreonDispatch < Events & createStoreon . DispatchableEvents < State > >
10
16
}
You can’t perform that action at this time.
0 commit comments