Fix spacing in RSVP (thanks, Prettier).

This commit is contained in:
Chris Krycho
2017-08-11 09:19:55 -04:00
parent 0196f2468e
commit 6ecbed7242
+148 -148
View File
@@ -14,98 +14,98 @@
// Credit for that file goes to: Barrie Nemetchek <https://github.com/bnemetchek>, Andrew Gaspar <https://github.com/AndrewGaspar/>, John Reilly <https://github.com/johnnyreilly>
declare namespace RSVP {
type Resolution<T, U, C> = (value: T) => U | Thenable<U, C>;
type Rejection<T, C, D> = (error: C) => D | Thenable<T, D>;
type Resolution<T, U, C> = (value: T) => U | Thenable<U, C>;
type Rejection<T, C, D> = (error: C) => D | Thenable<T, D>;
interface Thenable<T, C> {
then(label?: string): Thenable<T, C>;
then<U>(onFulfillment: Resolution<T, U, C>, label?: string): Thenable<U, C>;
then<U, D>(
onFulfillment: Resolution<T, U, C>,
onRejected: Rejection<T, C, D>,
label?: string
): Thenable<U, D>;
}
interface Thenable<T, C> {
then(label?: string): Thenable<T, C>;
then<U>(onFulfillment: Resolution<T, U, C>, label?: string): Thenable<U, C>;
then<U, D>(
onFulfillment: Resolution<T, U, C>,
onRejected: Rejection<T, C, D>,
label?: string
): Thenable<U, D>;
}
interface Catchable<C> {
catch(label?: string): Catchable<C>;
catch<D>(onRejection: (error: C) => D, label?: string): Catchable<D>;
}
interface Catchable<C> {
catch(label?: string): Catchable<C>;
catch<D>(onRejection: (error: C) => D, label?: string): Catchable<D>;
}
interface Deferred<T, C> {
promise: Promise<T, C>;
resolve(value: T): void;
reject(reason: C): void;
}
interface Deferred<T, C> {
promise: Promise<T, C>;
resolve(value: T): void;
reject(reason: C): void;
}
type PromiseStates = 'fulfilled' | 'rejected' | 'pending';
interface IPromiseState<T, C> {
state: PromiseStates;
value: T;
reason: C;
}
type PromiseStates = 'fulfilled' | 'rejected' | 'pending';
interface IPromiseState<T, C> {
state: PromiseStates;
value: T;
reason: C;
}
class Resolved<T, C> implements IPromiseState<T, C> {
state: 'fulfilled';
value: T;
reason: never;
}
class Resolved<T, C> implements IPromiseState<T, C> {
state: 'fulfilled';
value: T;
reason: never;
}
class Rejected<T, C> implements IPromiseState<T, C> {
state: 'rejected';
value: never;
reason: C;
}
class Rejected<T, C> implements IPromiseState<T, C> {
state: 'rejected';
value: never;
reason: C;
}
class Pending<T, C> implements IPromiseState<T, C> {
state: 'pending';
value: never;
reason: never;
}
class Pending<T, C> implements IPromiseState<T, C> {
state: 'pending';
value: never;
reason: never;
}
type PromiseState<T, C> = Resolved<T, C> | Rejected<C, C> | Pending<T, C>;
type PromiseState<T, C> = Resolved<T, C> | Rejected<C, C> | Pending<T, C>;
type PromiseHash<T, C> = { [P in keyof T]: Thenable<T[P], C> | T[P] };
type PromiseHash<T, C> = { [P in keyof T]: Thenable<T[P], C> | T[P] };
type SettledHash<T, C> = { [P in keyof T]: PromiseState<T[P], C> };
type SettledHash<T, C> = { [P in keyof T]: PromiseState<T[P], C> };
interface InstrumentEvent {
guid: string; // guid of promise. Must be globally unique, not just within the implementation
childGuid: string; // child of child promise (for chained via `then`)
eventName: string; // one of ['created', 'chained', 'fulfilled', 'rejected']
detail: any; // fulfillment value or rejection reason, if applicable
label: string; // label passed to promise's constructor
timeStamp: number; // milliseconds elapsed since 1 January 1970 00:00:00 UTC up until now
}
interface InstrumentEvent {
guid: string; // guid of promise. Must be globally unique, not just within the implementation
childGuid: string; // child of child promise (for chained via `then`)
eventName: string; // one of ['created', 'chained', 'fulfilled', 'rejected']
detail: any; // fulfillment value or rejection reason, if applicable
label: string; // label passed to promise's constructor
timeStamp: number; // milliseconds elapsed since 1 January 1970 00:00:00 UTC up until now
}
interface ObjectWithEventMixins {
on(
eventName: 'created' | 'chained' | 'fulfilled' | 'rejected',
listener: (event: InstrumentEvent) => void
): void;
on(eventName: 'error', errorHandler: (reason: any) => void): void;
on(eventName: string, callback: (value: any) => void): void;
off(eventName: string, callback?: (value: any) => void): void;
trigger(eventName: string, options?: any, label?: string): void;
}
interface ObjectWithEventMixins {
on(
eventName: 'created' | 'chained' | 'fulfilled' | 'rejected',
listener: (event: InstrumentEvent) => void
): void;
on(eventName: 'error', errorHandler: (reason: any) => void): void;
on(eventName: string, callback: (value: any) => void): void;
off(eventName: string, callback?: (value: any) => void): void;
trigger(eventName: string, options?: any, label?: string): void;
}
class Promise<T, C> implements Thenable<T, C>, Catchable<C> {
/**
class Promise<T, C> implements Thenable<T, C>, Catchable<C> {
/**
* If you call resolve in the body of the callback passed to the constructor,
* your promise is fulfilled with result object passed to resolve.
* If you call reject your promise is rejected with the object passed to reject.
* For consistency and debugging (eg stack traces), obj should be an instanceof Error.
* Any errors thrown in the constructor callback will be implicitly passed to reject().
*/
constructor(
callback: (
resolve: (result?: T | Thenable<T, never>) => void,
reject: (error: C | Thenable<never, C>) => void
) => void,
label?: string
);
constructor(
callback: (
resolve: (result?: T | Thenable<T, never>) => void,
reject: (error: C | Thenable<never, C>) => void
) => void,
label?: string
);
/**
/**
* onFulfillment is called when/if "promise" resolves. onRejected is called when/if "promise" rejects.
* Both are optional, if either/both are omitted the next onFulfillment/onRejected in the chain is called.
* Both callbacks have a single parameter , the fulfillment value or rejection reason.
@@ -116,31 +116,31 @@ declare namespace RSVP {
* @param onRejected called when/if "promise" rejects
* @param label useful for tooling
*/
then<U, D>(
onFulfillment: Resolution<T, U, C>,
onRejected: Rejection<T, C, D>,
label?: string
): Promise<U, D>;
then<U>(onFulfillment: Resolution<T, U, C>, label?: string): Promise<U, C>;
then(label?: string): Promise<T, C>;
then<U, D>(
onFulfillment: Resolution<T, U, C>,
onRejected: Rejection<T, C, D>,
label?: string
): Promise<U, D>;
then<U>(onFulfillment: Resolution<T, U, C>, label?: string): Promise<U, C>;
then(label?: string): Promise<T, C>;
/**
/**
* Sugar for promise.then(undefined, onRejected)
*/
catch(label?: string): Promise<T, C>;
catch<D>(onRejection: Rejection<T, C, D>, label?: string): Promise<T, D>;
catch(label?: string): Promise<T, C>;
catch<D>(onRejection: Rejection<T, C, D>, label?: string): Promise<T, D>;
finally(finallyCallback: Function): Promise<T, C>;
finally(finallyCallback: Function): Promise<T, C>;
/**
/**
* `RSVP.Promise.all` accepts an array of promises, and returns a new promise which
* is fulfilled with an array of fulfillment values for the passed promises, or
* rejected with the reason of the first passed promise to be rejected. It casts all
* elements of the passed iterable to promises as it runs this algorithm.
*/
static all<T, C>(promises: Thenable<T, C>[], label?: string): Promise<T[], C>;
static all<T, C>(promises: Thenable<T, C>[], label?: string): Promise<T[], C>;
/**
/**
* `RSVP.Promise.race` returns a new promise which is settled in the same way as the
* first passed promise to settle.
*
@@ -150,67 +150,67 @@ declare namespace RSVP {
* become rejected before the other promises became fulfilled, the returned
* promise will become rejected.
*/
static race<T, C>(promises: Promise<T, C>[]): Promise<T, C>;
static race<T, C>(promises: Promise<T, C>[]): Promise<T, C>;
/**
/**
* Returns a promise that will become resolved with the passed `value`
*/
static resolve<T>(value: T, label?: string): Promise<T, never>;
static resolve<T>(value: T, label?: string): Promise<T, never>;
/**
/**
* Deprecated in favor of resolve
*/
static cast<T>(value: T, label?: string): Promise<T, never>;
static cast<T>(value: T, label?: string): Promise<T, never>;
/**
/**
* Returns a promise rejected with the passed `reason`.
*/
static reject<C>(reason: C): Promise<never, C>;
}
static reject<C>(reason: C): Promise<never, C>;
}
export namespace EventTarget {
/** `RSVP.EventTarget.mixin` extends an object with EventTarget methods. */
function mixin(object: object): ObjectWithEventMixins;
export namespace EventTarget {
/** `RSVP.EventTarget.mixin` extends an object with EventTarget methods. */
function mixin(object: object): ObjectWithEventMixins;
/** Registers a callback to be executed when `eventName` is triggered */
function on(
eventName: 'created' | 'chained' | 'fulfilled' | 'rejected',
listener: (event: InstrumentEvent) => void
): void;
function on(eventName: 'error', errorHandler: (reason: any) => void): void;
function on(eventName: string, callback: (value: any) => void): void;
/** Registers a callback to be executed when `eventName` is triggered */
function on(
eventName: 'created' | 'chained' | 'fulfilled' | 'rejected',
listener: (event: InstrumentEvent) => void
): void;
function on(eventName: 'error', errorHandler: (reason: any) => void): void;
function on(eventName: string, callback: (value: any) => void): void;
/**
/**
* You can use `off` to stop firing a particular callback for an event.
*
* If you don't pass a `callback` argument to `off`, ALL callbacks for the
* event will not be executed when the event fires.
*/
function off(eventName: string, callback?: (value: any) => void): void;
function off(eventName: string, callback?: (value: any) => void): void;
/**
/**
* Use `trigger` to fire custom events.
*
* You can also pass a value as a second argument to `trigger` that will be
* passed as an argument to all event listeners for the event
*/
function trigger(eventName: string, options?: any, label?: string): void;
}
function trigger(eventName: string, options?: any, label?: string): void;
}
export function configure(
configName: 'instrument' | 'instrument-with-stack',
shouldInstrument: boolean
): void;
export function configure(configName: string, value: any): void;
export function configure(
configName: 'instrument' | 'instrument-with-stack',
shouldInstrument: boolean
): void;
export function configure(configName: string, value: any): void;
/**
/**
* Make a promise that fulfills when every item in the array fulfills, and rejects if (and when) any item rejects.
* the array passed to all can be a mixture of promise-like objects and other objects.
* The fulfillment value is an array (in order) of fulfillment values. The rejection value is the first rejection value.
*/
export function all<T, C>(promises: Thenable<T, C>[]): Promise<T[], C>;
export function all<T, C>(promises: Thenable<T, C>[]): Promise<T[], C>;
/**
/**
* `RSVP.hash` is similar to `RSVP.all`, but takes an object instead of an array
* for its `promises` argument.
*
@@ -223,9 +223,9 @@ declare namespace RSVP {
* If any of the `promises` given to `RSVP.hash` are rejected, the first promise
* that is rejected will be given as the reason to the rejection handler.
*/
export function hash<T, C>(promises: PromiseHash<T, C>): Promise<T, C>;
export function hash<T, C>(promises: PromiseHash<T, C>): Promise<T, C>;
/**
/**
* `RSVP.map` is similar to JavaScript's native `map` method. `mapFn` is eagerly called
* meaning that as soon as any promise resolves its value will be passed to `mapFn`.
* `RSVP.map` returns a promise that will become fulfilled with the result of running
@@ -235,21 +235,21 @@ declare namespace RSVP {
* that is rejected will be given as an argument to the returned promise's
* rejection handler.
*/
export function map<T, U, C>(
promises: Thenable<T, C>[],
mapFn: (item: T) => U,
label?: string
): Promise<U[], C>;
export function map<T, U, C>(
promises: Thenable<T, C>[],
mapFn: (item: T) => U,
label?: string
): Promise<U[], C>;
/**
/**
* `RSVP.allSettled` is similar to `RSVP.all`, but instead of implementing
* a fail-fast method, it waits until all the promises have returned and
* shows you all the results. This is useful if you want to handle multiple
* promises' failure states together as a set.
*/
export function allSettled<T, C>(promises: Thenable<T, C>[]): Promise<PromiseState<T, C>[], C>;
export function allSettled<T, C>(promises: Thenable<T, C>[]): Promise<PromiseState<T, C>[], C>;
/**
/**
* `RSVP.hashSettled` is similar to `RSVP.allSettled`, but takes an object
* instead of an array for its `promises` argument.
*
@@ -259,14 +259,14 @@ declare namespace RSVP {
* with their states and values/reasons. This is useful if you want to
* handle multiple promises' failure states together as a set.
*/
export function hashSettled<T, C>(promises: PromiseHash<T, C>): Promise<SettledHash<T, C>, C>;
export function hashSettled<T, C>(promises: PromiseHash<T, C>): Promise<SettledHash<T, C>, C>;
/**
/**
* Make a Promise that fulfills when any item fulfills, and rejects if any item rejects.
*/
function race<T, C>(promises: Promise<T, C>[]): Promise<T, C>;
function race<T, C>(promises: Promise<T, C>[]): Promise<T, C>;
/**
/**
* `RSVP.denodeify` takes a "node-style" function and returns a function that
* will return an `RSVP.Promise`. You can use `denodeify` in Node.js or the
* browser when you'd prefer to use promises over using callbacks. For example,
@@ -324,12 +324,12 @@ declare namespace RSVP {
* });
* ```
*/
export function denodeify<A, T, C>(
nodeFunction: Function,
options: boolean | string[]
): (...args: A[]) => Promise<T, C>;
export function denodeify<A, T, C>(
nodeFunction: Function,
options: boolean | string[]
): (...args: A[]) => Promise<T, C>;
/**
/**
* `RSVP.defer` returns an object similar to jQuery's `$.Deferred`.
* `RSVP.defer` should be used when porting over code reliant on `$.Deferred`'s
* interface. New code should use the `RSVP.Promise` constructor instead.
@@ -339,32 +339,32 @@ declare namespace RSVP {
* * reject - a function that causes the `promise` property on this object to become rejected
* * resolve - a function that causes the `promise` property on this object to become fulfilled.
*/
export function defer<T, C>(label?: string): Deferred<T, C>;
export function defer<T, C>(label?: string): Deferred<T, C>;
/**
/**
* `RSVP.Promise.reject` returns a promise rejected with the passed `reason`.
*/
export function reject<C>(reason: C): Promise<never, C>;
export function reject<C>(reason: C): Promise<never, C>;
/**
/**
* `RSVP.Promise.resolve` returns a promise that will become resolved with the
* passed `value`.
*/
export function resolve<T>(value: T): Promise<T, never>;
export function resolve<T>(value: T): Promise<T, never>;
/**
/**
* `RSVP.filter` is similar to JavaScript's native `filter` method, except that it
* waits for all promises to become fulfilled before running the `filterFn` on
* each item in given to `promises`. `RSVP.filter` returns a promise that will
* become fulfilled with the result of running `filterFn` on the values the
* promises become fulfilled with.
*/
export function filter<T, C>(
promises: Thenable<T, C>[],
filterFn: (value: T) => boolean | Promise<any, any>
): Promise<T[], C>;
export function filter<T, C>(
promises: Thenable<T, C>[],
filterFn: (value: T) => boolean | Promise<any, any>
): Promise<T[], C>;
/**
/**
* `RSVP.rethrow` will rethrow an error on the next turn of the JavaScript event
* loop in order to aid debugging.
*
@@ -376,7 +376,7 @@ declare namespace RSVP {
* or domain/cause uncaught exception in Node. `rethrow` will also throw the
* error again so the error can be handled by the promise per the spec.
*/
export function rethrow<C>(reason: C): void;
export function rethrow<C>(reason: C): void;
}
// export default RSVP;