Skip to content

Instantly share code, notes, and snippets.

@evenflow58
Last active February 6, 2018 08:08
Show Gist options
  • Save evenflow58/a52a0c17d0f7bae22b9ea1987ddc5583 to your computer and use it in GitHub Desktop.
Save evenflow58/a52a0c17d0f7bae22b9ea1987ddc5583 to your computer and use it in GitHub Desktop.
DI inheritance
<template>
<require from="./baseGrid"></require>
<require from="./grid"></require>
<!-- Works as expected -->
<base-grid></base-grid>
--------------------------------------------
<!-- Works as expected -->
<grid></grid>
--------------------------------------------
<!-- Does not resolve because the templating engine extracts out the body template -->
<grid>
<template replace-part="body">
<tr repeat.for="datum of data">
<td>
app: ${datum}
</td>
</tr>
</template>
</grid>
--------------------------------------------
<!-- This resolves the problem but is a bad approach -->
<base-grid>
<template replace-part="table">
<table>
<tbody>
<tr repeat.for="datum of data">
<td>
bad-app: ${datum}
</td>
</tr>
</tbody>
</table>
</template>
</base-grid>
</template>
export class App { message = 'Hello World'; }
<template>
<template replaceable part="table">
<table>
<tr repeat.for="datum of data">
<td>${datum}</td>
</tr>
</table>
</template>
</template>
export class BaseGrid {
data = 'This is the base grid'.split(' ');
}
import {inject} from 'aurelia-dependency-injection'
export class Action1Dependency {}
export class Action2Dependency {}
export class ActionBase{
}
@inject(Action1Dependency)
export class Action1 extends ActionBase{
constructor(dep){
super();
this.dep = dep;
}
}
@inject(Action2Dependency)
export class Action2 extends ActionBase{
constructor(dep){
super();
this.dep = dep;
}
}
<template>
<require from="./baseGrid"></require>
<base-grid>
<template replace-part="table">
<table>
<tbody>
<template replaceable part="body">
<tr repeat.for="datum of data">
<td>
grid: ${datum}
</td>
</tr>
</template>
</tbody>
</table>
</template>
</base-grid>
</template>
export class Grid { }
<!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