Skip to content

Commit

Permalink
refactor: use Arrow Function (#333)
Browse files Browse the repository at this point in the history
* feat(Ch4): クラス構文の補足を追加

* refactor: use Arrow Function

* refactor: use Arrow Function

* fix
  • Loading branch information
azu authored Oct 12, 2019
1 parent fc81e2e commit 0828ee6
Show file tree
Hide file tree
Showing 20 changed files with 47 additions and 47 deletions.
4 changes: 2 additions & 2 deletions Ch1_WhatsPromises/src/xhr-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ function fetchURL(URL) {
return new Promise((resolve, reject) => {
const req = new XMLHttpRequest();
req.open("GET", URL, true);
req.onload = function() {
req.onload = () => {
if (200 <= req.status && req.status < 300) {
resolve(req.responseText);
} else {
reject(new Error(req.statusText));
}
};
req.onerror = function() {
req.onerror = () => {
reject(new Error(req.statusText));
};
req.send();
Expand Down
4 changes: 2 additions & 2 deletions Ch2_HowToWrite/promise-all.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
----
include::embed/embed-promise-all-xhr.js[]
// 実行例
main().then(function (value) {
main().then((value) => {
console.log(value);
}).catch(function(error){
}).catch((error) => {
console.error(error);
});
----
Expand Down
4 changes: 2 additions & 2 deletions Ch2_HowToWrite/promise-and-array.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ function bindJSONParse(error, value) {
----
include::embed/embed-multiple-xhr.js[]
// 実行例
main().then(function (value) {
main().then((value) => {
console.log(value);
}).catch(function(error){
}).catch((error) => {
console.error(error);
});
----
Expand Down
4 changes: 2 additions & 2 deletions Ch2_HowToWrite/promise-finally.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ function fetchResource(URL) {
return new Promise((resolve, reject) => {
const req = new XMLHttpRequest();
req.open("GET", URL, true);
req.onload = function() {
req.onload = () => {
if (200 <= req.status && req.status < 300) {
resolve(req.responseText);
} else {
reject(new Error(req.statusText));
}
};
req.onerror = function() {
req.onerror = () => {
reject(new Error(req.statusText));
};
req.send();
Expand Down
4 changes: 2 additions & 2 deletions Ch2_HowToWrite/src/multiple-xhr-callback-counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
function fetchURLCallback(URL, callback) {
const req = new XMLHttpRequest();
req.open("GET", URL, true);
req.onload = function() {
req.onload = () => {
if (200 <= req.status && req.status < 300) {
callback(null, req.responseText);
} else {
callback(new Error(req.statusText), req.response);
}
};
req.onerror = function() {
req.onerror = () => {
callback(new Error(req.statusText));
};
req.send();
Expand Down
8 changes: 4 additions & 4 deletions Ch2_HowToWrite/src/multiple-xhr-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
function fetchURLCallback(URL, callback) {
const req = new XMLHttpRequest();
req.open("GET", URL, true);
req.onload = function() {
req.onload = () => {
if (200 <= req.status && req.status < 300) {
callback(null, req.responseText);
} else {
callback(new Error(req.statusText), req.response);
}
};
req.onerror = function() {
req.onerror = () => {
callback(new Error(req.statusText));
};
req.send();
Expand All @@ -29,10 +29,10 @@ function jsonParse(callback, error, value) {
}
// <2> XHRを叩いてリクエスト
const request = {
comment: function fetchComment(callback) {
comment(callback) {
return fetchURLCallback("https://azu.github.io/promises-book/json/comment.json", jsonParse.bind(null, callback));
},
people: function fetchPeople(callback) {
people(callback) {
return fetchURLCallback("https://azu.github.io/promises-book/json/people.json", jsonParse.bind(null, callback));
}
};
Expand Down
4 changes: 2 additions & 2 deletions Ch2_HowToWrite/src/multiple-xhr.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use strict";
const fetchURL = require("../../Ch1_WhatsPromises/src/xhr-promise").fetchURL;
const request = {
comment: function fetchComment() {
comment() {
return fetchURL("https://azu.github.io/promises-book/json/comment.json").then(JSON.parse);
},
people: function fetchPeople() {
people() {
return fetchURL("https://azu.github.io/promises-book/json/people.json").then(JSON.parse);
}
};
Expand Down
4 changes: 2 additions & 2 deletions Ch2_HowToWrite/src/promise-all-xhr.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use strict";
const fetchURL = require("../../Ch1_WhatsPromises/src/xhr-promise").fetchURL;
const request = {
comment: function fetchComment() {
comment() {
return fetchURL("https://azu.github.io/promises-book/json/comment.json").then(JSON.parse);
},
people: function fetchPeople() {
people() {
return fetchURL("https://azu.github.io/promises-book/json/people.json").then(JSON.parse);
}
};
Expand Down
4 changes: 2 additions & 2 deletions Ch4_AdvancedPromises/lib/cancelableXHR.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ function createXHRPromise(URL) {
delete requestMap[URL];
}
};
req.onload = function() {
req.onload = () => {
if (200 <= req.status && req.status < 300) {
resolve(req.responseText);
} else {
reject(new Error(req.statusText));
}
};
req.onerror = function() {
req.onerror = () => {
reject(new Error(req.statusText));
};
req.onabort = function() {
Expand Down
2 changes: 1 addition & 1 deletion Ch4_AdvancedPromises/promise-done.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ include::embed/embed-json-promise.js[]
var string = "jsonではない文字列";
JSONPromise(string).then(function (object) {
console.log(object);
}).catch(function(error){
}).catch((error) => {
// => JSON.parseで例外が発生した時
console.error(error);
});
Expand Down
16 changes: 8 additions & 8 deletions Ch4_AdvancedPromises/promise-sequence.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Aの処理 が終わったら Bの処理 というような逐次的な処理を
----
include::../Ch2_HowToWrite/embed/embed-multiple-xhr.js[]
// 実行例
main().then(function (value) {
main().then((value) => {
console.log(value);
}).catch(function(error){
}).catch((error) => {
console.error(error);
});
----
Expand All @@ -40,9 +40,9 @@ main().then(function (value) {
----
include::embed/embed-promise-foreach-xhr.js[]
// 実行例
main().then(function (value) {
main().then((value) => {
console.log(value);
}).catch(function(error){
}).catch((error) => {
console.error(error);
});
----
Expand All @@ -69,9 +69,9 @@ forループで書く場合、<<then-return-new-promise,コラム: thenは常に
----
include::embed/embed-promise-reduce-xhr.js[]
// 実行例
main().then(function (value) {
main().then((value) => {
console.log(value);
}).catch(function(error){
}).catch((error) => {
console.error(error);
});
----
Expand Down Expand Up @@ -139,9 +139,9 @@ promiseオブジェクトを作った段階ですでにXHRが実行されてい
----
include::embed/embed-promise-sequence-xhr.js[]
// 実行例
main().then(function (value) {
main().then((value) => {
console.log(value);
}).catch(function(error){
}).catch((error) => {
console.error(error);
});
----
Expand Down
2 changes: 1 addition & 1 deletion Ch4_AdvancedPromises/race-delay-timeout.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var taskPromise = new Promise(function(resolve){
});
timeoutPromise(taskPromise, 1000).then(function(value){
console.log("taskPromiseが時間内に終わった : " + value);
}).catch(function(error){
}).catch((error) => {
console.log("タイムアウトになってしまった", error);
});
----
Expand Down
4 changes: 2 additions & 2 deletions Ch4_AdvancedPromises/resolve-thenable.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ include::embed/embed-notification-as-promise.js[]
// 実行例
notifyMessageAsPromise("Hi!").then(function (notification) {
console.log(notification);// 通知のオブジェクト
}).catch(function(error){
}).catch((error) => {
console.error(error);
});
----
Expand Down Expand Up @@ -195,7 +195,7 @@ include::embed/embed-notification-thenable.js[]
// 実行例
Promise.resolve(notifyMessageAsThenable("message")).then(function (notification) {
console.log(notification);// 通知のオブジェクト
}).catch(function(error){
}).catch((error) => {
console.error(error);
});
----
Expand Down
4 changes: 2 additions & 2 deletions Ch4_AdvancedPromises/src/deferred/xhr-deferred.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ function fetchURL(URL) {
const deferred = new Deferred();
const req = new XMLHttpRequest();
req.open("GET", URL, true);
req.onload = function() {
req.onload = () => {
if (200 <= req.status && req.status < 300) {
deferred.resolve(req.responseText);
} else {
deferred.reject(new Error(req.statusText));
}
};
req.onerror = function() {
req.onerror = () => {
deferred.reject(new Error(req.statusText));
};
req.send();
Expand Down
4 changes: 2 additions & 2 deletions Ch4_AdvancedPromises/src/grouping-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ function getXHRTimeout(URL) {
const deferred = new Deferred();
const req = new XMLHttpRequest();
req.open("GET", URL, true);
req.onload = function() {
req.onload = () => {
if (200 <= req.status && req.status < 300) {
deferred.resolve(req.responseText);
} else {
deferred.reject(new Error(req.statusText));
}
};
req.onerror = function() {
req.onerror = () => {
deferred.reject(new Error(req.statusText));
};
req.send();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ function cancelableXHR(URL) {
const req = new XMLHttpRequest();
const promise = new Promise((resolve, reject) => {
req.open("GET", URL, true);
req.onload = function() {
req.onload = () => {
if (200 <= req.status && req.status < 300) {
resolve(req.responseText);
} else {
reject(new Error(req.statusText));
}
};
req.onerror = function() {
req.onerror = () => {
reject(new Error(req.statusText));
};
req.onabort = function() {
Expand Down
4 changes: 2 additions & 2 deletions Ch4_AdvancedPromises/src/sequence/promise-foreach-xhr.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use strict";
const fetchURL = require("../../../Ch1_WhatsPromises/src/xhr-promise").fetchURL;
const request = {
comment: function fetchComment() {
comment() {
return fetchURL("https://azu.github.io/promises-book/json/comment.json").then(JSON.parse);
},
people: function fetchPeople() {
people() {
return fetchURL("https://azu.github.io/promises-book/json/people.json").then(JSON.parse);
}
};
Expand Down
4 changes: 2 additions & 2 deletions Ch4_AdvancedPromises/src/sequence/promise-reduce-xhr.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use strict";
const fetchURL = require("../../../Ch1_WhatsPromises/src/xhr-promise").fetchURL;
const request = {
comment: function fetchComment() {
comment() {
return fetchURL("https://azu.github.io/promises-book/json/comment.json").then(JSON.parse);
},
people: function fetchPeople() {
people() {
return fetchURL("https://azu.github.io/promises-book/json/people.json").then(JSON.parse);
}
};
Expand Down
4 changes: 2 additions & 2 deletions Ch4_AdvancedPromises/src/sequence/promise-sequence-xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
const sequenceTasks = require("../../lib/promise-sequence").sequenceTasks;
const fetchURL = require("../../../Ch1_WhatsPromises/src/xhr-promise").fetchURL;
const request = {
comment: function fetchComment() {
comment() {
return fetchURL("https://azu.github.io/promises-book/json/comment.json").then(JSON.parse);
},
people: function fetchPeople() {
people() {
return fetchURL("https://azu.github.io/promises-book/json/people.json").then(JSON.parse);
}
};
Expand Down
6 changes: 3 additions & 3 deletions test/inline-script/run-inline-script-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* LICENSE : MIT
*/
"use strict";
var checkInlineScript = require("./inline-script-tester").checkInlineScript;
checkInlineScript("../../").catch(function (error) {
if(error) {
const checkInlineScript = require("./inline-script-tester").checkInlineScript;
checkInlineScript("../../").catch((error) => {
if (error) {
console.error(error);
}
});

0 comments on commit 0828ee6

Please sign in to comment.