Last active
May 7, 2019 14:24
-
-
Save charlespockert/ee30c0e70d80bb38c77b1d77137f1de4 to your computer and use it in GitHub Desktop.
Composition test
This file contains hidden or 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="./composition"></require> | |
<component-renderer view-model.bind="testVm" element.bind="comp" ref="comp"></component-renderer> | |
</template> |
This file contains hidden or 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 {Test} from 'test'; | |
export class App { | |
message = 'Hello World'; | |
testVm = null; | |
constructor() { | |
this.testVm = new Test(); | |
} | |
} |
This file contains hidden or 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> | |
</template> |
This file contains hidden or 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 { noView, inject, bindable, observable, autoinject, CompositionEngine, CompositionContext, Container, ViewSlot } from "aurelia-framework"; | |
@inject(CompositionEngine, Container, Element) | |
@noView | |
export class ComponentRenderer { | |
@bindable | |
model = null; | |
@bindable | |
viewModel = null; | |
@bindable | |
element; | |
container; | |
compositionEngine; | |
constructor(compositionEngine, container) { | |
this.container = container; | |
this.compositionEngine = compositionEngine; | |
} | |
activate() { | |
this.elementChanged(); | |
} | |
elementChanged() { | |
console.log("element changed"); | |
if (this.element !== null) { | |
let context = this.createContext(this.viewModel, this.element, this.model); | |
let _this = this; | |
this.compositionEngine.compose(context).then((view) => { | |
console.log("rendered") | |
}); | |
} | |
} | |
createContext(viewModel, host, model): CompositionContext { | |
return { | |
container: this.container.createChild(), | |
viewModel: viewModel, | |
model: model, | |
host: host, | |
bindingContext: null, | |
viewResources: null, | |
viewSlot: new ViewSlot(host, true) | |
}; | |
} | |
detached() { | |
this.element = null; | |
this.viewModel = null; | |
this.model = null; | |
} | |
} |
This file contains hidden or 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://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script> | |
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script> | |
<script> | |
System.import('aurelia-bootstrapper'); | |
</script> | |
</body> | |
</html> |
This file contains hidden or 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> | |
<h1>${message}</h1> | |
</template> |
This file contains hidden or 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
export class Test { | |
message = "hello World"; | |
constructor(){ | |
console.log("new test"); | |
} | |
activate() { | |
console.log("new test activated"); | |
this.message = this.message + " ...I was activated"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment