File tree Expand file tree Collapse file tree 9 files changed +1415
-1236
lines changed Expand file tree Collapse file tree 9 files changed +1415
-1236
lines changed Original file line number Diff line number Diff line change 88 "build" : " webpack-genius build --env production"
99 },
1010 "dependencies" : {
11- "@redux-model/web " : " ^6.9.1 " ,
11+ "@redux-model/react " : " ^7.0.0-beta.13 " ,
1212 "lodash" : " ^4.17.15" ,
1313 "react" : " ^16.12.0" ,
1414 "react-dom" : " ^16.12.0" ,
2424 "@types/redux-logger" : " ^3.0.7" ,
2525 "redux-logger" : " ^3.0.6" ,
2626 "typescript" : " ^3.7.4" ,
27- "webpack-genius" : " ^4.13.2 "
27+ "webpack-genius" : " ^4.13.7 "
2828 }
2929}
Original file line number Diff line number Diff line change 11.wrapper
22 flex-direction : row
33 display : flex
4-
5- : global
6- #react-refresh-overlay
7- display : none !important
8-
Original file line number Diff line number Diff line change 11import React , { FunctionComponent , useCallback } from 'react' ;
22import { npmInfoModel } from '../models/NpmInfoModel' ;
33import styles from './Request.less' ;
4+ import { Model } from '@redux-model/react' ;
45
56const Request : FunctionComponent = ( ) => {
67 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+ ) ;
813
914 const handleClick = useCallback ( ( ) => {
1015 npmInfoModel . manage ( 'react-native' )
@@ -18,7 +23,9 @@ const Request: FunctionComponent = () => {
1823 } , [ ] ) ;
1924
2025 const handleClick2 = useCallback ( ( ) => {
21- npmInfoModel . manage ( 'not-existed-package' ) ;
26+ npmInfoModel . combo ( 'not-existed-package' ) . catch ( ( e ) => {
27+ alert ( e . message ) ;
28+ } ) ;
2229 } , [ ] ) ;
2330
2431 const handleReset = useCallback ( ( ) => {
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import ReactDom from 'react-dom' ;
33import { Provider } from 'react-redux' ;
4- import { applyMiddleware , compose , Middleware } from 'redux' ;
4+ import { Middleware } from 'redux' ;
55import App from './components/App' ;
6- import { createReduxStore , PersistGate } from '@redux-model/web ' ;
6+ import { createReduxStore , PersistGate } from '@redux-model/react ' ;
77import { createLogger } from 'redux-logger' ;
88import { summaryModel } from './models/SummaryModel' ;
99
@@ -16,15 +16,12 @@ const rootMiddleWares: Middleware[] = [
1616] ;
1717
1818const store = createReduxStore ( {
19- reducers : {
20- ...summaryModel . register ( ) ,
21- } ,
22- enhancer : compose ( applyMiddleware ( ...rootMiddleWares ) ) ,
19+ middleware : rootMiddleWares ,
2320 persist : {
24- version : '0.0.1 ' ,
21+ version : '0.0.2 ' ,
2522 key : 'demo-react-hooks' ,
26- storage : localStorage ,
27- whitelist : {
23+ storage : 'local' ,
24+ allowlist : {
2825 summaryModel,
2926 } ,
3027 } ,
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 ' ;
22
3- export const $api = new HttpService ( {
3+ export const $api = new HttpService < { error : string , reason : string } > ( {
44 baseUrl : 'https://registry.npm.taobao.org' ,
55 headers : ( ) => {
66 return {
@@ -15,16 +15,16 @@ export const $api = new HttpService({
1515
1616 return true ;
1717 } ,
18- onRespondError : ( response : HttpResponse < { error : string , reason : string } > , transform ) => {
18+ onRespondError : ( response , transform ) => {
1919 if ( response . data && response . data . reason ) {
2020 transform . message = response . data . reason ;
2121 }
2222 } ,
23- onShowSuccess : ( successText : string ) => {
23+ onShowSuccess : ( successText ) => {
2424 console . info ( successText ) ;
2525 alert ( successText ) ;
2626 } ,
27- onShowError : ( errorText : string ) => {
27+ onShowError : ( errorText ) => {
2828 console . error ( errorText ) ;
2929 alert ( errorText ) ;
3030 } ,
Original file line number Diff line number Diff line change 1- import { Model } from '@redux-model/web ' ;
1+ import { Model } from '@redux-model/react ' ;
22
33type Data = {
44 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 ' ;
22import { $api } from '../libraries/httpService/$api' ;
3+ import { counterModel } from './CounterModel' ;
34
45interface Response {
56 _id : string ;
@@ -16,10 +17,13 @@ class NpmInfoModel extends Model<Data> {
1617 . throttle ( 1000 )
1718 . onSuccess ( ( _ , action ) => {
1819 return action . response ;
20+ } )
21+ . afterSuccess ( ( ) => {
22+ counterModel . increase ( ) ;
1923 } ) ;
2024 } ) ;
2125
22- async combo ( packageName : string ) {
26+ combo = this . compose ( async ( packageName : string ) => {
2327 const info = await $api . getAsync < Response > ( {
2428 uri : '/' + packageName ,
2529 query : {
@@ -30,7 +34,7 @@ class NpmInfoModel extends Model<Data> {
3034 this . changeReducer ( ( state ) => {
3135 state . homepage = info . response . homepage ;
3236 } ) ;
33- }
37+ } ) ;
3438
3539 reset = this . action ( ( ) => {
3640 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 ' ;
22import { counterModel } from './CounterModel' ;
33import { npmInfoModel } from './NpmInfoModel' ;
44
You can’t perform that action at this time.
0 commit comments