Last active
March 11, 2020 16:51
-
-
Save davismj/d8eef3781a2e6cb64cee714be81942a6 to your computer and use it in GitHub Desktop.
dynamic compose vm api
This file contains 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> | |
<!-- static fields --> | |
<div>vm1</div> | |
<select value.bind="vm1"> | |
<option>thingA</option> | |
<option>thingB</option> | |
</select> | |
<div>vm2</div> | |
<select value.bind="vm2"> | |
<option>thingA</option> | |
<option>thingB</option> | |
</select> | |
<div>value a</div> | |
<div> | |
<input /> | |
</div> | |
<div>value b</div> | |
<div> | |
<input /> | |
</div> | |
<!-- dynamic fields --> | |
<div element.ref="$dynamicFieldsElement"> | |
<div> | |
<compose view-model.bind="vm1" view-model.ref="vms"></compose> | |
</div> | |
<div> | |
<compose view-model.bind="vm2" view-model.ref="vms"></compose> | |
</div> | |
</div> | |
<div> | |
<button click.delegate="reset()">do the thing</button> | |
</div> | |
</template> |
This file contains 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 { | |
vm1 = 'thingA'; | |
vm2 = 'thingB'; | |
vms = [] | |
reset() { | |
const controls = this.$dynamicFieldsElement.querySelectorAll('compose'); | |
for (let { au: { compose: { viewModel: { currentViewModel } } } } of controls) { | |
currentViewModel.doThings(); | |
} | |
} | |
} |
This file contains 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 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> | |
thing a says ${message} | |
</template> |
This file contains 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 ThingViewModel { | |
message = 'hey'; | |
doThings() { | |
this.message = [this.message, this.message].join(' ') | |
} | |
} |
This file contains 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> | |
thing b | |
</template> |
This file contains 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 ThingBViewModel { | |
doThings() { | |
alert('totally dynamic bro'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment