Skip to content

Commit

Permalink
feat(typeahead): ts style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
valorkin committed Sep 16, 2015
1 parent 4a6b3e6 commit 3eab1e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
11 changes: 6 additions & 5 deletions components/typeahead/typeahead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ export class Typeahead {
private debounce(func:Function, wait:number):Function {
let timeout:any;
let args:Array<any>;
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
Expand All @@ -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
Expand Down Expand Up @@ -400,8 +400,9 @@ export class Typeahead {
}

show(matches:Array<string>) {
let options:TypeaheadOptions = new TypeaheadOptions({
placement: this.placement
let options = new TypeaheadOptions({
placement: this.placement,
animation: false
});

let binding = Injector.resolve([
Expand Down
15 changes: 6 additions & 9 deletions demo/components/typeahead/typeahead-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]> {
let p:Promise<string[]> = new Promise((resolve:Function) => {
setTimeout(() => {
let matches:Array<any> = [];
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;
Expand Down

0 comments on commit 3eab1e4

Please sign in to comment.