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

Commit04174cd

Browse files
committed
update tutorial versions and display latest tutorial version
1 parent8d27b84 commit04174cd

File tree

16 files changed

+128
-83
lines changed

16 files changed

+128
-83
lines changed

‎lib/components/Tutorials/UpdateTutorial/index.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ var UpdateTutorial = (function (_super) {
2626
UpdateTutorial.prototype.render=function(){
2727
var_a=this.props,tutorial=_a.tutorial,tutorialUpdate=_a.tutorialUpdate;
2828
return(React.createElement("span",null,
29-
React.createElement(update_1.default,{style:styles.icon,color:colors_1.pink500,onTouchTap:tutorialUpdate.bind(this,tutorial.name)})
30-
));
29+
React.createElement(update_1.default,{style:styles.icon,color:colors_1.pink500,onTouchTap:tutorialUpdate.bind(this,tutorial.name)}),
30+
React.createElement("span",null,tutorial.latest)));
3131
};
3232
returnUpdateTutorial;
3333
}(React.Component));

‎lib/components/Tutorials/index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var Tutorials = (function (_super) {
3636
),
3737
React.createElement(Table_1.TableRowColumn,null,
3838
tutorial.version,
39-
!tutorial.latest
39+
!tutorial.isLatest
4040
?React.createElement(UpdateTutorial_1.default,{tutorial:tutorial})
4141
:null)));
4242
}))),

‎lib/modules/tutorials/actions.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ var actions_2 = require('../tutorial/actions');
55
exports.tutorialSet=actions_2.tutorialSet;
66
functiontutorialUpdate(title){
77
returnfunction(dispatch){
8+
dispatch({type:types_1.TUTORIAL_UPDATE,payload:{title:title}});
89
varalert={
910
message:"run `npm install --save-dev "+title+"`",
1011
action:'note',
1112
duration:3000,
1213
};
13-
dispatch({type:types_1.TUTORIAL_UPDATE,payload:{title:title}});
1414
dispatch(actions_1.alertOpen(alert));
1515
};
1616
}
@@ -27,3 +27,8 @@ function tutorialsFind() {
2727
};
2828
}
2929
exports.tutorialsFind=tutorialsFind;
30+
functiontutorialVersion(_a){
31+
varname=_a.name,latest=_a.latest;
32+
return{type:types_1.TUTORIAL_VERSION,payload:{name:name,latest:latest}};
33+
}
34+
exports.tutorialVersion=tutorialVersion;

‎lib/modules/tutorials/index.js‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
2-
varlatestVersion_1=require('./latestVersion');
32
vartypes_1=require('./types');
3+
varlatestVersion_1=require('./utils/latestVersion');
44
varcoderoad_cli_1=require('coderoad-cli');
55
functiontutorialsReducer(t,action){
66
if(t===void0){t=[];}
@@ -11,9 +11,15 @@ function tutorialsReducer(t, action) {
1111
casetypes_1.TUTORIALS_UPDATE:
1212
returnt.map(function(tutorial){
1313
varname=tutorial.name,version=tutorial.version;
14-
if(version){
15-
latestVersion_1.default({name:name,version:version})
16-
.then(function(x){returntutorial.latest=x;});
14+
latestVersion_1.default({name:name,version:version});
15+
returntutorial;
16+
});
17+
casetypes_1.TUTORIAL_VERSION:
18+
var_a=action.payload,name_1=_a.name,latest_1=_a.latest;
19+
t.map(function(tutorial){
20+
if(tutorial.name===name_1){
21+
tutorial.isLatest=false;
22+
tutorial.latest=latest_1;
1723
}
1824
returntutorial;
1925
});

‎lib/modules/tutorials/types.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
exports.TUTORIALS_FIND='TUTORIALS_FIND';
33
exports.TUTORIALS_UPDATE='TUTORIALS_UPDATE';
44
exports.TUTORIAL_UPDATE='TUTORIAL_UPDATE';
5+
exports.TUTORIAL_VERSION='TUTORIAL_VERSION';
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"use strict";
2+
varstore_1=require('../../../store');
3+
varcompareVersions_1=require('../../../utils/compareVersions');
4+
varfetch_1=require('../../../utils/fetch');
5+
varactions_1=require('./actions');
6+
varnpmApiCall=function(name){return("https://registry.npmjs.org/"+name);};
7+
functiongetLatest(version,data){
8+
returndata['dist-tags'].latest;
9+
}
10+
functionisLatestVersion(_a){
11+
varname=_a.name,version=_a.version;
12+
window.fetch(npmApiCall(name))
13+
.then(fetch_1.status)
14+
.then(fetch_1.json)
15+
.then(getLatest.bind(this,version))
16+
.then(function(latest){
17+
if(!compareVersions_1.isAboveVersion(version,latest)){
18+
store_1.default.dispatch(actions_1.tutorialVersion({name:name,latest:latest}));
19+
}
20+
})
21+
.catch(function(err){returnconsole.log("Error fetching tutorial \""+name+"\": "+err);});
22+
}
23+
Object.defineProperty(exports,"__esModule",{value:true});
24+
exports.default=isLatestVersion;

‎lib/utils/fetch.js‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
"use strict";
2-
varfetch=function(url){
3-
returnnewPromise(function(resolve,reject){
4-
varlib=url.startsWith('https') ?require('https') :require('http');
5-
varrequest=lib.get(url,function(response){
6-
if(response.statusCode<200||response.statusCode>299){
7-
reject(newError('Failed to load page, status code: '+response.statusCode));
8-
}
9-
varbody=[];
10-
response.on('data',function(chunk){returnbody.push(chunk);});
11-
response.on('end',function(){returnresolve(body.join(''));});
12-
});
13-
request.on('error',function(err){returnreject(err);});
14-
});
15-
};
16-
Object.defineProperty(exports,"__esModule",{value:true});
17-
exports.default=fetch;
2+
functionstatus(response){
3+
if(response.status>=200&&response.status<300){
4+
returnPromise.resolve(response);
5+
}
6+
else{
7+
returnPromise.reject(newError(response.statusText));
8+
}
9+
}
10+
exports.status=status;
11+
functionjson(response){
12+
returnresponse.json();
13+
}
14+
exports.json=json;

‎src/components/Tutorials/UpdateTutorial/index.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class UpdateTutorial extends React.Component<{
2727
color={pink500}
2828
onTouchTap={tutorialUpdate.bind(this,tutorial.name)}
2929
/>
30+
<span>{tutorial.latest}</span>
3031
</span>
3132
);
3233
}

‎src/components/Tutorials/index.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Tutorials extends React.Component<{
4848
<TableRowColumn>
4949
{tutorial.version}
5050

51-
{!tutorial.latest
51+
{!tutorial.isLatest
5252
?<UpdateTutorialtutorial={tutorial}/>
5353
:null
5454
}

‎src/modules/tutorials/actions.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import{alertOpen}from'../alert/actions';
2-
import{TUTORIALS_FIND,TUTORIALS_UPDATE,TUTORIAL_UPDATE}from'./types';
2+
import{TUTORIALS_FIND,TUTORIALS_UPDATE,TUTORIAL_UPDATE,TUTORIAL_VERSION}from'./types';
33
export{tutorialSet}from'../tutorial/actions';
44

55
exportfunctiontutorialUpdate(title:string):
66
Redux.ThunkAction<any,{},{}>{
77
return(dispatch)=>{
8+
dispatch({type:TUTORIAL_UPDATE,payload:{ title}});
9+
10+
// alert instructions
811
constalert={
912
message:`run \`npm install --save-dev${title}\``,
1013
action:'note',
1114
duration:3000,
1215
};
13-
dispatch({type:TUTORIAL_UPDATE,payload:{ title}});
1416
dispatch(alertOpen(alert));
1517
};
1618
}
@@ -26,3 +28,7 @@ export function tutorialsFind(): Redux.ThunkAction<any, {dir: string}, {}> {
2628
dispatch(tutorialsUpdate());
2729
};
2830
}
31+
32+
exportfunctiontutorialVersion({name, latest}):Action{
33+
return{type:TUTORIAL_VERSION,payload:{ name, latest}};
34+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp