Last active
May 6, 2016 12:18
-
-
Save Thanood/9cc04c97426b7803410709d93522073f to your computer and use it in GitHub Desktop.
Aurelia - filter large list
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-icon"></require> | |
<require from="./my-list.html"></require> | |
<require from="./my-list-item.html"></require> | |
<div> | |
<input type="text" value.bind="term" placeholder="filter" /> | |
<button click.delegate="addSome()">add some</button> | |
</div> | |
<!--<div> | |
<div repeat.for="item of filteredData" data-id.bind="item.id"> | |
<span my-icon>person</span> | |
<span>${item.title}</span> | |
<span text.bind="item.id"></span> | |
</div> | |
</div>--> | |
<my-list> | |
<my-list-item repeat.for="item of filteredData" data-id.bind="item.id"> | |
<span my-icon>person</span> | |
<span>${item.title}</span> | |
<span text.bind="item.id"></span> | |
</my-list-item> | |
</my-list> | |
</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, inject} from 'aurelia-framework'; | |
export class App { | |
data = []; | |
filteredData = []; | |
@bindable() term = ''; | |
constructor() { | |
for (let i=0; i<20; i++) { | |
this.data.push({ id: i, title: `item ${i+1}` }); | |
} | |
this.filteredData = this.data.filter(i => true); | |
} | |
termChanged(newValue) { | |
let rex = new RegExp(newValue, 'ig'); | |
this.filteredData = this.data.filter(i => rex.test(i.title)); | |
} | |
addSome() { | |
let from = this.data.length + 0; | |
let to = from + 20; | |
for (let i = from; i < to; i++) { | |
this.data.push({ id: i, title: `item ${i+1}` }) | |
} | |
let rex = new RegExp(this.term, 'ig'); | |
this.filteredData = this.data.filter(i => rex.test(i.title)); | |
} | |
} |
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 IconService { | |
registeredSources = {}; | |
constructor() { | |
this.registeredSources['material-icons'] = { | |
css: () => 'material-icons', | |
html: icon => 'person' | |
}; | |
} | |
getIcon(source, icon) { | |
let provider = this.registeredSources[source]; | |
if (provider) { | |
return { | |
css: provider.css(icon), | |
html: provider.html(icon) | |
} | |
} else { | |
return null; | |
} | |
} | |
registerSource(key, config) { | |
this.registeredSources[key] = config; | |
} | |
} |
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> | |
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" /> | |
<link rel="stylesheet" href="styles.css"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body aurelia-app="main"> | |
<h1>Loading...</h1> | |
<script src="https://cdn.rawgit.com/jdanyow/aurelia-plunker/v0.11.10/jspm_packages/system.js"></script> | |
<script src="https://cdn.rawgit.com/jdanyow/aurelia-plunker/v0.11.10/config2.js"></script> | |
<script> | |
System.import('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
/******************************************************************************* | |
* The following two lines enable async/await without using babel's | |
* "runtime" transformer. Uncomment the lines if you intend to use async/await. | |
* | |
* More info here: https://github.com/jdanyow/aurelia-plunker/issues/2 | |
*/ | |
//import regeneratorRuntime from 'babel-runtime/regenerator'; | |
//window.regeneratorRuntime = regeneratorRuntime; | |
/******************************************************************************/ | |
export function configure(aurelia) { | |
aurelia.use | |
.standardConfiguration() | |
.developmentLogging(); | |
aurelia.start().then(a => a.setRoot()); | |
} |
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, inject} from 'aurelia-framework'; | |
import {IconService} from './icon-service'; | |
@inject(Element, IconService) | |
export class MyIconCustomAttribute { | |
@bindable() source = 'material-icons'; | |
_originalContent; | |
constructor(element, iconService) { | |
this.element = element; | |
this.iconService = iconService; | |
} | |
attached() { | |
/* | |
this.element.classList.add('material-icons'); | |
if (this.icon) { | |
this.element.innerHTML = this.icon; | |
} | |
*/ | |
let icon = this.iconService.getIcon(this.source, this.element.innerText); | |
if (icon) { | |
if (icon.css) { | |
this.element.classList.add(icon.css); | |
} | |
if (icon.html) { | |
this._originalContent = this.element.innerHTML; | |
this.element.innerHTML = icon.html; | |
} | |
} | |
} | |
detached() { | |
if (this._originalContent) { | |
this.element.innerHTML = this._originalContent; | |
} | |
} | |
} |
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 style="display: block;"> | |
<content></content> | |
</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
<template> | |
<content select="my-list-item"></content> | |
</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
/* Styles go here */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment