Last active
June 30, 2021 19:41
-
-
Save Seebiscuit/7d6ba7fdb9457badebad6a83ea70be83 to your computer and use it in GitHub Desktop.
Child takes over props
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> | |
<meta charset="utf-8"> | |
<title>Dumber Gist</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no"> | |
<base href="/"> | |
</head> | |
<!-- | |
Dumber gist uses dumber bundler, the default bundle file | |
is /dist/entry-bundle.js. | |
The starting module is pointed to aurelia-bootstrapper | |
(data-main attribute on script) for Aurelia, | |
The aurelia bootstrapper then loads up user module "main" | |
(aurelia-app attribute on <body>) which is your src/main.js. | |
--> | |
<body aurelia-app="main"> | |
<script src="/dist/entry-bundle.js" data-main="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
{ | |
"dependencies": { | |
"aurelia-bootstrapper": "^2.3.3" | |
} | |
} |
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="./child"></require> | |
<h2> | |
Uncontrolled | |
</h2> | |
<child | |
child-prop.bind="childPropUncontrolled" | |
on-click-child.bind="onClickChild" | |
>Uncontrolled</child> | |
<h2> | |
Controlled | |
</h2> | |
<child | |
child-prop.bind="childPropControlled" | |
on-click-child.bind="onClickChild" | |
should-control.bind="false" | |
>Controlled</child> | |
</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 App { | |
childPropUncontrolled = "Initial Parent Uncontrolled" | |
childPropControlled = "Initial Parent Controlled" | |
count = 0 | |
onClickChild = () => { | |
this.count++ | |
let count = this.count % 2 ? this.count : this.count - 1; | |
this.childPropControlled = "Parent Setting Controlled " + count | |
this.childPropUncontrolled = "Parent setting Uncontrolled " + count | |
console.log("Parent updated childPropA with", this.childPropA) | |
} | |
} |
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> | |
<p>${childProp}</p> | |
<button click.delegate="onClick()">Click <slot></slot></button> | |
</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 { bindable } from "aurelia-framework" | |
export class Child { | |
@bindable childProp | |
@bindable onClickChild | |
@bindable shouldControl = true | |
count = 0 | |
bind() { | |
this.childProp = "Chaning childProp in bind()" | |
} | |
onClick() { | |
if (this.shouldControl) { | |
this.childProp = "Child Setting propA" | |
console.log("Child is setting propA") | |
} else { | |
this.onClickChild() | |
console.log("Child invoked parent prop method") | |
} | |
} | |
} |
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 function configure(aurelia) { | |
aurelia.use | |
.standardConfiguration() | |
.developmentLogging('info'); | |
aurelia.start().then(() => aurelia.setRoot()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment