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

Commitc9c7744

Browse files
committed
Update dependencies
- expose 'mapStoreToProps' function from store- add 'mapDispatchToProps' functiion
1 parentaa74736 commitc9c7744

File tree

12 files changed

+2135
-3047
lines changed

12 files changed

+2135
-3047
lines changed

‎README.md‎

Lines changed: 289 additions & 171 deletions
Large diffs are not rendered by default.

‎package.json‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,28 @@
5050
"redux":"^4.0.1"
5151
},
5252
"devDependencies": {
53-
"@types/chai":"^4.1.7",
54-
"@types/mocha":"^5.2.5",
55-
"@types/react":"^16.7.18",
56-
"@types/react-redux":"^6.0.11",
53+
"@types/chai":"^4.2.4",
54+
"@types/mocha":"^5.2.7",
55+
"@types/react":"^16.9.11",
56+
"@types/react-redux":"^7.1.5",
5757
"chai":"^4.2.0",
58-
"mocha":"^5.2.0",
59-
"prettier-tslint":"^0.4.1",
60-
"rimraf":"^2.6.2",
61-
"source-map-support":"^0.5.9",
62-
"ts-loader":"^5.3.2",
63-
"ts-node":"^7.0.1",
64-
"tslint-config-airbnb":"^5.11.1",
65-
"typescript":"^3.2.2",
66-
"webpack":"^4.28.2",
67-
"webpack-cli":"^3.1.2",
68-
"webpack-merge":"^4.1.5",
58+
"mocha":"^6.2.2",
59+
"prettier-tslint":"^0.4.2",
60+
"rimraf":"^3.0.0",
61+
"source-map-support":"^0.5.16",
62+
"ts-loader":"^6.2.1",
63+
"ts-node":"^8.5.0",
64+
"tslint-config-airbnb":"^5.11.2",
65+
"typescript":"^3.7.2",
66+
"webpack":"^4.41.2",
67+
"webpack-cli":"^3.3.10",
68+
"webpack-merge":"^4.2.2",
6969
"webpack-node-externals":"^1.7.2"
7070
},
7171
"peerDependencies": {
72-
"react":">=15",
73-
"react-dom":">=15",
74-
"react-redux":">=5",
72+
"react":">=16",
73+
"react-dom":">=16",
74+
"react-redux":">=7",
7575
"redux":">=4"
7676
},
7777
"prettier": {

‎src/helpers/redux.helpers.ts‎

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
1-
import{ActionCreatorDefinition,DispatchToProps,Indexer}from'..'
2-
3-
exportconstcreateAction=<TPayload=any,TMeta=any>(
4-
type:string,
5-
):ActionCreatorDefinition<TPayload,TMeta>=>{
6-
constcreator:any=(payload?:TPayload,meta?:TMeta)=>({
7-
payload,
8-
meta,
9-
type,
10-
})
11-
creator.type=type
12-
returncreator
13-
}
14-
15-
exportconstmapDispatchToProps:DispatchToProps=map=>(dispatch,own)=>{
16-
constmapper=<TextendsIndexer>(m:T)=>
17-
Object.keys(m).reduce(
18-
(prev,key)=>({
19-
...prev,
20-
[key]:(...params:any[])=>dispatch(m[key](...params)),
21-
}),
22-
{},
23-
)astypeofm
24-
25-
returntypeofmap==='function' ?mapper(map(dispatch,own)) :mapper(map)
26-
}
1+
import{ActionCreatorDefinition,DispatchToProps,Indexer}from'..'
2+
3+
exportconstcreateAction=<TPayload=any,TMeta=any>(
4+
type:string,
5+
):ActionCreatorDefinition<TPayload,TMeta>=>{
6+
constcreator:any=(payload?:TPayload,meta?:TMeta)=>({
7+
payload,
8+
meta,
9+
type,
10+
})
11+
creator.type=type
12+
returncreator
13+
}
14+
15+
16+
/**
17+
* Dummy function to return `MapDispatchToPropsParam` type that can be passed to `connect`
18+
* As paramter, either mapper function which takes dispatch object and returns indexer object or indexer object is required
19+
* ex.
20+
* const changeLayout = createAction('changeLayout')
21+
* const dispatchedProps = mapDispatchToProps((dispatch, own) => ({ changeLayout: () => dispatch(changeLayout()) }))
22+
* // or
23+
* const dispatchedProps = mapDispatchToProps({ changeLayout }))
24+
*
25+
*@param {*} map
26+
*/
27+
exportconstmapDispatchToProps:DispatchToProps=map=>(dispatch,own)=>{
28+
constmapper=<TextendsIndexer>(m:T)=>
29+
Object.keys(m).reduce(
30+
(prev,key)=>({
31+
...prev,
32+
[key]:(...params:any[])=>dispatch(m[key](...params)),
33+
}),
34+
{},
35+
)astypeofm
36+
37+
returntypeofmap==='function' ?mapper(map(dispatch,own)) :mapper(map)
38+
}

‎src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import'./polyfills/promise.polyfill'
2+
23
export*from'./models/action.model'
34
export*from'./models/redux.model'
45
export*from'./reducer.builder'

‎src/models/action.model.ts‎

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
import{ActionasReduxAction}from'redux'
2-
3-
exportinterfaceAction<TPayload=any,TMeta=any>
4-
extendsReduxAction<string>{
5-
payload:TPayload
6-
meta:TMeta
7-
}
8-
9-
exportinterfaceActionCreatorDefinition<TPayload,TMeta>{
10-
(payload?:TPayload,meta?:TMeta):Action<TPayload,TMeta>
11-
type:string
12-
}
13-
14-
exporttypeLazyDispatch=<TActionextendsReduxAction>(
15-
action:TAction,
16-
)=>Promise<TAction>
17-
18-
exporttypeActionBody<TState,TPayload>=(
19-
state:TState,
20-
action:TPayload,
21-
dispatch:LazyDispatch,
22-
)=>TState
1+
import{ActionasReduxAction}from'redux'
2+
3+
exportinterfaceAction<TPayload=any,TMeta=any>extendsReduxAction<string>{
4+
payload:TPayload
5+
meta:TMeta
6+
}
7+
8+
exportinterfaceActionCreatorDefinition<TPayload,TMeta>{
9+
(payload?:TPayload,meta?:TMeta):Action<TPayload,TMeta>
10+
type:string
11+
}
12+
13+
exporttypeLazyDispatch=<TActionextendsReduxAction>(action:TAction)=>Promise<TAction>
14+
15+
exporttypeActionBody<TState,TPayload>=(
16+
state:TState,
17+
action:TPayload,
18+
dispatch:LazyDispatch,
19+
)=>TState

‎src/models/redux.model.ts‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import{AnyAction}from'redux'
2-
import{MapDispatchToPropsFunction,MapStateToProps}from'react-redux'
3-
4-
exporttypeIndexer<T=any>={[key:string]:T}
5-
6-
exportinterfaceStateToProps<TState=any>{
7-
<TextendsIndexer,TOwn>(
8-
map:MapStateToProps<T,TOwn,TState>,
9-
):MapStateToProps<T,TOwn,TState>
10-
}
11-
12-
exportinterfaceDispatchToProps{
13-
<TextendsIndexer<(...params:any[])=>AnyAction>,TOwn>(
14-
map:T|MapDispatchToPropsFunction<T,TOwn>,
15-
):MapDispatchToPropsFunction<T,TOwn>
16-
}
1+
import{MapDispatchToPropsFunction,MapStateToProps}from'react-redux'
2+
import{AnyAction}from'redux'
3+
4+
exporttypeIndexer<T=any>={[key:string]:T}
5+
6+
exporttypeStateToProps<TState=any>={
7+
<TextendsIndexer,TOwn>(
8+
map:MapStateToProps<T,TOwn,TState>,
9+
):MapStateToProps<T,TOwn,TState>
10+
}
11+
12+
exporttypeDispatchToProps={
13+
<TextendsIndexer<(...params:any[])=>AnyAction>,TOwn>(
14+
map:T|MapDispatchToPropsFunction<T,TOwn>,
15+
):MapDispatchToPropsFunction<T,TOwn>
16+
}

‎src/polyfills/promise.polyfill.ts‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
interfacePromiseConstructor{
2-
defer<T>():{
3-
resolve:(value?:T|PromiseLike<T>)=>void
4-
reject:(reason?:any)=>void
5-
promise:Promise<T>,
6-
}
7-
}
8-
9-
Promise['defer']=functiondeferPolyfill(){
10-
constdeferred={}asany
11-
constpromise=newPromise((resolve,reject)=>{
12-
deferred.resolve=resolve
13-
deferred.reject=reject
14-
})
15-
deferred.promise=promise
16-
returndeferred
17-
}
1+
interfacePromiseConstructor{
2+
defer<T>():{
3+
resolve:(value?:T|PromiseLike<T>)=>void
4+
reject:(reason?:any)=>void
5+
promise:Promise<T>,
6+
}
7+
}
8+
9+
Promise['defer']=functiondeferPolyfill(){
10+
constdeferred={}asany
11+
constpromise=newPromise((resolve,reject)=>{
12+
deferred.resolve=resolve
13+
deferred.reject=reject
14+
})
15+
deferred.promise=promise
16+
returndeferred
17+
}

‎src/reducer.builder.ts‎

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,51 @@
1-
import{ActionBody,Action,ActionCreatorDefinition,LazyDispatch}from'.'
2-
import{Dispatch,Reducer}from'redux'
3-
4-
exportclassReducerBuilder<State={}>{
5-
privateactions:{[type:string]:ActionBody<State,Action>}={}
6-
privateinitState:State
7-
8-
/**
9-
* Initial state of the reducer
10-
*
11-
*@param {State} state State object
12-
*@returns
13-
*@memberof ReducerBuilder
14-
*/
15-
publicinit(state:State){
16-
this.initState=state
17-
returnthis
18-
}
19-
20-
/**
21-
* Consumer definition for given action type
22-
*
23-
*@template TPayload Action payload type
24-
*@param {ActionCreatorDefinition<TPayload>} creator Action creator function
25-
*@param {ActionBody<State, Action<TPayload>>} body Action body
26-
*@returns
27-
*@memberof ReducerBuilder
28-
*/
29-
publichandle<TPayload,TMeta>(
30-
creator:ActionCreatorDefinition<TPayload,TMeta>,
31-
body:ActionBody<State,Action<TPayload,TMeta>>,
32-
){
33-
this.actions[creator.type]=body
34-
returnthis
35-
}
36-
37-
privatebuild(dispatchPromise:Promise<Dispatch>):Reducer<State,Action>{
38-
return(state=this.initState,action)=>{
39-
constactionBody=this.actions[action.type]
40-
constlazyDispatch:LazyDispatch=nestedAction=>
41-
dispatchPromise.then(dispatch=>dispatch(nestedAction))
42-
43-
if(!!actionBody){
44-
returnactionBody(state,action,lazyDispatch)
45-
}
46-
47-
returnstate
48-
}
49-
}
50-
}
1+
import{Dispatch,Reducer}from'redux'
2+
3+
import{Action,ActionBody,ActionCreatorDefinition,LazyDispatch}from'.'
4+
5+
exportclassReducerBuilder<State={}>{
6+
privateactions:{[type:string]:ActionBody<State,Action>}={}
7+
privateinitState:State
8+
9+
/**
10+
* Initial state of the reducer
11+
*
12+
*@param {State} state State object
13+
*@returns
14+
*@memberof ReducerBuilder
15+
*/
16+
publicinit(state:State){
17+
this.initState=state
18+
returnthis
19+
}
20+
21+
/**
22+
* Consumer definition for given action type
23+
*
24+
*@template TPayload Action payload type
25+
*@param {ActionCreatorDefinition<TPayload>} creator Action creator function
26+
*@param {ActionBody<State, Action<TPayload>>} body Action body
27+
*@returns
28+
*@memberof ReducerBuilder
29+
*/
30+
publichandle<TPayload,TMeta>(
31+
creator:ActionCreatorDefinition<TPayload,TMeta>,
32+
body:ActionBody<State,Action<TPayload,TMeta>>,
33+
){
34+
this.actions[creator.type]=body
35+
returnthis
36+
}
37+
38+
privatebuild(dispatchPromise:Promise<Dispatch>):Reducer<State,Action>{
39+
return(state=this.initState,action)=>{
40+
constactionBody=this.actions[action.type]
41+
constlazyDispatch:LazyDispatch=nestedAction=>
42+
dispatchPromise.then(dispatch=>dispatch(nestedAction))
43+
44+
if(!!actionBody){
45+
returnactionBody(state,action,lazyDispatch)
46+
}
47+
48+
returnstate
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp