From 3eab1e428ebe3ce2ddf1013d48693bc38e23c150 Mon Sep 17 00:00:00 2001 From: Dmitriy Shekhovtsov Date: Wed, 16 Sep 2015 11:33:28 +0300 Subject: [PATCH] feat(typeahead): ts style fixes --- components/typeahead/typeahead.ts | 11 ++++++----- demo/components/typeahead/typeahead-demo.ts | 15 ++++++--------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/components/typeahead/typeahead.ts b/components/typeahead/typeahead.ts index 07a4f1ab69..0233aacdc6 100644 --- a/components/typeahead/typeahead.ts +++ b/components/typeahead/typeahead.ts @@ -224,13 +224,13 @@ export class Typeahead { private debounce(func:Function, wait:number):Function { let timeout:any; let args:Array; - let timestamp:Date; + let timestamp:number; let waitOriginal:number = wait; return function () { // save details of latest call args = [].slice.call(arguments, 0); - timestamp = new Date(); + timestamp = Date.now(); // this trick is about implementing of 'typeaheadWaitMs' // in this case we have adaptive 'wait' parameter @@ -242,7 +242,7 @@ export class Typeahead { let later = function () { // how long ago was the last call - let last = (new Date()) - timestamp; + let last = Date.now() - timestamp; // if the latest call was less that the wait period ago // then we reset the timeout to wait for the difference @@ -400,8 +400,9 @@ export class Typeahead { } show(matches:Array) { - let options:TypeaheadOptions = new TypeaheadOptions({ - placement: this.placement + let options = new TypeaheadOptions({ + placement: this.placement, + animation: false }); let binding = Injector.resolve([ diff --git a/demo/components/typeahead/typeahead-demo.ts b/demo/components/typeahead/typeahead-demo.ts index 64518e3449..70064339f4 100644 --- a/demo/components/typeahead/typeahead-demo.ts +++ b/demo/components/typeahead/typeahead-demo.ts @@ -50,16 +50,13 @@ export class TypeaheadDemo { } private getAsyncData(context:any):Function { - let f:Function = function ():Promise { - let p:Promise = new Promise((resolve:Function) => { + let f:Function = function ():Promise { + let p:Promise = new Promise((resolve:Function) => { setTimeout(() => { - let matches:Array = []; - for (let i = 0; i < context.states.length; i++) { - if (context.states[i].toLowerCase().indexOf(context.asyncSelected.toLowerCase()) >= 0) { - matches.push(context.states[i]); - } - } - resolve(matches); + let query = new RegExp(context.asyncSelected, 'ig'); + return resolve(context.states.filter((state) => { + return query.test(state); + })); }, 200); }); return p;