Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 80ff464

Browse files
committedDec 23, 2024
Improve code style
1 parent 9fd7b31 commit 80ff464

File tree

10 files changed

+34
-30
lines changed

10 files changed

+34
-30
lines changed
 

‎JavaScript/0-pause.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const thenable = {
44
then(onFulfilled) {
55
setTimeout(onFulfilled, 1000);
6-
}
6+
},
77
};
88

99
(async () => {

‎JavaScript/1-contract.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const thenableFactory = () => ({
44
then(onFulfilled) {
55
onFulfilled(5);
6-
}
6+
},
77
});
88

99
// Usage

‎JavaScript/2-usage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const getPerson = (id) => {
77
const person = { id, name: 'Marcus Aurelius' };
88
onFulfilled(person);
99
}, 1000);
10-
}
10+
},
1111
};
1212
return thenable;
1313
};

‎JavaScript/4-rejection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const getNumbers = () => ({
99
} else {
1010
onRejected(new Error('I have no numbers for you'));
1111
}
12-
}
12+
},
1313
});
1414

1515
// Usage

‎JavaScript/6-next.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
const getNumbers = () => {
44
const numbers = [1, 2, 3];
5-
return () => new Promise((resolve, reject) => {
6-
const num = numbers.shift();
7-
if (num) {
8-
resolve(num);
9-
} else {
10-
reject(new Error('I have no numbers for you'));
11-
}
12-
});
5+
return () =>
6+
new Promise((resolve, reject) => {
7+
const num = numbers.shift();
8+
if (num) {
9+
resolve(num);
10+
} else {
11+
reject(new Error('I have no numbers for you'));
12+
}
13+
});
1314
};
1415

1516
// Usage

‎JavaScript/7-then.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
const getNumbers = () => {
44
const numbers = [1, 2, 3];
5-
return () => new Promise((resolve, reject) => {
6-
const num = numbers.shift();
7-
if (num) {
8-
resolve(num);
9-
} else {
10-
reject(new Error('I have no numbers for you'));
11-
}
12-
});
5+
return () =>
6+
new Promise((resolve, reject) => {
7+
const num = numbers.shift();
8+
if (num) {
9+
resolve(num);
10+
} else {
11+
reject(new Error('I have no numbers for you'));
12+
}
13+
});
1314
};
1415

1516
// Usage
@@ -18,6 +19,6 @@ const getNext = getNumbers();
1819
for (let i = 0; i < 5; i++) {
1920
getNext().then(
2021
(res) => console.dir({ res }),
21-
(err) => console.dir({ err: err.message })
22+
(err) => console.dir({ err: err.message }),
2223
);
2324
}

‎JavaScript/8-chain.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const getNumbers = () => ({
1010
onRejected(new Error('I have no numbers for you'));
1111
}
1212
return this; // chain thenable
13-
}
13+
},
1414
});
1515

1616
// Usage

‎JavaScript/Tasks/2-reject.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
const iterate = (items) => {
66
let index = 0;
77
return {
8-
then(fulfill, /*reject*/) {
8+
then(fulfill /*reject*/) {
99
// Call both: fulfill and reject
1010
if (index < items.length) {
1111
fulfill(items[index++]);
1212
}
13-
}
13+
},
1414
};
1515
};
1616

‎JavaScript/Tasks/3-class.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
const iterate = (items) => {
77
let index = 0;
88
return {
9-
then(fulfill, /*reject*/) {
9+
then(fulfill /*reject*/) {
1010
if (index < items.length) {
1111
fulfill(items[index++]);
1212
}
13-
}
13+
},
1414
};
1515
};
1616

‎JavaScript/a-query.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ class Query {
2222

2323
then(resolve) {
2424
const { table, fields, where, limit, order } = this.options;
25-
const cond = Object.entries(where).map((e) => e.join('=')).join(' AND ');
25+
const cond = Object.entries(where)
26+
.map((e) => e.join('='))
27+
.join(' AND ');
2628
const sql = `SELECT ${fields} FROM ${table} WHERE ${cond}`;
2729
const opt = `ORDER BY ${order} LIMIT ${limit}`;
2830
resolve(sql + ' ' + opt);
@@ -31,12 +33,12 @@ class Query {
3133

3234
// Usage
3335

34-
(async () => {
35-
36+
const main = async () => {
3637
const sql = await new Query('cities')
3738
.where({ country: 10, type: 1 })
3839
.order('population')
3940
.limit(10);
4041
console.log(sql);
42+
};
4143

42-
})();
44+
main();

0 commit comments

Comments
 (0)
Please sign in to comment.