Several enhance statements with one Aurelia instance
I'm submitting a bug report
- Library Version: 1.0.0
Please tell us about your environment:
-
Operating System: OSX 10.11.6
-
Node Version: 5.8.0
- NPM Version: 3.7.3
- JSPM OR Webpack AND Version webpack 1.12.14
- Browser: all
-
Language: ESNext
Current behavior:
When I run this code it enhanced my-component1 two times. Because after first enhance my-component1 becomes an application host and then all following enhances runs in context of first enhanced component and just tries to enhance it again and again.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body>
<my-component1></my-component1>
<my-component2></my-component2>
</body>
</html>
import { bootstrap } from 'aurelia-bootstrapper-webpack';
bootstrap(function(aurelia) {
aurelia.use
.standardConfiguration()
.globalResources("my-component1", "my-component2");
aurelia.start().then((app) => {
// Enhance first element
app.enhance(null, document.querySelector('my-component1'));
// Get some data from server and then enhance second element with binding context
getSomeDataFromServer().then((data) => {
app.enhance(data, document.querySelector('my-component2'));
});
});
});
Expected/desired behavior:
Possibility to enhance several elements on existing page with several app.enhance statements in context of one Aurelia instance. Cause now it seems like you need to start new Aurelia instance for every enhanced component on the page.
- What is the motivation / use case for changing the behavior? To have a possibility to gradually enhance existing page with Aurelia.
http://stackoverflow.com/questions/39311949/aurelia-multiple-enhance-statements
@SidKH would you mind putting together a gist that demonstrates what is not working: https://gist.run/?id=7542e061bc940cde506b
This will enable us to get to the bottom of this very quickly, and can be the basis for the unit tests we'll write if there's a bug-fix required.
#600
Please use the templating engine's enhance to specifically target individual elements that you want to enhance when you are doing this multiple times.
@EisenbergEffect Can you provide a code snippet of how to best access the TemplatingEngine for this use case?
System.import('aurelia-bootstrapper').then(function(bootstrapper) {
bootstrapper.bootstrap(function(aurelia) {
aurelia.use
.defaultBindingLanguage()
.defaultResources()
.developmentLogging()
.globalResources('components/my-component1')
.globalResources('components/my-component2');
aurelia.start().then(function() {
//aurelia.enhance(); access templatingEninge's enhance instead?
});
});
});
I'm using the TypeScript skeleton btw thx
I'm honestly not sure what you are trying to do. The code above is where you would use the aurelia object's version, but if you want to enhance new elements at a later time, you would use the templating engine on those elements.
Additionally, I would like to understand why you are trying to do this. I can only think of one or two valid reasons. Most people do this because they don't realize there is an easier way to do dynamic composition with the compose element.
Can you provide more information?
Thanks for the answers, I've already used the templating engine enhance to solve this problem. And about my reasons to do this. I have an existing application in production which was built in a terrible way with jQuery plus Angular and what I want is to refactor it component by component in Aurelia. And to do it I need a possibility to enhance several elements on the page.
Got it. Glad you got it sorted. Perhaps you would be interested in contributing something to our docs to help future developers?
Well, actually the same thing @SidKH is trying to do, refactor existing webapp component by component. The code sample is just the one from the docs for progressive enhancement. However as pointed out I need to use the templating engine but idk what my startup code needs to look like.
@EisenbergEffect of course. I'm on vacation currently without access to my notebook, but as soon as I return I will create a PR with additional information on how you can enhance several components with template engine.
@SidKH Great! That would be a huge help to the community and a very nice contribution credit :)