binding
binding copied to clipboard
REQUEST: downgrade 'No Aurelia APIs are defined for the element: "xxx".' from thrown error to warning message
I'm submitting a feature request
currently aurelia enhance is falling over when it gets elements with element/controller/view-model/view which are not defined
and it breaks the bootstraping of aurelia
caused by this code
function getAU(element) {
let au = element.au;
if (au === undefined) {
throw new Error(`No Aurelia APIs are defined for the element: "${element.tagName}".`);
}
return au;
}
node_modules\aurelia-binding\dist\aurelia-binding.js
is there any chance this could be sent as a warning or try/catched into a warning
currently monkey patched with this in dev which not ideal, to stopping html inserted ahead of js components being deployed breaking builds
// Monkey Patch : turn thrown error into error message
import {NameExpression} from 'aurelia-binding';
function getAU(element) {
var au = element.au;
if (au === undefined) {
// assumption that aurelia instance available
aurelia.logger.error('No Aurelia APIs are defined for the element: "' + element.tagName + '".');
// throw new Error('No Aurelia APIs are defined for the element: "' + element.tagName + '".');
}
return au;
}
NameExpression.locateAPI = function locateAPI(element, apiName) {
switch (apiName) {
case 'element':
return element;
case 'controller':
return getAU(element).controller;
case 'view-model':
return getAU(element).controller.viewModel;
case 'view':
return getAU(element).controller.view;
default:
var target = getAU(element)[apiName];
if (target === undefined) {
throw new Error('Attempted to reference "' + apiName + '", but it was not found amongst the target\'s API.');
}
return target.viewModel;
}
};
- Library Version: ALL
Please tell us about your environment:
-
Operating System: NA
-
Node Version: NA
-
JSPM OR Webpack AND Version NA
-
Browser: NA
-
Language: NA
Current behavior:
Expected/desired behavior:
-
What is the expected behavior? Aurelia should be robust and not fall over / aka cascade exception, when finding dom without Aurelia API
-
What is the motivation / use case for changing the behavior? Aurelia should be tough and handle not ideal html gracefully (but still call out error and the situations)
Can't you just add a try-catch around your own code calling enhance
?
I ask because it sounds like there's a bug in your code, where you're calling an Aurelia api when you shouldn't have?
@Anthony-Mckale Please provide an minimal example code when it fails for you. How are you using it?
this gist is configured with the latest version of aurelia: https://gist.run/?id=7542e061bc940cde506b
The error comes from ref
binding, which happens when names of reference cannot be found. I think:
- it's a must that this fails hard & fast
- this error should be documented.
Would be nice if @Anthony-Mckale or some community member could help with this 😃
@Anthony-Mckale I use ref with enhance and it works if you register your components with .globalResources()
.globalResources( [ PLATFORM.moduleName("globals/checkaccess") ,PLATFORM.moduleName("globals/message") ]);
@magnusdanielson yeah i ended up doing that for the webpack port, i'm now on a new contract doing react work, looking forward to see how aurelia next goes though