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

Commitcba2fc1

Browse files
author
okan.cetin
committed
#000 okan remove action name from decorator
1 parente39308d commitcba2fc1

File tree

6 files changed

+18
-32
lines changed

6 files changed

+18
-32
lines changed

‎src/app/actions/authActions.ts‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { push } from 'react-router-redux'
55
consttokenKey="auth";
66

77

8-
@Action("LOGIN_REQUEST")
8+
@Action
99
exportclassLoginRequestextendsAsyncAction{
1010
constructor(publicusername:string,publicpassword:string){
1111
super();
@@ -15,29 +15,25 @@ export class LoginRequest extends AsyncAction {
1515
.then(x=>x.json())
1616
.then(data=>{
1717
dispatch(newLogin(data.args.username+"|"+data.args.password));
18+
dispatch(push("dashboard"));
1819
});
1920
returnthis;
2021
});
2122
}
2223
}
2324

24-
@Action("LOGIN")
25-
exportclassLoginextendsAsyncAction{
25+
@Action
26+
exportclassLoginextendsSyncAction{
2627
constructor(publictoken:string){
2728
super();
28-
29-
this.then(dispatch=>{
30-
dispatch(push("dashboard"));
31-
returnthis;
32-
});
3329
}
3430

3531
getTokenKey(){
3632
returntokenKey;
3733
}
3834
}
3935

40-
@Action("LOGOUT")
36+
@Action
4137
exportclassLogoutextendsAsyncAction{
4238
constructor(){
4339
super();

‎src/app/actions/layoutActions.ts‎

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

33

4-
@Action("CHANGE_THEME")
4+
@Action
55
exportclassChangeThemeextendsSyncAction{}

‎src/app/reducers/authReducer.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ export interface AuthState {
1010
exportconstauthReducer=newReducerBuilder<AuthState>()
1111
.init({})
1212

13-
.action(Login,(state,action)=>{
13+
.handle(Login,(state,action)=>{
1414
consttoken=action.token;
1515

1616
localStorage.setItem(action.getTokenKey(),token);
17-
17+
1818
return{
1919
token:token
2020
};
2121
})
2222

23-
.action(Logout,(state,action)=>{
23+
.handle(Logout,(state,action)=>{
2424
localStorage.removeItem(action.getTokenKey());
25-
25+
2626
return{
2727
token:null
2828
};

‎src/app/reducers/layoutReducer.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ export const layoutReducer = new ReducerBuilder<LayoutState>()
1515
asyncCount:0
1616
})
1717

18-
.action(ChangeTheme,(state)=>{
18+
.handle(ChangeTheme,(state)=>{
1919
return{
2020
useDarkTheme:!state.useDarkTheme
2121
};
2222
})
2323

24-
.action(ShowLoading,(state)=>{
24+
.handle(ShowLoading,(state)=>{
2525
letcount=state.asyncCount;
2626
return{
2727
asyncCount:++count
2828
};
2929
})
3030

31-
.action(HideLoading,(state)=>{
31+
.handle(HideLoading,(state)=>{
3232
letcount=state.asyncCount;
3333
return{
3434
asyncCount:--count

‎src/app/utils/actionHelpers.ts‎

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,19 @@ export abstract class AsyncAction extends SyncAction implements Promise<Dispatch
3333
}
3434
}
3535

36-
exportfunctionAction(name:string){
37-
returnfunction<TextendsRedux.Action>(actionClass:IAction<T>){
38-
actionClass.prototype.type=name;
39-
}
36+
exportfunctionAction<TextendsSyncAction>(actionClass:IAction<T>){
37+
actionClass.prototype.type=actionClass.toString().match(/\w+/g)[1];;
4038
}
4139

4240

43-
@Action("SHOW_LOADING")
41+
@Action
4442
exportclassShowLoadingextendsSyncAction{}
4543

4644

47-
@Action("HIDE_LOADING")
45+
@Action
4846
exportclassHideLoadingextendsSyncAction{}
4947

5048

51-
// export function isType<T extends Action>(action: Action, actionClass: IAction<T>): action is T {
52-
// return action.type == actionClass.prototype.type;
53-
// }
54-
55-
// export function getType<T extends Action>(action: Action): action is T {
56-
// return action.type;
57-
// }
58-
5949
exportconsttypedToPlainMiddleware:Middleware=
6050
<S>(store:MiddlewareAPI<S>)=>(next:Dispatch<S>):Dispatch<S>=>(action:any)=>{
6151
if(typeofaction==="object"){

‎src/app/utils/reducerBuilder.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class ReducerBuilder<State> {
1515
returnthis;
1616
}
1717

18-
publicaction<TextendsSyncAction>(actionType:IAction<T>,actionBody:(state:State,action?:T)=>State){
18+
publichandle<TextendsSyncAction>(actionType:IAction<T>,actionBody:(state:State,action?:T)=>State){
1919
this.actions[actionType.prototype.type]=actionBody;
2020
returnthis;
2121
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp