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

Commit693b36f

Browse files
committed
refactor alert
1 parent9d02a1a commit693b36f

File tree

16 files changed

+39
-41
lines changed

16 files changed

+39
-41
lines changed

‎lib/actions/progress.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function completeTutorial(completed) {
4545
returnfunction(dispatch,getState){
4646
vartutorial=getState().tutorial;
4747
dispatch({type:_types_1.COMPLETE_TUTORIAL,payload:{tutorial:tutorial,completed:completed}});
48-
dispatch(alert_1.alertToggle({
48+
dispatch('ALER'({
4949
message:'Tutorial Complete',
5050
action:'PASS',
5151
}));

‎lib/actions/tutorial.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
var_types_1=require('./_types');
33
varprogress_1=require('./progress');
44
varroute_1=require('./route');
5+
varalert_1=require('./alert');
56
functiontutorialSet(name){
67
returnfunction(dispatch,getState){
78
vardir=getState().dir;
@@ -16,10 +17,10 @@ function tutorialUpdate(name) {
1617
varalert={
1718
message:"run `npm install --save-dev "+name+"`",
1819
action:'note',
19-
duration:4000,
20+
duration:3000,
2021
};
2122
dispatch({type:_types_1.TUTORIAL_UPDATE,payload:{name:name}});
22-
dispatch({type:_types_1.ALERT_TOGGLE,payload:{alert:alert}});
23+
dispatch(alert_1.alertToggle(alert));
2324
};
2425
}
2526
exports.tutorialUpdate=tutorialUpdate;

‎lib/components/Alert/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
1515
};
1616
varReact=require('react');
1717
varreact_redux_1=require('react-redux');
18-
varactions_1=require('../../actions');
1918
varSnackbar_1=require('material-ui/Snackbar');
19+
varactions_1=require('../../actions');
2020
vardefaultAlert={
2121
message:'',
2222
open:false,
@@ -28,13 +28,13 @@ var Alert = (function (_super) {
2828
}
2929
Alert.prototype.render=function(){
3030
var_a=this.props,alert=_a.alert,alertToggle=_a.alertToggle;
31-
varaction=alert.action,open=alert.open,message=alert.message,duration=alert.duration;
32-
return(React.createElement(Snackbar_1.default,{className:"cr-alert "+action,open:open||false,message:message||'',action:action,autoHideDuration:duration||2000,onActionTouchTap:alertToggle,onRequestClose:alertToggle}));
31+
varaction=alert.action,message=alert.message,open=alert.open,duration=alert.duration;
32+
return(React.createElement(Snackbar_1.default,{className:"cr-alert "+action,open:open,message:message||'',action:action||'NOTE',autoHideDuration:duration||2000,onRequestClose:alertToggle}));
3333
};
3434
Alert=__decorate([
3535
react_redux_1.connect(null,function(dispatch){
3636
return{
37-
alertToggle:function(){returndispatch(actions_1.alertToggle());},
37+
alertToggle:function(){returndispatch(actions_1.alertToggle({open:false}));}
3838
};
3939
}),
4040
__metadata('design:paramtypes',[])

‎lib/reducers/alert/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ function alertReducer(alert, action) {
2929
case_types_1.ALERT_REPLAY:
3030
returnsetAlert(current);
3131
case_types_1.ALERT_TOGGLE:
32-
vara=action.payload.alert;
33-
if(!a){
34-
return_alert;
35-
}
36-
returnsetAlert(a);
32+
returnsetAlert(action.payload.alert);
3733
default:
3834
returnalert;
3935
}

‎lib/store/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ var redux_1 = require('redux');
33
varredux_action_thunk_1=require('redux-action-thunk');
44
varreducers_1=require('../reducers');
55
varcreateLogger=require('redux-logger');
6-
varredux_thunk_1=require('redux-thunk');
7-
varmiddlewares=[redux_action_thunk_1.ratMiddleware,redux_thunk_1.default];
8-
vardevMode=false;
6+
varmiddlewares=[redux_action_thunk_1.ratMiddleware];
7+
vardevMode=true;
98
if(devMode){
109
varlogger=createLogger();
1110
middlewares.push(logger);

‎package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
"react-redux":"4.4.5",
4747
"react-tap-event-plugin":"1.0.0",
4848
"redux":"3.5.2",
49-
"redux-action-thunk":"0.1.0",
49+
"redux-action-thunk":"0.3.0",
5050
"redux-logger":"2.6.1",
51-
"redux-thunk":"^2.1.0"
51+
"redux-thunk":"2.1.0"
5252
},
5353
"scripts": {
5454
"compile":"tsc"

‎src/actions/alert.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@ export function alertToggle(alert: Object): ReduxThunk.ThunkInterface {
99
exportfunctionalertReplay():Action{
1010
return{type:ALERT_REPLAY};
1111
}
12+
13+
// import {rat} from 'redux-action-thunk';
14+
//
15+
// rat.add('ALERT_TOGGLE', (dispatch, getState) => (alert) => {
16+
// dispatch({ type: 'ALERT_TOGGLE', payload: { alert }});
17+
// });
18+
//
19+
// rat.add('ALERT_REPLAY');

‎src/actions/hint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import{HINT_SHOW,HINT_POSITION_SET}from'./_types';
1+
import{HINT_POSITION_SET}from'./_types';
22

33
exportfunctionhintPositionSet(hintPosition:number):Action{
44
return{type:HINT_POSITION_SET,payload:{ hintPosition}};

‎src/actions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export{alertToggle,alertReplay}from'./alert';
2+
// import './alert';
23
export{
34
progressLoad,completePage,completeTutorial,
45
progressPagePositionLoad

‎src/actions/progress.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function completeTutorial(completed = true): ReduxThunk.ThunkInterface {
4545
return(dispatch,getState):void=>{
4646
const{tutorial}=getState();
4747
dispatch({type:COMPLETE_TUTORIAL,payload:{ tutorial, completed}});
48-
dispatch(alertToggle({
48+
dispatch('ALER'({
4949
message:'Tutorial Complete',
5050
action:'PASS',
5151
}));

‎src/actions/tutorial.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import{
2-
TUTORIALS_FIND,TUTORIAL_UPDATE,TUTORIAL_SET,
3-
ALERT_TOGGLE
2+
TUTORIALS_FIND,TUTORIAL_UPDATE,TUTORIAL_SET
43
}from'./_types';
54
import{progressLoad}from'./progress';
65
import{routeSet}from'./route';
6+
import{alertToggle}from'./alert';
77

88
exportfunctiontutorialSet(name:string):ReduxThunk.ThunkInterface{
99
return(dispatch,getState):void=>{
@@ -19,10 +19,10 @@ export function tutorialUpdate(name: string): ReduxThunk.ThunkInterface {
1919
constalert={
2020
message:`run \`npm install --save-dev${name}\``,
2121
action:'note',
22-
duration:4000,
22+
duration:3000,
2323
};
2424
dispatch({type:TUTORIAL_UPDATE,payload:{ name}});
25-
dispatch({type:ALERT_TOGGLE,payload:{alert}});
25+
dispatch(alertToggle(alert));
2626
};
2727
}
2828

‎src/components/Alert/index.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
import*asReactfrom'react';
22
import{connect}from'react-redux';
3-
import{alertToggle}from'../../actions';
43
importSnackbarfrom'material-ui/Snackbar';
4+
import{alertToggle}from'../../actions';
55

66
constdefaultAlert={
77
message:'',
88
open:false,
99
};
1010

11-
@connect(null,(dispatch)=>{
11+
@connect(null,dispatch=>{
1212
return{
13-
alertToggle:()=>dispatch(alertToggle()),
13+
alertToggle:()=>dispatch(alertToggle({open:false}))
1414
};
1515
})
1616
exportdefaultclassAlertextendsReact.Component<{
1717
alert:CR.Alert,alertToggle?:any
1818
},{}>{
1919
render(){
2020
const{alert, alertToggle}=this.props;
21-
const{action,open, message, duration}=alert;
21+
const{action,message, open, duration}=alert;
2222
return(
2323
<Snackbar
2424
className={`cr-alert${action}`}
25-
open={open||false}
25+
open={open}
2626
message={message||''}
27-
action={action}
27+
action={action||'NOTE'}
2828
autoHideDuration={duration||2000}
29-
onActionTouchTap={alertToggle}
3029
onRequestClose={alertToggle}
3130
/>
3231
);

‎src/components/Common/RouteButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {connect} from 'react-redux';
33
import{routeSet}from'../../actions';
44
importRaisedButtonfrom'material-ui/RaisedButton';
55

6-
@connect(null,(dispatch)=>{
6+
@connect(null,dispatch=>{
77
return{
88
routeTo:(route:string)=>dispatch(routeSet(route)),
99
};

‎src/reducers/alert/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,7 @@ export default function alertReducer(
4141
returnsetAlert(current);
4242

4343
caseALERT_TOGGLE:
44-
consta=action.payload.alert;
45-
46-
if(!a){
47-
// close alert
48-
return_alert;
49-
}
50-
returnsetAlert(a);
44+
returnsetAlert(action.payload.alert);
5145

5246
default:
5347
returnalert;

‎src/reducers/tutorial-list/update.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
importcommandLinefrom'../../services/command-line';
2-
import{alertToggle}from'../../actions';
2+
//import {alertToggle} from '../../actions';
33
import{tutorialsFind}from'../../actions';
44

55
exportfunctiontutorialUpdate(name:string):void{

‎src/store/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import * as createLogger from 'redux-logger';
55
importthunkfrom'redux-thunk';
66

77
// const middlewares = [ramMiddleware];
8-
constmiddlewares=[ratMiddleware,thunk];
8+
constmiddlewares=[ratMiddleware];
99

10-
constdevMode=false;
10+
constdevMode=true;
1111
if(devMode){
1212
constlogger=createLogger();
1313
middlewares.push(logger);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp