Skip to content

Commit 3c8339f

Browse files
committed
Revert "revert: change AsyncOption to prototype-style."
This reverts commit a5cbd67.
1 parent 91d8720 commit 3c8339f

File tree

1 file changed

+54
-54
lines changed

1 file changed

+54
-54
lines changed

packages/@vuepress/core/lib/plugin-api/abstract/AsyncOption.js

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,69 +11,69 @@ const Option = require('./Option')
1111
* Expose Asynchronous Option.
1212
*/
1313

14-
class AsyncOption extends Option {}
14+
class AsyncOption extends Option {
15+
/**
16+
* Asynchronous serial running
17+
* @param args
18+
* @param {Array<AsyncFunction>} args
19+
*/
1520

16-
/**
17-
* Asynchronous serial running
18-
* @param args
19-
* @param {Array<AsyncFunction>} args
20-
*/
21-
22-
AsyncOption.prototype.asyncApply = async function (...args) {
23-
const items = []
24-
for (const { name, value } of this.items) {
25-
try {
26-
items.push({
27-
name,
28-
value: isFunction(value)
29-
? await value(...args)
30-
: value
31-
})
32-
} catch (error) {
33-
logger.error(`${chalk.cyan(name)} apply ${chalk.cyan(this.key)} failed.`)
34-
throw error
21+
async asyncApply (...args) {
22+
const items = []
23+
for (const { name, value } of this.items) {
24+
try {
25+
items.push({
26+
name,
27+
value: isFunction(value)
28+
? await value(...args)
29+
: value
30+
})
31+
} catch (error) {
32+
logger.error(`${chalk.cyan(name)} apply ${chalk.cyan(this.key)} failed.`)
33+
throw error
34+
}
3535
}
36+
this.appliedItems = items
3637
}
37-
this.appliedItems = items
38-
}
3938

40-
/**
41-
* Asynchronous serial running
42-
* @param args
43-
* @param {Array<AsyncFunction>} args
44-
*/
39+
/**
40+
* Asynchronous serial running
41+
* @param args
42+
* @param {Array<AsyncFunction>} args
43+
*/
4544

46-
AsyncOption.prototype.parallelApply = async function (...args) {
47-
const items = []
48-
await Promise.all(this.items.map(async ({ name, value }) => {
49-
try {
50-
items.push({
51-
name,
52-
value: isFunction(value)
53-
? await value(...args)
54-
: value
55-
})
56-
} catch (error) {
57-
logger.error(`${chalk.cyan(name)} apply ${chalk.cyan(this.key)} failed.`)
45+
async parallelApply (...args) {
46+
const items = []
47+
await Promise.all(this.items.map(async ({ name, value }) => {
48+
try {
49+
items.push({
50+
name,
51+
value: isFunction(value)
52+
? await value(...args)
53+
: value
54+
})
55+
} catch (error) {
56+
logger.error(`${chalk.cyan(name)} apply ${chalk.cyan(this.key)} failed.`)
57+
throw error
58+
}
59+
})).catch(error => {
5860
throw error
59-
}
60-
})).catch(error => {
61-
throw error
62-
})
63-
return items
64-
}
61+
})
62+
return items
63+
}
6564

66-
/**
67-
* Process a value via a pipeline.
68-
* @param input
69-
* @returns {*}
70-
*/
65+
/**
66+
* Process a value via a pipeline.
67+
* @param input
68+
* @returns {*}
69+
*/
7170

72-
AsyncOption.prototype.pipeline = async function (input) {
73-
for (const fn of this.values) {
74-
input = await fn(input)
71+
async pipeline (input) {
72+
for (const fn of this.values) {
73+
input = await fn(input)
74+
}
75+
return input
7576
}
76-
return input
7777
}
7878

7979
AsyncOption.prototype.apply = AsyncOption.prototype.asyncApply

0 commit comments

Comments
 (0)