Skip to content

Commit

Permalink
compileable
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Dec 8, 2018
1 parent 24fa3e8 commit 3152634
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
20 changes: 0 additions & 20 deletions src/internal/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,6 @@ function quantile(values: Float32Array, quantile: number) {
return v + (vAfter - v) * (target - index); // shift by change
}

/**
* cache the value in a hidden __ variable
* @internal
*/
function cached() {
return function (_target: any, propertyKey: string, descriptor: PropertyDescriptor) {
const getter = descriptor.get!;
const cacheKey = `__${propertyKey}`;
descriptor.get = function (this: any) {
if (this.hasOwnProperty(cacheKey)) {
return this[cacheKey];
}
const value = getter.call(this);
this[cacheKey] = value;
return value;
};
return descriptor;
};
}

export function computeBoxPlot(arr: ISequence<IForEachAble<number> | number>): IAdvancedBoxPlotData {
// filter out NaN
let min = Number.POSITIVE_INFINITY;
Expand Down
24 changes: 20 additions & 4 deletions src/internal/scheduler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {IAbortAblePromise, ABORTED} from 'lineupengine';
import {IAbortAblePromise, ABORTED, IAbortAblePromiseBase} from 'lineupengine';
export {IAbortAblePromise, ABORTED} from 'lineupengine';

export interface IPoorManIdleDeadline {
Expand All @@ -19,6 +19,18 @@ export interface ITask<T> {
result: PromiseLike<T | symbol>;
}

function thenFactory<T>(wrappee: PromiseLike<T>, abort: () => void) {
function then<TResult1 = T | symbol, TResult2 = never>(onfulfilled?: ((value: T | symbol) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): IAbortAblePromiseBase<TResult1 | TResult2> {
const r = wrappee.then(onfulfilled, onrejected);
return {
then: <any>thenFactory(r, abort),
abort
};
}
return then;
}


export default class TaskScheduler {
private tasks: ITask<any>[] = [];
private taskId: number = -1;
Expand Down Expand Up @@ -53,7 +65,7 @@ export default class TaskScheduler {

abort(); // abort existing with same id

const p = new Promise<T>((resolve) => {
const p = new Promise<T | symbol>((resolve) => {
this.tasks.push({
id,
calc,
Expand All @@ -72,8 +84,12 @@ export default class TaskScheduler {
this.taskId = self.setTimeout(this.runTasks, 1);
}
});
(<any>p).abort = abort;
return <IAbortAblePromise<T>>p;


return {
then: thenFactory(p, abort),
abort
};
}

abort(id: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/ANumbersCellRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {INumbersColumn, EAdvancedSortMethod} from '../model/INumberColumn';
import {default as IRenderContext, IImposer} from './interfaces';
import {renderMissingCanvas, renderMissingDOM} from './missing';
import {ISequence} from '../internal/interable';
import {computeBoxPlot, IAdvancedBoxPlotData} from '../internal';
import {computeBoxPlot} from '../internal';

/** @internal */
export abstract class ANumbersCellRenderer {
Expand Down

0 comments on commit 3152634

Please sign in to comment.