[ember] @ember/runloop as source of types, ember as re-export

This commit is contained in:
Mike North 2018-09-20 10:27:55 -07:00
parent 5679ed161c
commit ff0bdade31
6 changed files with 344 additions and 338 deletions

328
types/ember/index.d.ts vendored
View File

@ -21,6 +21,7 @@
/// <reference types="ember__array" />
/// <reference types="ember__engine" />
/// <reference types="ember__debug" />
/// <reference types="ember__runloop" />
declare module 'ember' {
import {
@ -43,6 +44,7 @@ declare module 'ember' {
import * as EmberStringNs from '@ember/string';
import * as EmberPolyfillsNs from '@ember/polyfills';
import * as EmberUtilsNs from '@ember/utils';
import * as EmberRunloopNs from '@ember/runloop';
import * as EmberObjectNs from '@ember/object';
import * as EmberObjectObserversNs from '@ember/object/observers';
import * as EmberObjectMixinNs from '@ember/object/mixin';
@ -70,6 +72,8 @@ declare module 'ember' {
import EmberArrayProxy from '@ember/array/proxy';
import EmberEnumerable from '@ember/array/-private/enumerable';
import EmberArrayProtoExtensions from '@ember/array/types/prototype-extensions';
// @ember/run
import { RunMethod } from '@ember/runloop/-private/types';
type EmberArray<T> = EmberArrayNs.default<T>;
@ -99,18 +103,6 @@ declare module 'ember' {
[index: string]: (...params: any[]) => any;
}
interface EmberRunTimer {
__ember_run_timer_brand__: any;
}
type RunMethod<Target, Ret = any> = ((this: Target, ...args: any[]) => Ret) | keyof Target;
type EmberRunQueues =
| 'sync'
| 'actions'
| 'routerTransitions'
| 'render'
| 'afterRender'
| 'destroy';
type QueryParamTypes = 'boolean' | 'number' | 'array' | 'string';
type QueryParamScopeTypes = 'controller' | 'model';
@ -1421,300 +1413,7 @@ declare module 'ember' {
const w: typeof EmberStringNs.w;
}
const computed: typeof EmberObjectNs.computed;
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;
queues: EmberRunQueues[];
};
const run: typeof EmberRunloopNs.run;
const platform: {
defineProperty: boolean;
hasPropertyAccessors: boolean;
@ -2155,23 +1854,6 @@ declare module '@ember/routing/router-service' {
export default class extends RouterService { }
}
declare module '@ember/runloop' {
import Ember from 'ember';
export const begin: typeof Ember.run.begin;
export const bind: typeof Ember.run.bind;
export const cancel: typeof Ember.run.cancel;
export const debounce: typeof Ember.run.debounce;
export const end: typeof Ember.run.end;
export const join: typeof Ember.run.join;
export const later: typeof Ember.run.later;
export const next: typeof Ember.run.next;
export const once: typeof Ember.run.once;
export const run: typeof Ember.run;
export const schedule: typeof Ember.run.schedule;
export const scheduleOnce: typeof Ember.run.scheduleOnce;
export const throttle: typeof Ember.run.throttle;
}
declare module '@ember/service' {
import Ember from 'ember';
export default class Service extends Ember.Service { }

View File

@ -24,6 +24,8 @@
"@ember/array/*": ["ember__array/*"],
"@ember/debug": ["ember__debug"],
"@ember/debug/*": ["ember__debug/*"],
"@ember/runloop": ["ember__runloop"],
"@ember/runloop/*": ["ember__runloop/*"],
"@ember/object": ["ember__object"],
"@ember/object/*": ["ember__object/*"],
"@ember/polyfills": ["ember__polyfills"]

View File

@ -0,0 +1,8 @@
export type RunMethod<Target, Ret = any> = ((this: Target, ...args: any[]) => Ret) | keyof Target;
export type EmberRunQueues =
| 'sync'
| 'actions'
| 'routerTransitions'
| 'render'
| 'afterRender'
| 'destroy';

View File

@ -4,18 +4,326 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import Ember from 'ember';
import { RunMethod, EmberRunQueues } from "@ember/runloop/-private/types";
import { EmberRunTimer } from "@ember/runloop/types";
export const begin: typeof Ember.run.begin;
export const bind: typeof Ember.run.bind;
export const cancel: typeof Ember.run.cancel;
export const debounce: typeof Ember.run.debounce;
export const end: typeof Ember.run.end;
export const join: typeof Ember.run.join;
export const later: typeof Ember.run.later;
export const next: typeof Ember.run.next;
export const once: typeof Ember.run.once;
export const run: typeof Ember.run;
export const schedule: typeof Ember.run.schedule;
export const scheduleOnce: typeof Ember.run.scheduleOnce;
export const throttle: typeof Ember.run.throttle;
// 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;
queues: EmberRunQueues[];
};
export const begin: typeof run.begin;
export const bind: typeof run.bind;
export const cancel: typeof run.cancel;
export const debounce: typeof run.debounce;
export const end: typeof run.end;
export const join: typeof run.join;
export const later: typeof run.later;
export const next: typeof run.next;
export const once: typeof run.once;
export const schedule: typeof run.schedule;
export const scheduleOnce: typeof run.scheduleOnce;
export const throttle: typeof run.throttle;

View File

@ -19,7 +19,8 @@
"@ember/object/*": ["ember__object/*"],
"@ember/engine": ["ember__engine"],
"@ember/engine/*": ["ember__engine/*"],
"@ember/runloop": ["ember__runloop"]
"@ember/runloop": ["ember__runloop"],
"@ember/runloop/*": ["ember__runloop/*"]
},
"types": [],
"noEmit": true,
@ -27,6 +28,8 @@
},
"files": [
"index.d.ts",
"types.d.ts",
"-private/types.d.ts",
"ember__runloop-tests.ts"
]
}

3
types/ember__runloop/types.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
export interface EmberRunTimer {
__ember_run_timer_brand__: boolean;
}