File tree 3 files changed +26
-8
lines changed
3 files changed +26
-8
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ npm-debug.log
4
4
yarn-error.log
5
5
yarn.lock
6
6
7
- * .spec .js
7
+ * .test .js
8
8
.travis.yml
9
9
10
10
node_modules /
Original file line number Diff line number Diff line change @@ -34,15 +34,33 @@ Use `createSvelteStore` from the `@storeon/svelte` package instead of using `cre
34
34
import { createSvelteStore } from " @storeon/svelte" ;
35
35
36
36
let counter = store => {
37
- // Initial state
38
37
store .on (" @init" , () => ({ count: 0 }));
39
- // Reducers returns only changed part of the state
40
38
store .on (" inc" , ({ count }) => ({ count: count + 1 }));
41
39
};
42
40
43
41
export const connect = createSvelteStore ([counter]);
44
42
```
45
43
44
+ Using TypeScript you can pass ` State ` interface to the ` createSvelteStore ` function
45
+
46
+ #### ` store.ts `
47
+
48
+ ``` typescript
49
+ import { Store } from ' storeon' ;
50
+ import { createSvelteStore } from " @storeon/svelte" ;
51
+
52
+ interface State {
53
+ count: number ;
54
+ }
55
+
56
+ let counter = (store : Store <State >) => {
57
+ store .on (" @init" , () => ({ count: 0 }));
58
+ store .on (" inc" , ({ count }) => ({ count: count + 1 }));
59
+ };
60
+
61
+ export const connect = createSvelteStore <State >([counter ]);
62
+ ```
63
+
46
64
Import ` connect ` function from our ` ./store ` and use it for getting state and dispatching new events
47
65
48
66
#### ` App.svelte `
Original file line number Diff line number Diff line change 1
- import { Dispatch } from " storeon" ;
1
+ import { Module , Dispatch } from ' storeon' ;
2
2
3
- declare function createSvelteStore < T > (
4
- modules : any [ ]
5
- ) : ( key : string ) => [ Dispatch , any ] ;
3
+ interface Changes < State , K extends keyof State > {
4
+ subscribe : ( run : ( state : State [ K ] ) => void ) => ( ) => void ;
5
+ }
6
6
7
- export { createSvelteStore } ;
7
+ export declare function createSvelteStore < State > ( modules : Module < State > [ ] ) : < K extends keyof State > ( key : K ) => [ Dispatch , Changes < State , K > ] ;
You can’t perform that action at this time.
0 commit comments