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

Commit421a37b

Browse files
committed
#000 okan apply solution to check action type
1 parent71e6e72 commit421a37b

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

‎src/app/actions/layoutActions.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import{Action,BaseAction}from'../utils/actionHelpers'
22

3+
34
@Action("CHANGE_THEME")
45
exportclassChangeThemeextendsBaseAction{}

‎src/app/reducers/layoutReducer.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// import { fromJS } from 'immutable';
2-
import{Action,Reducer}from'redux'
3-
import{BaseAction}from'../utils/actionHelpers'
2+
import{Reducer}from'redux'
3+
import{BaseAction,isType}from'../utils/actionHelpers'
44
import{ChangeTheme}from'../actions'
55

66
// const INITIAL_STATE = fromJS({
77
// useDarkTheme: false,
88
// });
99

1010
constINITIAL_STATE:LayoutState={
11-
useDarkTheme:false,
11+
useDarkTheme:false
1212
};
1313

1414

@@ -18,11 +18,11 @@ export interface LayoutState {
1818

1919
exportconstlayoutReducer:Reducer<LayoutState>=(state=INITIAL_STATE,action:BaseAction)=>{
2020

21-
if(actioninstanceofChangeTheme){
21+
if(isType(action,ChangeTheme)){
2222
return{
2323
useDarkTheme:!state.useDarkTheme
2424
};
2525
}
2626

2727
returnstate;
28-
}
28+
}

‎src/app/utils/actionHelpers.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ export abstract class BaseAction implements Action {
1212
constructor(){
1313
this.type=this.type;
1414
}
15-
16-
// is<T extends Action>(actionClass: IAction<T>): this is T {
17-
// return this.type == actionClass.prototype.type;
18-
// }
1915
}
2016

2117
exportfunctionAction(name:string){
@@ -24,6 +20,10 @@ export function Action(name: string) {
2420
}
2521
}
2622

23+
exportfunctionisType<TextendsAction>(action:Action,actionClass:IAction<T>):action isT{
24+
returnaction.type==actionClass.prototype.type;
25+
}
26+
2727
exportconsttypedToPlainMiddleware:Middleware=(store:any)=>(next:any)=>(action:any)=>{
2828
next(_.merge({},action));
2929
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp