Skip to content

Instantly share code, notes, and snippets.

@jdanyow
Last active March 6, 2016 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jdanyow/14271b1559e73f1da745 to your computer and use it in GitHub Desktop.
Save jdanyow/14271b1559e73f1da745 to your computer and use it in GitHub Desktop.
Aurelia - Search Input
<template>
<require from="./search"></require>
<search execute.call="doSearch(query)" delay.bind="400"></search>
<ul>
<li repeat.for="query of queries">${query}</li>
</ul>
</template>
export class App {
queries = [];
doSearch(query) {
this.queries.splice(0, 0, query);
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<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-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>
/*******************************************************************************
* 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());
}
<template>
<form submit.delegate="executeSearch()">
<input type="text" value.bind="query">
<button type="submit">Search</button>
</form>
</template>
import {bindable} from 'aurelia-framework';
export class Search {
@bindable execute;
@bindable delay;
timeoutHandle;
executeSearch() {
clearTimeout(this.timeoutHandle);
this.execute({ query: this.query });
}
_query = '';
get query() {
return this._query;
}
set query(newValue) {
this._query = newValue;
clearTimeout(this.timeoutHandle);
this.timeoutHandle = setTimeout(() => this.executeSearch(), this.delay);
}
}
/* Styles go here */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment