[ember__runloop] Adding backburner types to -private subdirectory

This commit is contained in:
Steve Calvert
2019-02-11 10:44:25 -08:00
committed by Mike North
parent 1ce60bdc07
commit 5749616efe
4 changed files with 362 additions and 306 deletions

View File

@@ -0,0 +1,37 @@
export interface QueueItem {
method: string;
target: object;
args: object[];
stack: string | undefined;
}
export interface DeferredActionQueues {
[index: string]: any;
queues: object;
schedule(
queueName: string,
target: any,
method: any,
args: any,
onceFlag: boolean,
stack: any
): any;
flush(fromAutorun: boolean): any;
}
export interface DebugInfo {
autorun: Error | undefined | null;
counters: object;
timers: QueueItem[];
instanceStack: DeferredActionQueues[];
}
export interface Backburner {
join(...args: any[]): void;
on(...args: any[]): void;
scheduleOnce(...args: any[]): void;
schedule(queueName: string, target: object | null, method: () => void | string): void;
ensureInstance(): void;
DEBUG: boolean;
getDebugInfo(): DebugInfo;
}

View File

@@ -1,9 +1,19 @@
import { run } from '@ember/runloop';
import EmberObject from '@ember/object';
import { Backburner, DebugInfo, QueueItem, DeferredActionQueues } from '@ember/runloop/-private/backburner';
run; // $ExpectType RunNamespace
run.queues; // $ExpectType EmberRunQueues[]
const queues: string[] = run.queues;
// It will be the responsibility of each consuming package that needs access to the backburner property
// to merge the private types in the public API.
declare module '@ember/runloop' {
interface RunNamespace {
backburner: Backburner;
}
}
function testRun() {
run(() => { // $ExpectType number
// code to be executed within a RunLoop
@@ -198,3 +208,9 @@ function testThrottle() {
run.throttle(runIt, 150);
run.throttle(myContext, runIt, 150);
}
function testBackburner() {
const debugInfo: DebugInfo = run.backburner.getDebugInfo();
const queueItems: QueueItem[] = debugInfo.timers;
const deferredActionQueues: DeferredActionQueues[] = debugInfo.instanceStack;
}

View File

@@ -1,320 +1,322 @@
// Type definitions for non-npm package @ember/runloop 3.0
// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Frunloop
// Definitions by: Mike North <https://github.com/mike-north>
// Steve Calvert <https://github.com/scalvert>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import { RunMethod, EmberRunQueues } from "@ember/runloop/-private/types";
import { EmberRunTimer } from "@ember/runloop/types";
import '@ember/runloop/-private/backburner';
// tslint:disable-next-line:strict-export-declare-modifiers
export const run: {
/**
* Runs the passed target and method inside of a RunLoop, ensuring any
* deferred actions including bindings and views updates are flushed at the
* end.
*/
<Ret>(method: (...args: any[]) => Ret): Ret;
<Target, Ret>(target: Target, method: RunMethod<Target, Ret>): Ret;
/**
* If no run-loop is present, it creates a new one. If a run loop is
* present it will queue itself to run on the existing run-loops action
* queue.
*/
join<Ret>(method: (...args: any[]) => Ret, ...args: any[]): Ret | undefined;
join<Target, Ret>(
target: Target,
method: RunMethod<Target, Ret>,
...args: any[]
): Ret | undefined;
/**
* Allows you to specify which context to call the specified function in while
* adding the execution of that function to the Ember run loop. This ability
* makes this method a great way to asynchronously integrate third-party libraries
* into your Ember application.
*/
bind<Target, Ret>(
target: Target,
method: RunMethod<Target, Ret>,
...args: any[]
): (...args: any[]) => Ret;
/**
* Begins a new RunLoop. Any deferred actions invoked after the begin will
* be buffered until you invoke a matching call to `run.end()`. This is
* a lower-level way to use a RunLoop instead of using `run()`.
*/
begin(): void;
/**
* Ends a RunLoop. This must be called sometime after you call
* `run.begin()` to flush any deferred actions. This is a lower-level way
* to use a RunLoop instead of using `run()`.
*/
end(): void;
/**
* Adds the passed target/method and any optional arguments to the named
* queue to be executed at the end of the RunLoop. If you have not already
* started a RunLoop when calling this method one will be started for you
* automatically.
*/
schedule<Target>(
queue: EmberRunQueues,
target: Target,
method: RunMethod<Target>,
...args: any[]
): EmberRunTimer;
schedule(
queue: EmberRunQueues,
method: (args: any[]) => any,
...args: any[]
): EmberRunTimer;
/**
* Invokes the passed target/method and optional arguments after a specified
* period of time. The last parameter of this method must always be a number
* of milliseconds.
*/
later(method: (...args: any[]) => any, wait: number): EmberRunTimer;
later<Target>(
target: Target,
method: RunMethod<Target>,
wait: number
): EmberRunTimer;
later<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
wait: number
): EmberRunTimer;
later<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
wait: number
): EmberRunTimer;
later<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
wait: number
): EmberRunTimer;
later<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
arg3: any,
wait: number
): EmberRunTimer;
later<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
arg3: any,
arg4: any,
wait: number
): EmberRunTimer;
later<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
arg3: any,
arg4: any,
arg5: any,
wait: number
): EmberRunTimer;
/**
* Schedule a function to run one time during the current RunLoop. This is equivalent
* to calling `scheduleOnce` with the "actions" queue.
*/
once<Target>(
target: Target,
method: RunMethod<Target>,
...args: any[]
): EmberRunTimer;
/**
* Schedules a function to run one time in a given queue of the current RunLoop.
* Calling this method with the same queue/target/method combination will have
* no effect (past the initial call).
*/
scheduleOnce<Target>(
queue: EmberRunQueues,
target: Target,
method: RunMethod<Target>,
...args: any[]
): EmberRunTimer;
/**
* Schedules an item to run from within a separate run loop, after
* control has been returned to the system. This is equivalent to calling
* `run.later` with a wait time of 1ms.
*/
next<Target>(
target: Target,
method: RunMethod<Target>,
...args: any[]
): EmberRunTimer;
/**
* Cancels a scheduled item. Must be a value returned by `run.later()`,
* `run.once()`, `run.scheduleOnce()`, `run.next()`, `run.debounce()`, or
* `run.throttle()`.
*/
cancel(timer: EmberRunTimer): boolean;
/**
* Delay calling the target method until the debounce period has elapsed
* with no additional debounce calls. If `debounce` is called again before
* the specified time has elapsed, the timer is reset and the entire period
* must pass again before the target method is called.
*/
debounce(
method: (...args: any[]) => any,
wait: number,
immediate?: boolean
): EmberRunTimer;
debounce<Target>(
target: Target,
method: RunMethod<Target>,
wait: number,
immediate?: boolean
): EmberRunTimer;
debounce<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
wait: number,
immediate?: boolean
): EmberRunTimer;
debounce<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
wait: number,
immediate?: boolean
): EmberRunTimer;
debounce<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
wait: number,
immediate?: boolean
): EmberRunTimer;
debounce<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
arg3: any,
wait: number,
immediate?: boolean
): EmberRunTimer;
debounce<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
arg3: any,
arg4: any,
wait: number,
immediate?: boolean
): EmberRunTimer;
debounce<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
arg3: any,
arg4: any,
arg5: any,
wait: number,
immediate?: boolean
): EmberRunTimer;
/**
* Ensure that the target method is never called more frequently than
* the specified spacing period. The target method is called immediately.
*/
throttle(
method: (...args: any[]) => any,
spacing: number,
immediate?: boolean
): EmberRunTimer;
throttle<Target>(
target: Target,
method: RunMethod<Target>,
spacing: number,
immediate?: boolean
): EmberRunTimer;
throttle<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
spacing: number,
immediate?: boolean
): EmberRunTimer;
throttle<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
spacing: number,
immediate?: boolean
): EmberRunTimer;
throttle<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
spacing: number,
immediate?: boolean
): EmberRunTimer;
throttle<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
arg3: any,
spacing: number,
immediate?: boolean
): EmberRunTimer;
throttle<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
arg3: any,
arg4: any,
spacing: number,
immediate?: boolean
): EmberRunTimer;
throttle<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
arg3: any,
arg4: any,
arg5: any,
spacing: number,
immediate?: boolean
): EmberRunTimer;
export interface RunNamespace {
/**
* Runs the passed target and method inside of a RunLoop, ensuring any
* deferred actions including bindings and views updates are flushed at the
* end.
*/
<Ret>(method: (...args: any[]) => Ret): Ret;
<Target, Ret>(target: Target, method: RunMethod<Target, Ret>): Ret;
/**
* If no run-loop is present, it creates a new one. If a run loop is
* present it will queue itself to run on the existing run-loops action
* queue.
*/
join<Ret>(method: (...args: any[]) => Ret, ...args: any[]): Ret | undefined;
join<Target, Ret>(
target: Target,
method: RunMethod<Target, Ret>,
...args: any[]
): Ret | undefined;
/**
* Allows you to specify which context to call the specified function in while
* adding the execution of that function to the Ember run loop. This ability
* makes this method a great way to asynchronously integrate third-party libraries
* into your Ember application.
*/
bind<Target, Ret>(
target: Target,
method: RunMethod<Target, Ret>,
...args: any[]
): (...args: any[]) => Ret;
/**
* Begins a new RunLoop. Any deferred actions invoked after the begin will
* be buffered until you invoke a matching call to `run.end()`. This is
* a lower-level way to use a RunLoop instead of using `run()`.
*/
begin(): void;
/**
* Ends a RunLoop. This must be called sometime after you call
* `run.begin()` to flush any deferred actions. This is a lower-level way
* to use a RunLoop instead of using `run()`.
*/
end(): void;
/**
* Adds the passed target/method and any optional arguments to the named
* queue to be executed at the end of the RunLoop. If you have not already
* started a RunLoop when calling this method one will be started for you
* automatically.
*/
schedule<Target>(
queue: EmberRunQueues,
target: Target,
method: RunMethod<Target>,
...args: any[]
): EmberRunTimer;
schedule(
queue: EmberRunQueues,
method: (args: any[]) => any,
...args: any[]
): EmberRunTimer;
/**
* Invokes the passed target/method and optional arguments after a specified
* period of time. The last parameter of this method must always be a number
* of milliseconds.
*/
later(method: (...args: any[]) => any, wait: number): EmberRunTimer;
later<Target>(
target: Target,
method: RunMethod<Target>,
wait: number
): EmberRunTimer;
later<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
wait: number
): EmberRunTimer;
later<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
wait: number
): EmberRunTimer;
later<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
wait: number
): EmberRunTimer;
later<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
arg3: any,
wait: number
): EmberRunTimer;
later<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
arg3: any,
arg4: any,
wait: number
): EmberRunTimer;
later<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
arg3: any,
arg4: any,
arg5: any,
wait: number
): EmberRunTimer;
/**
* Schedule a function to run one time during the current RunLoop. This is equivalent
* to calling `scheduleOnce` with the "actions" queue.
*/
once<Target>(
target: Target,
method: RunMethod<Target>,
...args: any[]
): EmberRunTimer;
/**
* Schedules a function to run one time in a given queue of the current RunLoop.
* Calling this method with the same queue/target/method combination will have
* no effect (past the initial call).
*/
scheduleOnce<Target>(
queue: EmberRunQueues,
target: Target,
method: RunMethod<Target>,
...args: any[]
): EmberRunTimer;
/**
* Schedules an item to run from within a separate run loop, after
* control has been returned to the system. This is equivalent to calling
* `run.later` with a wait time of 1ms.
*/
next<Target>(
target: Target,
method: RunMethod<Target>,
...args: any[]
): EmberRunTimer;
/**
* Cancels a scheduled item. Must be a value returned by `run.later()`,
* `run.once()`, `run.scheduleOnce()`, `run.next()`, `run.debounce()`, or
* `run.throttle()`.
*/
cancel(timer: EmberRunTimer): boolean;
/**
* Delay calling the target method until the debounce period has elapsed
* with no additional debounce calls. If `debounce` is called again before
* the specified time has elapsed, the timer is reset and the entire period
* must pass again before the target method is called.
*/
debounce(
method: (...args: any[]) => any,
wait: number,
immediate?: boolean
): EmberRunTimer;
debounce<Target>(
target: Target,
method: RunMethod<Target>,
wait: number,
immediate?: boolean
): EmberRunTimer;
debounce<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
wait: number,
immediate?: boolean
): EmberRunTimer;
debounce<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
wait: number,
immediate?: boolean
): EmberRunTimer;
debounce<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
wait: number,
immediate?: boolean
): EmberRunTimer;
debounce<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
arg3: any,
wait: number,
immediate?: boolean
): EmberRunTimer;
debounce<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
arg3: any,
arg4: any,
wait: number,
immediate?: boolean
): EmberRunTimer;
debounce<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
arg3: any,
arg4: any,
arg5: any,
wait: number,
immediate?: boolean
): EmberRunTimer;
/**
* Ensure that the target method is never called more frequently than
* the specified spacing period. The target method is called immediately.
*/
throttle(
method: (...args: any[]) => any,
spacing: number,
immediate?: boolean
): EmberRunTimer;
throttle<Target>(
target: Target,
method: RunMethod<Target>,
spacing: number,
immediate?: boolean
): EmberRunTimer;
throttle<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
spacing: number,
immediate?: boolean
): EmberRunTimer;
throttle<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
spacing: number,
immediate?: boolean
): EmberRunTimer;
throttle<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
spacing: number,
immediate?: boolean
): EmberRunTimer;
throttle<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
arg3: any,
spacing: number,
immediate?: boolean
): EmberRunTimer;
throttle<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
arg3: any,
arg4: any,
spacing: number,
immediate?: boolean
): EmberRunTimer;
throttle<Target>(
target: Target,
method: RunMethod<Target>,
arg0: any,
arg1: any,
arg2: any,
arg3: any,
arg4: any,
arg5: any,
spacing: number,
immediate?: boolean
): EmberRunTimer;
queues: EmberRunQueues[];
};
queues: EmberRunQueues[];
}
export const run: RunNamespace;
export const begin: typeof run.begin;
export const bind: typeof run.bind;
export const cancel: typeof run.cancel;

View File

@@ -28,6 +28,7 @@
"index.d.ts",
"types.d.ts",
"-private/types.d.ts",
"-private/backburner.d.ts",
"ember__runloop-tests.ts"
]
}