File tree 9 files changed +1415
-1236
lines changed
9 files changed +1415
-1236
lines changed Original file line number Diff line number Diff line change 8
8
"build" : " webpack-genius build --env production"
9
9
},
10
10
"dependencies" : {
11
- "@redux-model/web " : " ^6.9.1 " ,
11
+ "@redux-model/react " : " ^7.0.0-beta.13 " ,
12
12
"lodash" : " ^4.17.15" ,
13
13
"react" : " ^16.12.0" ,
14
14
"react-dom" : " ^16.12.0" ,
24
24
"@types/redux-logger" : " ^3.0.7" ,
25
25
"redux-logger" : " ^3.0.6" ,
26
26
"typescript" : " ^3.7.4" ,
27
- "webpack-genius" : " ^4.13.2 "
27
+ "webpack-genius" : " ^4.13.7 "
28
28
}
29
29
}
Original file line number Diff line number Diff line change 1
1
.wrapper
2
2
flex-direction : row
3
3
display : flex
4
-
5
- : global
6
- #react-refresh-overlay
7
- display : none !important
8
-
Original file line number Diff line number Diff line change 1
1
import React , { FunctionComponent , useCallback } from 'react' ;
2
2
import { npmInfoModel } from '../models/NpmInfoModel' ;
3
3
import styles from './Request.less' ;
4
+ import { Model } from '@redux-model/react' ;
4
5
5
6
const Request : FunctionComponent = ( ) => {
6
7
const npmInfo = npmInfoModel . useData ( ) ;
7
- const loading = npmInfoModel . manage . useLoading ( ) ;
8
+
9
+ const loading = Model . useLoading (
10
+ npmInfoModel . manage . useLoading ( ) ,
11
+ npmInfoModel . combo . useLoading ( ) ,
12
+ ) ;
8
13
9
14
const handleClick = useCallback ( ( ) => {
10
15
npmInfoModel . manage ( 'react-native' )
@@ -18,7 +23,9 @@ const Request: FunctionComponent = () => {
18
23
} , [ ] ) ;
19
24
20
25
const handleClick2 = useCallback ( ( ) => {
21
- npmInfoModel . manage ( 'not-existed-package' ) ;
26
+ npmInfoModel . combo ( 'not-existed-package' ) . catch ( ( e ) => {
27
+ alert ( e . message ) ;
28
+ } ) ;
22
29
} , [ ] ) ;
23
30
24
31
const handleReset = useCallback ( ( ) => {
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import ReactDom from 'react-dom' ;
3
3
import { Provider } from 'react-redux' ;
4
- import { applyMiddleware , compose , Middleware } from 'redux' ;
4
+ import { Middleware } from 'redux' ;
5
5
import App from './components/App' ;
6
- import { createReduxStore , PersistGate } from '@redux-model/web ' ;
6
+ import { createReduxStore , PersistGate } from '@redux-model/react ' ;
7
7
import { createLogger } from 'redux-logger' ;
8
8
import { summaryModel } from './models/SummaryModel' ;
9
9
@@ -16,15 +16,12 @@ const rootMiddleWares: Middleware[] = [
16
16
] ;
17
17
18
18
const store = createReduxStore ( {
19
- reducers : {
20
- ...summaryModel . register ( ) ,
21
- } ,
22
- enhancer : compose ( applyMiddleware ( ...rootMiddleWares ) ) ,
19
+ middleware : rootMiddleWares ,
23
20
persist : {
24
- version : '0.0.1 ' ,
21
+ version : '0.0.2 ' ,
25
22
key : 'demo-react-hooks' ,
26
- storage : localStorage ,
27
- whitelist : {
23
+ storage : 'local' ,
24
+ allowlist : {
28
25
summaryModel,
29
26
} ,
30
27
} ,
Original file line number Diff line number Diff line change 1
- import { HttpResponse , HttpService } from '@redux-model/web ' ;
1
+ import { HttpService } from '@redux-model/react ' ;
2
2
3
- export const $api = new HttpService ( {
3
+ export const $api = new HttpService < { error : string , reason : string } > ( {
4
4
baseUrl : 'https://registry.npm.taobao.org' ,
5
5
headers : ( ) => {
6
6
return {
@@ -15,16 +15,16 @@ export const $api = new HttpService({
15
15
16
16
return true ;
17
17
} ,
18
- onRespondError : ( response : HttpResponse < { error : string , reason : string } > , transform ) => {
18
+ onRespondError : ( response , transform ) => {
19
19
if ( response . data && response . data . reason ) {
20
20
transform . message = response . data . reason ;
21
21
}
22
22
} ,
23
- onShowSuccess : ( successText : string ) => {
23
+ onShowSuccess : ( successText ) => {
24
24
console . info ( successText ) ;
25
25
alert ( successText ) ;
26
26
} ,
27
- onShowError : ( errorText : string ) => {
27
+ onShowError : ( errorText ) => {
28
28
console . error ( errorText ) ;
29
29
alert ( errorText ) ;
30
30
} ,
Original file line number Diff line number Diff line change 1
- import { Model } from '@redux-model/web ' ;
1
+ import { Model } from '@redux-model/react ' ;
2
2
3
3
type Data = {
4
4
amount : number ;
Original file line number Diff line number Diff line change 1
- import { Model } from '@redux-model/web ' ;
1
+ import { Model } from '@redux-model/react ' ;
2
2
import { $api } from '../libraries/httpService/$api' ;
3
+ import { counterModel } from './CounterModel' ;
3
4
4
5
interface Response {
5
6
_id : string ;
@@ -16,10 +17,13 @@ class NpmInfoModel extends Model<Data> {
16
17
. throttle ( 1000 )
17
18
. onSuccess ( ( _ , action ) => {
18
19
return action . response ;
20
+ } )
21
+ . afterSuccess ( ( ) => {
22
+ counterModel . increase ( ) ;
19
23
} ) ;
20
24
} ) ;
21
25
22
- async combo ( packageName : string ) {
26
+ combo = this . compose ( async ( packageName : string ) => {
23
27
const info = await $api . getAsync < Response > ( {
24
28
uri : '/' + packageName ,
25
29
query : {
@@ -30,7 +34,7 @@ class NpmInfoModel extends Model<Data> {
30
34
this . changeReducer ( ( state ) => {
31
35
state . homepage = info . response . homepage ;
32
36
} ) ;
33
- }
37
+ } ) ;
34
38
35
39
reset = this . action ( ( ) => {
36
40
return { } ;
Original file line number Diff line number Diff line change 1
- import { Effects , Model } from '@redux-model/web ' ;
1
+ import { Effects , Model } from '@redux-model/react ' ;
2
2
import { counterModel } from './CounterModel' ;
3
3
import { npmInfoModel } from './NpmInfoModel' ;
4
4
You can’t perform that action at this time.
0 commit comments