Skip to content

Commit 1a66631

Browse files
author
Péter Hauszknecht
committed
update README and documentation
1 parent e7d3e2a commit 1a66631

3 files changed

Lines changed: 13 additions & 27 deletions

File tree

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,6 @@ A repatch middleware takes the `store` instance, a `next` function and the previ
9090
Middleware: Store -> Next -> Reducer -> any
9191
```
9292

93-
where
94-
95-
```javascript
96-
Next: Reducer -> Reducer
97-
```
98-
9993
Use the `addMiddleware` method to chaining middlewares:
10094

10195
```javascript

docs/store.md

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The `Store` holds the whole state tree of your application. You need to instantiate it.
44

5-
## Constructor
5+
## **`constructor(initialState: State)`**
66

77
#### Arguments
88

@@ -22,7 +22,7 @@ const store = new Store({ counter: 0 })
2222

2323
## Methods
2424

25-
### `getState()`
25+
### **`getState(): State`**
2626

2727
This method returns the current state of the store.
2828

@@ -40,17 +40,17 @@ const state = store.getState()
4040
console.log(state.counter === 0) // true
4141
```
4242

43-
### `dispatch(reducer)`
43+
### **`dispatch(reducer: Reducer): State`**
4444

4545
Dispatches a reducer.
4646

4747
#### Arguments
4848

49-
1) **reducer** (*ReducerFunction: State -> State*): That reducer will reduce the state of the store. This takes the current state and returns the next state.
49+
1) **reducer** (*Reducer: State -> State*): That reducer will reduce the state of the store. This takes the current state and returns the next state.
5050

5151
#### Returns
5252

53-
(*ReducerFunction*): The final reducer that is made by applying the middlewares - if they are given. If the store does enhanced with middlewares, the `dispatch` method returns the same reducer that was taken as argument.
53+
(*State*): The new state after reducing.
5454

5555
#### Example
5656

@@ -66,19 +66,19 @@ console.log(result === increment) // true
6666

6767
#### Notes
6868

69-
Middlewares can modify the given reducer, so that is not guaranteed that the `dispatch` returns the original reducer that was taken as argument.
69+
If you use middlewares, that is not guaranteed that the `dispatch` returns the new state. For example `thunk` middleware modify `dispatch` that it returns the result of delegate function.
7070

71-
### `subscribe(listener)`
71+
### **`subscribe(listener: Listener): Unsubscribe`**
7272

7373
Adds a state change listener.
7474

7575
#### Arguments
7676

77-
1) **listener** (*ListenerFunction: void -> void*): The listener that will be synchronously run after the state was modified by dispatching a reducer.
77+
1) **listener** (*Listener: void -> void*): The listener that will be synchronously run after the state was modified by dispatching a reducer.
7878

7979
#### Returns
8080

81-
(*UnsubscribeFunction: void -> void*): The unsubscribe function, that you can use to unsubscribe the given listener.
81+
(*Unsubscribe: void -> void*): The unsubscribe function, that you can use to unsubscribe the given listener.
8282

8383
#### Example
8484

@@ -96,15 +96,15 @@ unsubscribe()
9696
store.dispatch(increment) // listener won't be fired
9797
```
9898

99-
### `addMiddleware(...middlewares)`
99+
### **`addMiddleware(...middlewares: Middleware[]): Store`**
100100

101101
Enhances the store with the given middleware(s).
102102

103103
Middlewares will be run at dispatching before the store applies the new state of the reducer. The added middlewares are composed by order of addition, so the last added middleware will run first.
104104

105105
#### Arguments
106106

107-
1) **...middlewares** (*MiddlewareFunction: Store -> Next -> Reducer -> any*): Middlewares as variadic arguments. Middleware functions take the `store` instance, a `next` function and the previous `reducer`. The middleware can provide a new reducer via the `next` function.
107+
1) **...middlewares** (*Middleware: Store -> Next -> Reducer -> any*): Middlewares as variadic arguments. Middleware functions take the `store` instance, a `next` function and the previous `reducer`. The middleware can provide a new reducer via the `next` function.
108108

109109
#### Returns
110110

@@ -124,10 +124,4 @@ const store = new Store({ counter: 0 }).addMiddleware(logger)
124124

125125
store.dispatch(state => ({ counter: state.counter + 1 }))
126126
// logger logs { counter: 0 } { counter: 1 }
127-
```
128-
129-
## Static members
130-
131-
### `thunk`
132-
133-
The [thunk](thunk.md) middleware.
127+
```

docs/thunk.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
Thunk is a repatch middleware to handle async actions. It is very similar to [redux-thunk](https://www.npmjs.com/package/redux-thunk). Thunk middleware allows you to create reducers that returns a function (delegate). The delegate will be fired at dispatching.
44

5-
## ThunkMiddleware
6-
7-
`State -> Delegate`
5+
`Thunk: State -> Delegate`
86

97
#### Example
108

0 commit comments

Comments
 (0)