Skip to content

Instantly share code, notes, and snippets.

@djedi
Last active February 2, 2018 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djedi/b664d5f12c8257cf5aa6c8fc17c4503e to your computer and use it in GitHub Desktop.
Save djedi/b664d5f12c8257cf5aa6c8fc17c4503e to your computer and use it in GitHub Desktop.
shared class
<template>
<require from="./componentA"></require>
<require from="./componentB"></require>
<component-a>
<component-b>Click Here</component-b>
</component-a>
</template>
export class App {
}
<template>
<h3>${sharedClass.sharedVal ? 'True' : 'False'}</h3>
<ul><slot></slot></ul>
</template>
import {inject} from 'aurelia-framework';
import {SharedClass} from 'sharedClass';
@inject(SharedClass)
export class componentA {
constructor(sharedClass) {
this.sharedClass = sharedClass;
}
}
<template>
<li>
<a click.delegate="stuffClick()"><slot></slot></a>
</li>
</template>
import {inject} from 'aurelia-framework';
import {SharedClass} from 'sharedClass';
@inject(SharedClass)
export class componentB {
constructor(sharedClass) {
this.sharedClass = sharedClass;
}
stuffClick() {
this.sharedClass.sharedVal = !this.sharedClass.sharedVal;
}
}
<!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>
export class SharedClass {
sharedVal = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment