From ff0bdade31fefd781250d58a01b023ba7e6e15c0 Mon Sep 17 00:00:00 2001 From: Mike North Date: Thu, 20 Sep 2018 10:27:55 -0700 Subject: [PATCH] [ember] @ember/runloop as source of types, ember as re-export --- types/ember/index.d.ts | 328 +--------------------- types/ember/tsconfig.json | 2 + types/ember__runloop/-private/types.d.ts | 8 + types/ember__runloop/index.d.ts | 336 ++++++++++++++++++++++- types/ember__runloop/tsconfig.json | 5 +- types/ember__runloop/types.d.ts | 3 + 6 files changed, 344 insertions(+), 338 deletions(-) create mode 100644 types/ember__runloop/-private/types.d.ts create mode 100644 types/ember__runloop/types.d.ts diff --git a/types/ember/index.d.ts b/types/ember/index.d.ts index 7765f89592..ad5e0fc7a7 100755 --- a/types/ember/index.d.ts +++ b/types/ember/index.d.ts @@ -21,6 +21,7 @@ /// /// /// +/// 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 = EmberArrayNs.default; @@ -99,18 +103,6 @@ declare module 'ember' { [index: string]: (...params: any[]) => any; } - interface EmberRunTimer { - __ember_run_timer_brand__: any; - } - - type RunMethod = ((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. - */ - (method: (...args: any[]) => Ret): Ret; - (target: Target, method: RunMethod): 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(method: (...args: any[]) => Ret, ...args: any[]): Ret | undefined; - join( - target: Target, - method: RunMethod, - ...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: Target, - method: RunMethod, - ...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( - queue: EmberRunQueues, - target: Target, - method: RunMethod, - ...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, method: RunMethod, wait: number): EmberRunTimer; - later( - target: Target, - method: RunMethod, - arg0: any, - wait: number - ): EmberRunTimer; - later( - target: Target, - method: RunMethod, - arg0: any, - arg1: any, - wait: number - ): EmberRunTimer; - later( - target: Target, - method: RunMethod, - arg0: any, - arg1: any, - arg2: any, - wait: number - ): EmberRunTimer; - later( - target: Target, - method: RunMethod, - arg0: any, - arg1: any, - arg2: any, - arg3: any, - wait: number - ): EmberRunTimer; - later( - target: Target, - method: RunMethod, - arg0: any, - arg1: any, - arg2: any, - arg3: any, - arg4: any, - wait: number - ): EmberRunTimer; - later( - target: Target, - method: RunMethod, - 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, method: RunMethod, ...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( - queue: EmberRunQueues, - target: Target, - method: RunMethod, - ...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, method: RunMethod, ...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, - method: RunMethod, - wait: number, - immediate?: boolean - ): EmberRunTimer; - debounce( - target: Target, - method: RunMethod, - arg0: any, - wait: number, - immediate?: boolean - ): EmberRunTimer; - debounce( - target: Target, - method: RunMethod, - arg0: any, - arg1: any, - wait: number, - immediate?: boolean - ): EmberRunTimer; - debounce( - target: Target, - method: RunMethod, - arg0: any, - arg1: any, - arg2: any, - wait: number, - immediate?: boolean - ): EmberRunTimer; - debounce( - target: Target, - method: RunMethod, - arg0: any, - arg1: any, - arg2: any, - arg3: any, - wait: number, - immediate?: boolean - ): EmberRunTimer; - debounce( - target: Target, - method: RunMethod, - arg0: any, - arg1: any, - arg2: any, - arg3: any, - arg4: any, - wait: number, - immediate?: boolean - ): EmberRunTimer; - debounce( - target: Target, - method: RunMethod, - 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, - method: RunMethod, - spacing: number, - immediate?: boolean - ): EmberRunTimer; - throttle( - target: Target, - method: RunMethod, - arg0: any, - spacing: number, - immediate?: boolean - ): EmberRunTimer; - throttle( - target: Target, - method: RunMethod, - arg0: any, - arg1: any, - spacing: number, - immediate?: boolean - ): EmberRunTimer; - throttle( - target: Target, - method: RunMethod, - arg0: any, - arg1: any, - arg2: any, - spacing: number, - immediate?: boolean - ): EmberRunTimer; - throttle( - target: Target, - method: RunMethod, - arg0: any, - arg1: any, - arg2: any, - arg3: any, - spacing: number, - immediate?: boolean - ): EmberRunTimer; - throttle( - target: Target, - method: RunMethod, - arg0: any, - arg1: any, - arg2: any, - arg3: any, - arg4: any, - spacing: number, - immediate?: boolean - ): EmberRunTimer; - throttle( - target: Target, - method: RunMethod, - 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 { } diff --git a/types/ember/tsconfig.json b/types/ember/tsconfig.json index 7df2202cb8..e22a9df4ec 100755 --- a/types/ember/tsconfig.json +++ b/types/ember/tsconfig.json @@ -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"] diff --git a/types/ember__runloop/-private/types.d.ts b/types/ember__runloop/-private/types.d.ts new file mode 100644 index 0000000000..7d3bcfc61b --- /dev/null +++ b/types/ember__runloop/-private/types.d.ts @@ -0,0 +1,8 @@ +export type RunMethod = ((this: Target, ...args: any[]) => Ret) | keyof Target; +export type EmberRunQueues = + | 'sync' + | 'actions' + | 'routerTransitions' + | 'render' + | 'afterRender' + | 'destroy'; diff --git a/types/ember__runloop/index.d.ts b/types/ember__runloop/index.d.ts index acc8c3ad8a..f1deeb9d17 100644 --- a/types/ember__runloop/index.d.ts +++ b/types/ember__runloop/index.d.ts @@ -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. + */ + (method: (...args: any[]) => Ret): Ret; + (target: Target, method: RunMethod): 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(method: (...args: any[]) => Ret, ...args: any[]): Ret | undefined; + join( + target: Target, + method: RunMethod, + ...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: Target, + method: RunMethod, + ...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( + queue: EmberRunQueues, + target: Target, + method: RunMethod, + ...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, + method: RunMethod, + wait: number + ): EmberRunTimer; + later( + target: Target, + method: RunMethod, + arg0: any, + wait: number + ): EmberRunTimer; + later( + target: Target, + method: RunMethod, + arg0: any, + arg1: any, + wait: number + ): EmberRunTimer; + later( + target: Target, + method: RunMethod, + arg0: any, + arg1: any, + arg2: any, + wait: number + ): EmberRunTimer; + later( + target: Target, + method: RunMethod, + arg0: any, + arg1: any, + arg2: any, + arg3: any, + wait: number + ): EmberRunTimer; + later( + target: Target, + method: RunMethod, + arg0: any, + arg1: any, + arg2: any, + arg3: any, + arg4: any, + wait: number + ): EmberRunTimer; + later( + target: Target, + method: RunMethod, + 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, + method: RunMethod, + ...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( + queue: EmberRunQueues, + target: Target, + method: RunMethod, + ...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, + method: RunMethod, + ...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, + method: RunMethod, + wait: number, + immediate?: boolean + ): EmberRunTimer; + debounce( + target: Target, + method: RunMethod, + arg0: any, + wait: number, + immediate?: boolean + ): EmberRunTimer; + debounce( + target: Target, + method: RunMethod, + arg0: any, + arg1: any, + wait: number, + immediate?: boolean + ): EmberRunTimer; + debounce( + target: Target, + method: RunMethod, + arg0: any, + arg1: any, + arg2: any, + wait: number, + immediate?: boolean + ): EmberRunTimer; + debounce( + target: Target, + method: RunMethod, + arg0: any, + arg1: any, + arg2: any, + arg3: any, + wait: number, + immediate?: boolean + ): EmberRunTimer; + debounce( + target: Target, + method: RunMethod, + arg0: any, + arg1: any, + arg2: any, + arg3: any, + arg4: any, + wait: number, + immediate?: boolean + ): EmberRunTimer; + debounce( + target: Target, + method: RunMethod, + 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, + method: RunMethod, + spacing: number, + immediate?: boolean + ): EmberRunTimer; + throttle( + target: Target, + method: RunMethod, + arg0: any, + spacing: number, + immediate?: boolean + ): EmberRunTimer; + throttle( + target: Target, + method: RunMethod, + arg0: any, + arg1: any, + spacing: number, + immediate?: boolean + ): EmberRunTimer; + throttle( + target: Target, + method: RunMethod, + arg0: any, + arg1: any, + arg2: any, + spacing: number, + immediate?: boolean + ): EmberRunTimer; + throttle( + target: Target, + method: RunMethod, + arg0: any, + arg1: any, + arg2: any, + arg3: any, + spacing: number, + immediate?: boolean + ): EmberRunTimer; + throttle( + target: Target, + method: RunMethod, + arg0: any, + arg1: any, + arg2: any, + arg3: any, + arg4: any, + spacing: number, + immediate?: boolean + ): EmberRunTimer; + throttle( + target: Target, + method: RunMethod, + 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; diff --git a/types/ember__runloop/tsconfig.json b/types/ember__runloop/tsconfig.json index 3ece4d5f92..978da83052 100644 --- a/types/ember__runloop/tsconfig.json +++ b/types/ember__runloop/tsconfig.json @@ -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" ] } diff --git a/types/ember__runloop/types.d.ts b/types/ember__runloop/types.d.ts new file mode 100644 index 0000000000..2aeaa44726 --- /dev/null +++ b/types/ember__runloop/types.d.ts @@ -0,0 +1,3 @@ +export interface EmberRunTimer { + __ember_run_timer_brand__: boolean; +}