Skip to content

Instantly share code, notes, and snippets.

@alexander-alvarez
Created March 7, 2017 21:27
Show Gist options
  • Save alexander-alvarez/8cc6e00930c41e7b1bb7f3be92c4699a to your computer and use it in GitHub Desktop.
Save alexander-alvarez/8cc6e00930c41e7b1bb7f3be92c4699a to your computer and use it in GitHub Desktop.
cancel typeahead
import Ember from 'ember';
import {task, timeout} from 'ember-concurrency';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
typeAheadTask: task(function * (value) {
yield timeout(500);
return value
}), // you can cancel or whatever you like
actions: {
startTask(value){
this.get('typeAheadTask').perform(value);
this.set('value', value);
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
{{one-way-input value update=(action 'startTask')}}
<br>
results:
<br>
{{#if (and typeAheadTask.isRunning (not typeAheadTask.isIdle))}}
searching
{{else}}
{{typeAheadTask.last.value}}
{{/if}}
<br>
<br>
{
"version": "0.11.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.11.0",
"ember-data": "2.11.0",
"ember-template-compiler": "2.11.0",
"ember-testing": "2.11.0"
},
"addons": {
"ember-one-way-controls": "*",
"ember-truth-helpers": "*",
"ember-concurrency": "*"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment