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

Commit3545577

Browse files
committed
reducer refactoring. move logic to dispatchers
1 parent7217aca commit3545577

File tree

14 files changed

+112
-96
lines changed

14 files changed

+112
-96
lines changed

‎lib/actions/alert.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
"use strict";
22
var_types_1=require('./_types');
3-
functionalertToggle(alert){
3+
functionalertToggle(alert,filter){
44
returnfunction(dispatch,getState){
5-
varisOpen=getState().alert.open;
6-
if(!alert){
7-
alert={
8-
action:'',
9-
message:'',
10-
open:false,
11-
};
12-
}
13-
else{
14-
alert=Object.assign({},{open:!isOpen},alert);
15-
}
165
dispatch({type:_types_1.ALERT_TOGGLE,payload:{alert:alert}});
176
};
187
}

‎lib/actions/page.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22
var_types_1=require('./_types');
33
varconfig_task_tests_1=require('./config-task-tests');
4+
varhint_1=require('./hint');
45
functionpageNext(){
56
returnfunction(dispatch,getState){
67
var_a=getState(),pagePosition=_a.pagePosition,tutorial=_a.tutorial;
@@ -26,6 +27,7 @@ function pageSet(pagePosition) {
2627
dispatch({
2728
type:_types_1.PAGE_SET,payload:{dir:dir,pagePosition:pagePosition,tutorial:tutorial,progress:progress,tasks:tasks}
2829
});
30+
dispatch(hint_1.hintPositionSet(0));
2931
};
3032
}
3133
exports.pageSet=pageSet;

‎lib/actions/progress.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
var_types_1=require('./_types');
3+
varalert_1=require('./alert');
34
functionprogressPagePositionLoad(){
45
returnfunction(dispatch,getState){
56
varprogress=getState().progress;
@@ -18,17 +19,27 @@ exports.progressLoad = progressLoad;
1819
functioncompletePage(){
1920
returnfunction(dispatch,getState){
2021
var_a=getState(),pagePosition=_a.pagePosition,progress=_a.progress,tutorial=_a.tutorial;
22+
dispatch({type:_types_1.COMPLETE_PAGE,payload:{pagePosition:pagePosition,tutorial:tutorial}});
2123
if(progress.pages.every(function(x){returnx.completed;})){
2224
dispatch(completeTutorial());
2325
}
24-
dispatch({type:_types_1.COMPLETE_PAGE,payload:{pagePosition:pagePosition,tutorial:tutorial}});
26+
else{
27+
dispatch(alert_1.alertToggle({
28+
message:"Page "+(pagePosition+1)+" Complete",
29+
action:'pass',
30+
}));
31+
}
2532
};
2633
}
2734
exports.completePage=completePage;
2835
functioncompleteTutorial(){
2936
returnfunction(dispatch,getState){
3037
vartutorial=getState().tutorial;
3138
dispatch({type:_types_1.COMPLETE_TUTORIAL,payload:{tutorial:tutorial}});
39+
dispatch(alert_1.alertToggle({
40+
message:'Tutorial Complete',
41+
action:'pass',
42+
}));
3243
};
3344
}
3445
exports.completeTutorial=completeTutorial;

‎lib/actions/test.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
var_types_1=require('./_types');
3+
varhint_1=require('./hint');
34
functiontestRun(){
45
returnfunction(dispatch,getState){
56
var_a=getState(),taskTests=_a.taskTests,dir=_a.dir,tutorial=_a.tutorial,taskPosition=_a.taskPosition;
@@ -12,10 +13,24 @@ exports.testRun = testRun;
1213
functiontestResult(result){
1314
returnfunction(dispatch,getState){
1415
vartaskActions=getState().taskActions;
15-
dispatch({type:_types_1.TEST_RESULT,payload:{result:result,taskActions:taskActions}});
16+
varfilter=getTestFilter(result);
17+
if(result.change!==0){
18+
dispatch(hint_1.hintPositionSet(0));
19+
}
20+
dispatch({type:_types_1.TEST_RESULT,payload:{result:result,taskActions:taskActions},filter:filter});
1621
};
1722
}
1823
exports.testResult=testResult;
24+
functiongetTestFilter(result){
25+
switch(true){
26+
caseresult.pass&&result.change>0:
27+
return'PASS';
28+
caseresult.pass===false&&result.change<1:
29+
return'FAIL';
30+
default:
31+
return'NOTE';
32+
}
33+
}
1934
functiontestComplete(){
2035
return{type:_types_1.TEST_COMPLETE};
2136
}

‎lib/actions/tutorial.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ function tutorialSet(name) {
88
}
99
exports.tutorialSet=tutorialSet;
1010
functiontutorialUpdate(name){
11-
return{type:_types_1.TUTORIAL_UPDATE,payload:{name:name}};
11+
returnfunction(dispatch,getState){
12+
varalert={
13+
message:"run `npm install --save-dev "+name+"`",
14+
action:'note',
15+
duration:4000,
16+
};
17+
dispatch({type:_types_1.TUTORIAL_UPDATE,payload:{name:name}});
18+
dispatch({type:_types_1.ALERT_TOGGLE,payload:{alert:alert}});
19+
};
1220
}
1321
exports.tutorialUpdate=tutorialUpdate;
1422
functiontutorialsFind(){

‎lib/reducers/alert/index.js

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ var _types_1 = require('../../actions/_types');
33
var_alert={
44
message:'',
55
open:false,
6-
action:'',
6+
action:'note',
7+
duration:1500,
78
};
89
varopen={
910
open:true,
10-
action:'pass',
11+
action:'note',
12+
duration:1500
1113
};
1214
varcurrent=_alert;
1315
functionsetAlert(options,color){
@@ -24,43 +26,32 @@ function alertReducer(alert, action) {
2426
case_types_1.ALERT_REPLAY:
2527
returnsetAlert(current);
2628
case_types_1.ALERT_TOGGLE:
27-
returnaction.payload.alert||_alert;
29+
returnsetAlert(action.payload.alert||_alert);
2830
case_types_1.TUTORIAL_UPDATE:
2931
returnsetAlert({
3032
message:"run `npm install --save-dev "+action.payload.name+"`",
31-
action:'note',
3233
duration:4000,
3334
});
3435
case_types_1.TEST_RESULT:
3536
varresult=action.payload.result;
36-
switch(true){
37-
caseresult.pass&&result.change>0:
37+
switch(action.payload.filter){
38+
case'PASS':
3839
returnsetAlert({
3940
message:result.msg,
40-
duration:result.duration||1500,
41+
action:'pass',
42+
duration:result.duration||1200,
4143
},'#73C990');
42-
caseresult.pass===false&&result.change<1:
44+
case'FAIL':
4345
returnsetAlert({
4446
message:result.msg,
4547
action:'fail',
46-
duration:result.duration||2500,
48+
duration:result.duration||2200,
4749
},'#FF4081');
48-
default:
49-
break;
5050
}
5151
returnsetAlert({
5252
message:result.msg,
53-
action:'note',
54-
duration:result.duration||2500,
53+
duration:result.duration||2200,
5554
},'#9DA5B4');
56-
case_types_1.COMPLETE_PAGE:
57-
returnsetAlert({
58-
message:"Page "+(action.payload.pagePosition+1)+" Complete",
59-
});
60-
case_types_1.COMPLETE_TUTORIAL:
61-
returnsetAlert({
62-
message:'Tutorial Complete',
63-
});
6455
default:
6556
returnalert;
6657
}

‎lib/reducers/hint-position/index.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ var _types_1 = require('../../actions/_types');
33
functionhintPositionReducer(hintPosition,action){
44
if(hintPosition===void0){hintPosition=0;}
55
switch(action.type){
6-
case_types_1.PAGE_SET:
7-
return0;
8-
case_types_1.TEST_RESULT:
9-
if(action.payload.result.change!==0){
10-
return0;
11-
}
12-
returnhintPosition;
136
case_types_1.HINT_POSITION_SET:
147
returnaction.payload.hintPosition;
158
default:

‎src/actions/alert.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
1-
import{ALERT_TOGGLE,ALERT_REPLAY}from'./_types';
1+
import{ALERT_REPLAY,ALERT_TOGGLE}from'./_types';
22

3-
exportfunctionalertToggle(alert?:CR.Alert):ReduxThunk.ThunkInterface{
3+
exportfunctionalertToggle(alert:Object,filter?:string):ReduxThunk.ThunkInterface{
44
return(dispatch,getState):void=>{
5-
constisOpen=getState().alert.open;
6-
if(!alert){
7-
alert={
8-
action:'',
9-
message:'',
10-
open:false,
11-
};
12-
}else{
13-
alert=Object.assign({},{open:!isOpen},alert);
14-
}
155
dispatch({type:ALERT_TOGGLE,payload:{ alert}});
166
};
177
}

‎src/actions/page.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
ROUTE_SET,PAGE_SET,PAGE_POSITION_SET
33
}from'./_types';
44
importconfigTaskTestsfrom'./config-task-tests';
5+
import{hintPositionSet}from'./hint';
56

67
exportfunctionpageNext():ReduxThunk.ThunkInterface|Action{
78
return(dispatch,getState):void=>{
@@ -29,6 +30,7 @@ export function pageSet(pagePosition = 0): ReduxThunk.ThunkInterface {
2930
dispatch({
3031
type:PAGE_SET,payload:{ dir, pagePosition, tutorial, progress, tasks}
3132
});
33+
dispatch(hintPositionSet(0));
3234
};
3335
}
3436

‎src/actions/progress.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import{
22
PROGRESS_PAGE_POSITION_LOAD,PROGRESS_LOAD,COMPLETE_PAGE,COMPLETE_TUTORIAL
33
}from'./_types';
4+
import{alertToggle}from'./alert';
45

56
exportfunctionprogressPagePositionLoad():ReduxThunk.ThunkInterface{
67
return(dispatch,getState):void=>{
@@ -22,16 +23,25 @@ export function completePage(): ReduxThunk.ThunkInterface {
2223
return(dispatch,getState):void=>{
2324
const{pagePosition, progress, tutorial}=getState();
2425
// all pages are true, tutorial complete
26+
dispatch({type:COMPLETE_PAGE,payload:{ pagePosition, tutorial}});
2527
if(progress.pages.every(x=>x.completed)){
2628
dispatch(completeTutorial());
29+
}else{
30+
dispatch(alertToggle({
31+
message:`Page${pagePosition+1} Complete`,
32+
action:'pass',
33+
}));
2734
}
28-
dispatch({type:COMPLETE_PAGE,payload:{ pagePosition, tutorial}});
2935
};
3036
}
3137

3238
exportfunctioncompleteTutorial():ReduxThunk.ThunkInterface{
3339
return(dispatch,getState):void=>{
3440
const{tutorial}=getState();
3541
dispatch({type:COMPLETE_TUTORIAL,payload:{ tutorial}});
42+
dispatch(alertToggle({
43+
message:'Tutorial Complete',
44+
action:'pass',
45+
}));
3646
};
3747
}

‎src/actions/test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import{
22
TEST_RUN,TEST_RESULT,TEST_COMPLETE,TEST_SAVE
33
}from'./_types';
4+
import{hintPositionSet}from'./hint';
45

56
exportfunctiontestRun():ReduxThunk.ThunkInterface{
67
return(dispatch,getState):void=>{
@@ -14,10 +15,25 @@ export function testRun(): ReduxThunk.ThunkInterface {
1415
exportfunctiontestResult(result:Test.Result):ReduxThunk.ThunkInterface{
1516
return(dispatch,getState):void=>{
1617
const{taskActions}=getState();
17-
dispatch({type:TEST_RESULT,payload:{ result, taskActions}});
18+
constfilter:string=getTestFilter(result);
19+
if(result.change!==0){
20+
dispatch(hintPositionSet(0));
21+
}
22+
dispatch({type:TEST_RESULT,payload:{ result, taskActions}, filter});
1823
};
1924
}
2025

26+
functiongetTestFilter(result:Test.Result):string{
27+
switch(true){
28+
caseresult.pass&&result.change>0:
29+
return'PASS';
30+
caseresult.pass===false&&result.change<1:
31+
return'FAIL';
32+
default:
33+
return'NOTE';
34+
}
35+
}
36+
2137
exportfunctiontestComplete():Action{
2238
return{type:TEST_COMPLETE};
2339
}

‎src/actions/tutorial.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import{
2-
TUTORIALS_FIND,TUTORIAL_UPDATE,TUTORIAL_SET
2+
TUTORIALS_FIND,TUTORIAL_UPDATE,TUTORIAL_SET,
3+
ALERT_TOGGLE
34
}from'./_types';
45

56
exportfunctiontutorialSet(name:string):ReduxThunk.ThunkInterface{
@@ -9,8 +10,16 @@ export function tutorialSet(name: string): ReduxThunk.ThunkInterface {
910
};
1011
}
1112

12-
exportfunctiontutorialUpdate(name:string):Action{
13-
return{type:TUTORIAL_UPDATE,payload:{ name}};
13+
exportfunctiontutorialUpdate(name:string):ReduxThunk.ThunkInterface{
14+
return(dispatch,getState):void=>{
15+
constalert={
16+
message:`run \`npm install --save-dev${name}\``,
17+
action:'note',
18+
duration:4000,
19+
};
20+
dispatch({type:TUTORIAL_UPDATE,payload:{ name}});
21+
dispatch({type:ALERT_TOGGLE,payload:{ alert}});
22+
};
1423
}
1524

1625
exportfunctiontutorialsFind():ReduxThunk.ThunkInterface{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp