-
-
Save niieani/78e6ce914568a9b336d05eb301dc0c14 to your computer and use it in GitHub Desktop.
Aurelia Inconsistent Template Behaviour
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<require from="./attaching-span"></require> | |
<h1>${message}</h1> | |
<button click.delegate="addNumber('before')">Add number before</button> | |
<button click.delegate="addNumber('after')">Add number after</button> | |
<div> | |
<span as-element="attaching-span" repeat.for="number of numbers">${number}</span> | |
</div> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {inject, ObserverLocator, TaskQueue} from 'aurelia-framework'; | |
@inject(ObserverLocator, TaskQueue) | |
export class App { | |
constructor(observerLocator, taskQueue) { | |
this.message = 'Hello World!'; | |
this.numbers = []; | |
observerLocator.getArrayObserver(this.numbers).subscribe(() => { | |
taskQueue.queueMicroTask(() => { | |
alert(`If you add number after everything should be good now.\n\nIf you add number before elements will be duplicated, after exiting this alert rendering will complete`); | |
}); | |
}); | |
} | |
addNumber(location) { | |
const newNumber = this.numbers.length; | |
if(location == 'before') { | |
this.numbers.unshift(newNumber); | |
} else { | |
this.numbers.push(newNumber); | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {inlineView, customElement} from 'aurelia-framework' | |
@customElement('attaching-span') | |
@inlineView(`<template><content></content></template>`) | |
export class AttachingSpan { | |
attached() { | |
// you can notify that the element is attached, but the method has to be present | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Aurelia</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body aurelia-app> | |
<h1>Loading...</h1> | |
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script> | |
<script> | |
require(['aurelia-bootstrapper']); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment