Last active
October 20, 2016 12:06
-
-
Save RichTeaTime/f786c93f86ba8b22a323bfe50e176210 to your computer and use it in GitHub Desktop.
Aurelia Gist - using @Inject(NewInstance) does not work correctly with container.registerInstance
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="component"></require> | |
<div>expected: <span innerHTML.bind="mocktext"></span></div> | |
<div>actual: <component></component></div> | |
</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 {Container} from 'aurelia-framework' | |
import {BaseClass} from 'base-class' | |
import {MockClass} from 'mock-class' | |
export class App { | |
static inject = [Container]; | |
mocktext = ""; | |
constructor(container:Container) | |
{ | |
this.mocktext = new MockClass().text; | |
container.registerHandler(BaseClass, c => new MockClass()); | |
} | |
} |
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 BaseClass | |
{ | |
text = "<font color='red'>base class</red>"; | |
} |
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> | |
<span innerHTML.bind="message"></span> | |
</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 {BaseClass} from 'base-class' | |
import {NewInstance} from 'aurelia-framework' | |
export class Component | |
{ | |
messsage = ""; | |
static inject = [NewInstance.of(BaseClass)]; | |
constructor(baseInstance) | |
{ | |
this.message = baseInstance.text; | |
} | |
} |
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://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> |
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 {BaseClass} from 'base-class'; | |
export class MockClass extends BaseClass | |
{ | |
constructor() { | |
super(); | |
this.text = "<font color='green'>mock class</font>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment