Created
September 9, 2016 14:10
-
-
Save martonsagi/fea4069d8a4361c4802c7c5d42105145 to your computer and use it in GitHub Desktop.
Global attach() handler for viewmodels
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> | |
<require from="./extended-view"></require> | |
<div class="container-fluid"> | |
<h4 class="page-header">Global attach() handler for viewmodels </h4> | |
<ul class="list-group"> | |
<li class="list-group-item"> | |
<compose view-model="./extended-view"></compose> | |
</li> | |
<li class="list-group-item"> | |
<extended-view></extended-view> | |
</li> | |
</ul> | |
</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 { | |
} |
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
import { inject } from 'aurelia-framework'; | |
@inject(Element) | |
export class BaseView { | |
constructor(element) { | |
this.element = element; | |
this.timeout = Math.floor((Math.random() * 5) + 1); | |
} | |
attached() { | |
this.baseMessage = `BaseView::attaching in ${this.timeout}s`; | |
setTimeout(_ => { | |
let elems = this.element.querySelectorAll('input'); | |
for (let item of elems) { | |
item.type = "number"; | |
} | |
this.baseMessage = "BaseView::attached"; | |
}, this.timeout * 1000); | |
} | |
} |
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> | |
<div>${baseMessage}</div> | |
<div>${extendedMessage}</div> | |
<input type="text" value="1" class="form-control" /> | |
<input type="text" value="2" class="form-control" /> | |
</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
import { BaseView } from './base-view'; | |
import { inject } from 'aurelia-framework'; | |
@inject(Element) | |
export class ExtendedView extends BaseView { | |
constructor(element) { | |
super(element); | |
} | |
attached() { | |
super.attached(); | |
this.extendedMessage = "ExtendedView::attached"; | |
} | |
} |
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"> | |
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> | |
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous"> | |
</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