-
-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathperform.js
38 lines (34 loc) · 1.02 KB
/
perform.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { helper } from '@ember/component/helper';
import { assert } from '@ember/debug';
import { taskHelperClosure } from 'ember-concurrency/-private/helpers';
function maybeReportError(onError) {
return function (e) {
if (typeof onError === 'function') {
onError(e);
} else if (onError === null) {
// Do nothing
} else {
assert(
`The onError argument passed to the \`perform\` helper should be a function or null; you passed ${onError}`,
false
);
}
};
}
export function performHelper(args, hash) {
let perform = taskHelperClosure('perform', 'perform', args, hash);
if (hash && typeof hash.onError !== 'undefined') {
return function (...innerArgs) {
try {
let taskInstance = perform(...innerArgs);
return taskInstance.catch(maybeReportError(hash.onError));
// eslint-disable-next-line no-empty
} catch {
maybeReportError(hash.onError);
}
};
} else {
return perform;
}
}
export default helper(performHelper);