Created
September 23, 2016 17:08
-
-
Save jpray/339f2f83e2bff67ee5cd925e411fa39b to your computer and use it in GitHub Desktop.
Aurelia RequireJS Gist
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='./my-element'></require> | |
| <my-element some-boolean.bind="someBoolean"></my-element> | |
| </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 { | |
| attached() { | |
| setInterval(function(){ | |
| this.someBoolean = !this.someBoolean; | |
| }.bind(this),2000); | |
| } | |
| } |
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
| <template> | |
| <require from="./my-other-element"></require> | |
| <h3>My Element</h3> | |
| <p>My Other Element will flash below as I try to | |
| destroy and recreate the element. | |
| Ideally the number of times each lifecycle event fires should be the same. </p> | |
| <template if.bind="someBoolean"> | |
| <my-other-element></my-other-element> | |
| </template> | |
| </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 MyElement { | |
| @bindable | |
| someBoolean | |
| constructor(){ | |
| //this is just a simple example to help talk | |
| //about how to destroy/recreate a view/view-model pair | |
| } | |
| someBooleanChanged(){ | |
| //here I would like to make sure that my-other-element | |
| //is destroyed and recreated, but its hard :( | |
| } | |
| } |
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> | |
| <h5>My Other Element</h5> | |
| <ul> | |
| <li># times constructed: ${state.numTimesConstructed}</li> | |
| <li># times created: ${state.numTimesCreated}</li> | |
| <li># times bound: ${state.numTimesBound}</li> | |
| <li># times attached: ${state.numTimesAttached}</li> | |
| <li># times detached: ${state.numTimesDetached}</li> | |
| <li># times unbound: ${state.numTimesUnbound}</li> | |
| </ul> | |
| </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 {transient} from 'aurelia-framework'; | |
| var state = { | |
| numTimesConstructed: 0, | |
| numTimesCreated: 0, | |
| numTimesBound: 0, | |
| numTimesAttached: 0, | |
| numTimesDetached: 0, | |
| numTimesUnbound: 0 | |
| }; | |
| @transient() | |
| export class MyOtherElement { | |
| constructor(){ | |
| this.state = state; | |
| this.state.numTimesConstructed++; | |
| } | |
| created(){ this.state.numTimesCreated++; } | |
| bind(){ this.state.numTimesBound++; } | |
| attached(){ this.state.numTimesAttached++; } | |
| detached(){ this.state.numTimesDetached++; } | |
| unbind(){ this.state.numTimesUnbound++; } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment