DEV: allows to use routeAction from components/widgets (#9267)

ATM this is only usable as a helper in templates.
This commit is contained in:
Joffrey JAFFEUX 2020-03-25 15:51:30 +01:00 committed by GitHub
parent 2ed0f8d120
commit 7d7c5641b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 21 deletions

View File

@ -32,29 +32,32 @@ function getRouteWithAction(router, actionName) {
return { action, handler };
}
export function routeAction(actionName, router, ...params) {
assert("[ember-route-action-helper] Unable to lookup router", router);
runInDebug(() => {
let { handler } = getRouteWithAction(router, actionName);
assert(
`[ember-route-action-helper] Unable to find action ${actionName}`,
handler
);
});
return function(...invocationArgs) {
let { action, handler } = getRouteWithAction(router, actionName);
let args = params.concat(invocationArgs);
return run.join(handler, action, ...args);
};
}
export default Helper.extend({
router: computed(function() {
return getOwner(this).lookup("router:main");
}).readOnly(),
router: computed({
get() {
return getOwner(this).lookup("router:main");
}
}),
compute([actionName, ...params]) {
let router = get(this, "router");
assert("[ember-route-action-helper] Unable to lookup router", router);
runInDebug(() => {
let { handler } = getRouteWithAction(router, actionName);
assert(
`[ember-route-action-helper] Unable to find action ${actionName}`,
handler
);
});
let routeAction = function(...invocationArgs) {
let { action, handler } = getRouteWithAction(router, actionName);
let args = params.concat(invocationArgs);
return run.join(handler, action, ...args);
};
return routeAction;
return routeAction(actionName, get(this, "router"), ...params);
}
});