Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build flow types #8

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dist/module/exceptions.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* @flow */
import type { ZalgoPromise } from './promise';
const dispatchedErrors = [];
const possiblyUnhandledPromiseHandlers: Array<(mixed, promise?: ZalgoPromise<mixed>) => void> = [];
declare export function dispatchPossiblyUnhandledError<T>(err: mixed, promise: ZalgoPromise<T>): any;
declare export function onPossiblyUnhandledException(handler: (mixed, promise?: ZalgoPromise<mixed>) => void): {|
cancel: () => void
|};
6 changes: 6 additions & 0 deletions dist/module/export.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* @flow */
// $FlowFixMe
module.exports = require('./promise').ZalgoPromise; // eslint-disable-line import/no-commonjs
// $FlowFixMe

module.exports.ZalgoPromise = require('./promise').ZalgoPromise; // eslint-disable-line import/no-commonjs
8 changes: 8 additions & 0 deletions dist/module/flush.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* @flow */
import type { ZalgoPromise } from './promise';
let activeCount = 0;
let flushPromise;
declare function flushActive(): any;
declare export function startActive(): any;
declare export function endActive(): any;
declare export function awaitActive(Zalgo: Class<ZalgoPromise<*>>): ZalgoPromise<void>;
54 changes: 2 additions & 52 deletions dist/module/index.js.flow
Original file line number Diff line number Diff line change
@@ -1,52 +1,2 @@
// @flow

declare class Class0 {
static $call(message?: string): Class0;
static captureStackTrace(target: Object, constructor?: Function): void;
static prepareStackTrace: (err: Class0, stack: Array<CallSite>) => mixed;
static stackTraceLimit: number;

columnNumber?: number;
description?: string;
fileName?: string;
lineNumber?: number;
message: string;
name: string;
number?: number;
stack: string;
constructor(message?: mixed): void;
toString(): string;
}
declare export class ZalgoPromise<R> {
static all<X: [mixed /* UNEXPECTED TYPE: ExistsT */] | [mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */] | [mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */] | [mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */] | [mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */] | [mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */] | [mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */] | [mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */] | [mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */] | Array<mixed>>(promises: X): ZalgoPromise<mixed /* UNEXPECTED TYPE: EvalT */>;
static asyncReject(error: mixed): ZalgoPromise<R>;
static delay(delay: number): ZalgoPromise<void>;
static flush(): ZalgoPromise<void>;
static hash<O: {[_: string]: mixed /* UNEXPECTED TYPE: ExistsT */}>(promises: O): ZalgoPromise<mixed /* UNEXPECTED TYPE: EvalT */>;
static isPromise(value: mixed): boolean;
static map<T, X>(items: Array<T>, method: (_: T) => ZalgoPromise<X> | X): ZalgoPromise<Array<X>>;
static onPossiblyUnhandledException(handler: (err: mixed) => void): {cancel: () => void};
static reject(error: mixed): ZalgoPromise<R>;
static resolve<X>(value: X | ZalgoPromise<X>): ZalgoPromise<X>;
static try<X, Y, C, A: Array<mixed>>(method: (...args: A) => ZalgoPromise<X> | Y, context: ?C, args: ?A): ZalgoPromise<X | Y>;

dispatching: boolean;
error: mixed;
errorHandled: boolean;
handlers: Array<{onError: void | (error: mixed) => mixed, onSuccess: void | (result: R) => mixed, promise: ZalgoPromise<mixed /* UNEXPECTED TYPE: ExistsT */>}>;
rejected: boolean;
resolved: boolean;
stack: string;
value: R;
asyncReject(error: mixed): ZalgoPromise<R>;
catch<X, Y>(onError: (error: mixed) => ZalgoPromise<X> | Y): ZalgoPromise<X | Y>;
constructor(handler: ?(resolve: (result: R) => void, reject: (error: mixed) => void) => void): any;
dispatch(): any;
finally(onFinally: () => mixed): ZalgoPromise<R>;
reject(error: mixed): ZalgoPromise<R>;
resolve(result: R): ZalgoPromise<R>;
then<X, Y>(onSuccess: void | (result: R) => ZalgoPromise<X> | Y, onError: void | (error: mixed) => ZalgoPromise<X> | Y): ZalgoPromise<X | Y>;
timeout(time: number, err: ?Class0): ZalgoPromise<R>;
toPromise(): Class<Promise<R>> | Class<Promise> | Promise<+R>;
}

/* @flow */
export { ZalgoPromise } from './promise';
42 changes: 42 additions & 0 deletions dist/module/promise.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* @flow */
import { isPromise } from './utils';
import { onPossiblyUnhandledException, dispatchPossiblyUnhandledError } from './exceptions';
import { startActive, endActive, awaitActive } from './flush';
declare export class ZalgoPromise<R: mixed> {
resolved: boolean,
rejected: boolean,
errorHandled: boolean,
value: R,
error: mixed,
handlers: Array<{|
promise: ZalgoPromise<*>,
onSuccess: void | ((result: R) => mixed),
onError: void | ((error: mixed) => mixed),
|}>,
dispatching: boolean,
stack: string,
constructor(handler: ?(resolve: (result: R) => void, reject: (error: mixed) => void) => void): any,
resolve(result: R): ZalgoPromise<R>,
reject(error: mixed): ZalgoPromise<R>,
asyncReject(error: mixed): ZalgoPromise<R>,
dispatch(): any,
then<X, Y>(onSuccess: void | ((result: R) => ZalgoPromise<X> | Y), onError: void | ((error: mixed) => ZalgoPromise<X> | Y)): ZalgoPromise<X | Y>,
catch<X, Y>(onError: (error: mixed) => ZalgoPromise<X> | Y): ZalgoPromise<X | Y>,
finally(onFinally: () => mixed): ZalgoPromise<R>,
timeout(time: number, err: ?Error): ZalgoPromise<R>,
toPromise(): Promise<R>,
lazy(): ZalgoPromise<R>,
static resolve<X, Y>(value: ZalgoPromise<X> | Y): ZalgoPromise<X | Y>,
static reject(error: mixed): ZalgoPromise<R>,
static asyncReject(error: mixed): ZalgoPromise<R>,
static all<X: $ReadOnlyArray<mixed>>(promises: X): ZalgoPromise<$TupleMap<X, <Y>(ZalgoPromise<Y> | Y) => Y>>,
static hash<O: Object>(promises: O): ZalgoPromise<$ObjMap<O, <Y>(ZalgoPromise<Y> | Y) => Y>>,
static map<T, X>(items: $ReadOnlyArray<T>, method: (T) => ZalgoPromise<X> | X): ZalgoPromise<$ReadOnlyArray<X>>,
static onPossiblyUnhandledException(handler: (err: mixed) => void): {|
cancel: () => void
|},
static try<X, Y, C: mixed, A: $ReadOnlyArray<mixed>>(method: (...args: $ReadOnlyArray<mixed>) => ZalgoPromise<X> | Y, context?: C, args?: A): ZalgoPromise<X | Y>,
static delay(delay: number): ZalgoPromise<void>,
static isPromise(value: mixed): boolean,
static flush(): ZalgoPromise<void>,
}
4 changes: 4 additions & 0 deletions dist/module/types.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* @flow */
export type ZalgoPromiseConstructorType = (resolve: (mixed) => void, reject: (mixed) => void) => void; // export something to force webpack to see this as an ES module

export const TYPES = true;
2 changes: 2 additions & 0 deletions dist/module/utils.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* @flow */
declare export function isPromise(item: mixed): boolean;
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
"setup": "npm install && npm run flow-typed",
"lint": "eslint src/ test/ *.js",
"flow-typed": "flow-typed install",
"build:types": "gen-flow-files src --out-dir dist/module",
"flow": "flow",
"karma": "cross-env NODE_ENV=test babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/karma start",
"babel": "babel src/ --out-dir dist/module",
"webpack": "babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/webpack --display-optimization-bailout --progress",
"test": "npm run lint && npm run flow-typed && npm run flow && npm run karma",
"build": "npm run test && npm run babel && npm run webpack",
"build": "npm run test && npm run babel && npm run webpack && npm run build:types",
"release": "./publish.sh",
"release:patch": "./publish.sh patch",
"release:minor": "./publish.sh minor",
Expand Down Expand Up @@ -41,6 +42,7 @@
"readmeFilename": "README.md",
"devDependencies": {
"flow-bin": "0.155.0",
"gen-flow-files": "^0.4.11",
"grumbler-scripts": "^3",
"mocha": "^4"
},
Expand Down