Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc21f709

Browse files
committed
Return mapStoreToProps from build function
1 parentb9a01ef commitc21f709

File tree

6 files changed

+32
-34
lines changed

6 files changed

+32
-34
lines changed

‎README.md‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,10 @@ const layoutReducer = new ReducerBuilder<LayoutState>()
4747
)
4848

4949
// Build store
50-
exportconst store=newStoreBuilder<StoreState>()
50+
exportconst[store, mapStoreToProps]=newStoreBuilder<StoreState>()
5151
.withReducerBuildersMap({ layout:layoutReducer })
5252
.withDevTools()// enable chrome devtools
5353
.build()
54-
55-
export {mapStoreToProps } =store
5654
```
5755

5856
```tsx
@@ -99,7 +97,7 @@ import { connectRouter, routerMiddleware } from 'connected-react-router'
9997

10098
exportconsthistory=createBrowserHistory()
10199
constrouterReducer=connectRouter(history)
102-
exportconststore=newStoreBuilder<StoreState>()
100+
exportconst[store]=newStoreBuilder<StoreState>()
103101
.withMiddleware(routerMiddleware(history))
104102
.withReducer('router',routerReducer)
105103
.withDevTools()// enable chrome devtools
@@ -137,20 +135,18 @@ Create redux store with builder pattern.
137135
import {StoreBuilder }from'redux-ts'
138136
import {authReducer }from'./reducers/authReducer'
139137

140-
conststore=newStoreBuilder<StoreState>()
138+
exportconst[store,mapStoreToProps]=newStoreBuilder<StoreState>()
141139
.withInitialState({test:true})
142140
.withMiddleware()
143141
.withReducer("auth",authReducer)
144142
.withDevTools()
145143
.build();
146144
}
147-
148-
export {mapStoreToProps }=store
149145
```
150146
151147
- As generic parameter, it requires store state type in order to match given reducers and the state.
152148
- Any number of middleware, enhancer or reducer can be used to build the state.
153-
-`mapStoreToProps` ispublicmethod thatis exposed from store object. This method can be used to map store object to props which are consumed from connected components. Return type is`MapStateToPropsParam` which is compatible with [connect](https://react-redux.js.org/api/connect).
149+
-`mapStoreToProps` isa dummymethod thatreturns passed parameter again. This method can be used to map store object to props which are consumed from connected components. Return type is`MapStateToPropsParam` which is compatible with [connect](https://react-redux.js.org/api/connect).
154150
155151
### Actions
156152

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name":"redux-ts",
3-
"version":"4.1.8",
3+
"version":"4.2.0-rc.2",
44
"description":"Utils to define redux reducer/action in typescript",
55
"main":"dist/redux-ts.production.min.js",
6-
"typings":"dist/src/index.d.ts",
6+
"types":"lib/index.d.ts",
77
"files": [
88
"*.md",
99
"dist",

‎src/store.builder.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,21 @@ export class StoreBuilder<S extends StoreState> {
148148
* As paramter, mapper function is required which takes store object and returns indexer object
149149
* You can expose that function from your store object to be able to use on connected components.
150150
* ex.
151-
* const store = new StoreBuilder<StoreState>().build()
152-
* export { mapStoreToProps } = store
151+
* const[store, mapStoreToProps] = new StoreBuilder<StoreState>().build()
152+
* export { mapStoreToProps }
153153
*
154-
*@type {StateToProps<StoreState>}
154+
*@type {StateToProps<S>}
155155
*@memberof StoreBuilder
156156
*/
157-
publicmapStoreToProps:StateToProps<StoreState>=map=>map
157+
privatemapStoreToProps:StateToProps<S>=map=>map
158158

159159
/**
160160
* Build an instance of store with configured values.
161161
*
162162
*@returns {Store<StoreType>}
163163
*@memberof StoreBuilder
164164
*/
165-
publicbuild():Store<S>{
165+
publicbuild():[Store<S>,StateToProps<S>]{
166166
constdefer=Promise.defer<Dispatch<Action>>()
167167
constreducerMap=Object.keys(this.reducerBuilders).reduce(
168168
(p:any,r)=>({
@@ -178,6 +178,6 @@ export class StoreBuilder<S extends StoreState> {
178178

179179
defer.resolve(store.dispatch)
180180

181-
returnstore
181+
return[store,this.mapStoreToProps]
182182
}
183183
}

‎tests/reducer.builder.spec.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('Reducer', () => {
2424
isBasicActionCalled:true,
2525
})
2626

27-
conststore=newStoreBuilder<StoreState>()
27+
const[store]=newStoreBuilder<StoreState>()
2828
.withReducerBuildersMap({ reducer})
2929
.build()
3030

@@ -41,7 +41,7 @@ describe('Reducer', () => {
4141
returnstate
4242
})
4343

44-
conststore=newStoreBuilder<StoreState>()
44+
const[store]=newStoreBuilder<StoreState>()
4545
.withReducerBuilder('reducer',reducer)
4646
.build()
4747

@@ -84,7 +84,7 @@ describe('Reducer', () => {
8484
returnnext(a)
8585
})
8686
.withReducerBuildersMap({ reducer})
87-
.build()
87+
.build()[0]
8888

8989
store.dispatch(SimpleAction())
9090
})

‎tests/store.builder.spec.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('Store', () => {
1313
constinitState={reducer:{test:true}}
1414

1515
describe('with initial state',()=>{
16-
conststore=newStoreBuilder()
16+
const[store]=newStoreBuilder()
1717
.withInitialState(initState)
1818
.withReducersMap({ reducer})
1919
.build()
@@ -29,7 +29,7 @@ describe('Store', () => {
2929
isSet=true
3030
returnnext(action)
3131
}
32-
conststore=newStoreBuilder()
32+
const[store]=newStoreBuilder()
3333
.withMiddleware(testMiddleware)
3434
.withReducersMap({ reducer})
3535
.build()
@@ -49,7 +49,7 @@ describe('Store', () => {
4949
}
5050
returnstate
5151
}
52-
conststore=newStoreBuilder().withReducer('test',testReducer).build()
52+
const[store]=newStoreBuilder().withReducer('test',testReducer).build()
5353

5454
store.dispatch(testAction)
5555

@@ -66,7 +66,7 @@ describe('Store', () => {
6666
}
6767
returnstate
6868
}
69-
conststore=newStoreBuilder().withReducersMap({ testReducer}).build()
69+
const[store]=newStoreBuilder().withReducersMap({ testReducer}).build()
7070

7171
store.dispatch(testAction)
7272

@@ -81,7 +81,7 @@ describe('Store', () => {
8181
isSet=true
8282
returnf
8383
}
84-
conststore=newStoreBuilder()
84+
const[store]=newStoreBuilder()
8585
.withReducersMap({ reducer})
8686
.withEnhancer(enhancer)
8787
.build()

‎tsconfig.json‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
{
2-
"compilerOptions": {
3-
"module":"commonjs",
4-
"target":"es5",
5-
"noImplicitAny":true,
6-
"experimentalDecorators":true,
7-
"lib": ["dom","es5","es2015.promise","es2015.core"]
8-
},
9-
"exclude": ["node_modules","tests"]
10-
}
1+
{
2+
"compilerOptions": {
3+
"module":"commonjs",
4+
"target":"es5",
5+
"noImplicitAny":true,
6+
"experimentalDecorators":true,
7+
"declaration":true,
8+
"outDir":"./lib",
9+
"lib": ["dom","es5","es2015.promise","es2015.core"]
10+
},
11+
"exclude": ["node_modules","tests"]
12+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp