Skip to content
This repository has been archived by the owner on Aug 1, 2018. It is now read-only.

Commit

Permalink
Improve Flow type definitions for exported functions (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMSmithCA authored Apr 16, 2018
1 parent 63a4c2d commit 06f2ad5
Show file tree
Hide file tree
Showing 12 changed files with 433 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
[ignore]
.*/node_modules/.*[^(package)]\.json$
<PROJECT_ROOT>/dist/.*

[include]
./src/

[libs]
./node_modules/fusion-core/flow-typed

[lints]

[options]
suppress_comment= \\(.\\|\n\\)*\\$FlowIgnore

[strict]
10 changes: 10 additions & 0 deletions flow-typed/globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** Copyright (c) 2018 Uber Technologies, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

declare var __NODE__: boolean;
declare var __BROWSER__: boolean;
105 changes: 105 additions & 0 deletions flow-typed/tape-cup_v4.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* eslint-disable */

declare type tape$TestOpts = {
skip: boolean,
timeout?: number,
} | {
skip?: boolean,
timeout: number,
};

declare type tape$TestCb = (t: tape$Context) => mixed;
declare type tape$TestFn = (a: string | tape$TestOpts | tape$TestCb, b?: tape$TestOpts | tape$TestCb, c?: tape$TestCb) => void;

declare interface tape$Context {
fail(msg?: string): void,
pass(msg?: string): void,

error(err: mixed, msg?: string): void,
ifError(err: mixed, msg?: string): void,
ifErr(err: mixed, msg?: string): void,
iferror(err: mixed, msg?: string): void,

ok(value: mixed, msg?: string): void,
true(value: mixed, msg?: string): void,
assert(value: mixed, msg?: string): void,

notOk(value: mixed, msg?: string): void,
false(value: mixed, msg?: string): void,
notok(value: mixed, msg?: string): void,

// equal + aliases
equal(actual: mixed, expected: mixed, msg?: string): void,
equals(actual: mixed, expected: mixed, msg?: string): void,
isEqual(actual: mixed, expected: mixed, msg?: string): void,
is(actual: mixed, expected: mixed, msg?: string): void,
strictEqual(actual: mixed, expected: mixed, msg?: string): void,
strictEquals(actual: mixed, expected: mixed, msg?: string): void,

// notEqual + aliases
notEqual(actual: mixed, expected: mixed, msg?: string): void,
notEquals(actual: mixed, expected: mixed, msg?: string): void,
notStrictEqual(actual: mixed, expected: mixed, msg?: string): void,
notStrictEquals(actual: mixed, expected: mixed, msg?: string): void,
isNotEqual(actual: mixed, expected: mixed, msg?: string): void,
isNot(actual: mixed, expected: mixed, msg?: string): void,
not(actual: mixed, expected: mixed, msg?: string): void,
doesNotEqual(actual: mixed, expected: mixed, msg?: string): void,
isInequal(actual: mixed, expected: mixed, msg?: string): void,

// deepEqual + aliases
deepEqual(actual: mixed, expected: mixed, msg?: string): void,
deepEquals(actual: mixed, expected: mixed, msg?: string): void,
isEquivalent(actual: mixed, expected: mixed, msg?: string): void,
same(actual: mixed, expected: mixed, msg?: string): void,

// notDeepEqual
notDeepEqual(actual: mixed, expected: mixed, msg?: string): void,
notEquivalent(actual: mixed, expected: mixed, msg?: string): void,
notDeeply(actual: mixed, expected: mixed, msg?: string): void,
notSame(actual: mixed, expected: mixed, msg?: string): void,
isNotDeepEqual(actual: mixed, expected: mixed, msg?: string): void,
isNotDeeply(actual: mixed, expected: mixed, msg?: string): void,
isNotEquivalent(actual: mixed, expected: mixed, msg?: string): void,
isInequivalent(actual: mixed, expected: mixed, msg?: string): void,

// deepLooseEqual
deepLooseEqual(actual: mixed, expected: mixed, msg?: string): void,
looseEqual(actual: mixed, expected: mixed, msg?: string): void,
looseEquals(actual: mixed, expected: mixed, msg?: string): void,

// notDeepLooseEqual
notDeepLooseEqual(actual: mixed, expected: mixed, msg?: string): void,
notLooseEqual(actual: mixed, expected: mixed, msg?: string): void,
notLooseEquals(actual: mixed, expected: mixed, msg?: string): void,

throws(fn: Function, expected?: RegExp | Function, msg?: string): void,
doesNotThrow(fn: Function, expected?: RegExp | Function, msg?: string): void,

timeoutAfter(ms: number): void,

skip(msg?: string): void,
plan(n: number): void,
onFinish(fn: Function): void,
end(): void,
comment(msg: string): void,
test: tape$TestFn,
}

declare module 'tape-cup' {
declare type TestHarness = Tape;
declare type StreamOpts = {
objectMode?: boolean,
};

declare type Tape = {
(a: string | tape$TestOpts | tape$TestCb, b?: tape$TestCb | tape$TestOpts, c?: tape$TestCb, ...rest: Array<void>): void,
test: tape$TestFn,
skip: (name: string, cb?: tape$TestCb) => void,
createHarness: () => TestHarness,
createStream: (opts?: StreamOpts) => stream$Readable,
only: (a: string | tape$TestOpts | tape$TestCb, b?: tape$TestCb | tape$TestOpts, c?: tape$TestCb, ...rest: Array<void>) => void,
};

declare module.exports: Tape;
}
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"version": "1.2.1",
"description": "Prepare you app state for async rendering",
"repository": "fusionjs/fusion-react-async",
"files": ["dist", "src"],
"files": [
"dist",
"src"
],
"main": "./dist/index.js",
"module": "./dist/index.es.js",
"browser": {
Expand All @@ -27,6 +30,7 @@
"test": "npm run build-test && npm run just-test"
},
"dependencies": {
"fusion-core": "^1.2.2",
"prop-types": "^15.5.8",
"react-is": "^16.3.1"
},
Expand All @@ -52,7 +56,8 @@
},
"peerDependencies": {
"react": "14.x - 16.x",
"react-dom": "14.x - 16.x"
"react-dom": "14.x - 16.x",
"fusion-core": "^1.0.0"
},
"engines": {
"node": ">= 8.9.0"
Expand Down
14 changes: 11 additions & 3 deletions src/__tests__/__node__/context.node.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
/** Copyright (c) 2018 Uber Technologies, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import tape from 'tape-cup';
import React from 'react';
import {renderToString} from 'react-dom/server';
import Provider from '../../prepare-provider';
import {prepare} from '../../index.js';

tape('Handling context', async t => {
class Child extends React.Component {
class Child extends React.Component<any, any> {
static contextTypes = {
field: () => {},
};

constructor(props) {
constructor(props: *) {
super(props);
}

Expand All @@ -19,7 +27,7 @@ tape('Handling context', async t => {
}
}

class Parent extends React.Component {
class Parent extends React.Component<any, any> {
static childContextTypes = {
field: () => {},
};
Expand Down
4 changes: 3 additions & 1 deletion src/__tests__/__node__/prepare-context.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

/* eslint-disable react/no-multi-comp */
Expand All @@ -13,7 +15,7 @@ tape('Preparing a sync app passing through context', t => {
let numConstructors = 0;
let numRenders = 0;
let numChildRenders = 0;
class SimpleComponent extends Component {
class SimpleComponent extends Component<any, any> {
constructor(props, context) {
super(props, context);
t.equal(
Expand Down
24 changes: 15 additions & 9 deletions src/__tests__/__node__/prepare-render.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

/* eslint-disable react/no-multi-comp */
Expand All @@ -17,7 +19,7 @@ tape('Preparing a sync app', t => {
let numConstructors = 0;
let numRenders = 0;
let numChildRenders = 0;
class SimpleComponent extends Component {
class SimpleComponent extends Component<any> {
constructor(props, context) {
super(props, context);
t.equal(
Expand Down Expand Up @@ -51,7 +53,7 @@ tape('Preparing a sync app with nested children', t => {
let numConstructors = 0;
let numRenders = 0;
let numChildRenders = 0;
class SimpleComponent extends Component {
class SimpleComponent extends Component<any> {
constructor(props, context) {
super(props, context);
t.equal(
Expand Down Expand Up @@ -134,7 +136,7 @@ tape('Preparing an async app', t => {
let numRenders = 0;
let numChildRenders = 0;
let numPrepares = 0;
class SimpleComponent extends Component {
class SimpleComponent extends Component<any> {
constructor(props, context) {
super(props, context);
t.equal(
Expand Down Expand Up @@ -179,7 +181,7 @@ tape('Preparing an async app with nested asyncs', t => {
let numRenders = 0;
let numChildRenders = 0;
let numPrepares = 0;
class SimpleComponent extends Component {
class SimpleComponent extends Component<any> {
constructor(props, context) {
super(props, context);
t.equal(
Expand Down Expand Up @@ -236,7 +238,7 @@ tape('Preparing an app with sibling async components', t => {
let numRenders = 0;
let numChildRenders = 0;
let numPrepares = 0;
class SimpleComponent extends Component {
class SimpleComponent extends Component<any> {
constructor(props, context) {
super(props, context);
t.equal(
Expand Down Expand Up @@ -299,7 +301,7 @@ tape('Rendering a component triggers componentWillMount before render', t => {
const orderedMethodCalls = [];
const orderedChildMethodCalls = [];

class SimpleComponent extends Component {
class SimpleComponent extends Component<any> {
componentWillMount() {
orderedMethodCalls.push('componentWillMount');
}
Expand All @@ -310,7 +312,7 @@ tape('Rendering a component triggers componentWillMount before render', t => {
}
}

class SimpleChildComponent extends Component {
class SimpleChildComponent extends Component<any> {
componentWillMount() {
orderedChildMethodCalls.push('componentWillMount');
}
Expand All @@ -336,7 +338,7 @@ tape('Preparing an async app with componentWillReceiveProps option', t => {
let numRenders = 0;
let numChildRenders = 0;
let numPrepares = 0;
class SimpleComponent extends Component {
class SimpleComponent extends Component<any> {
constructor(props, context) {
super(props, context);
t.equal(
Expand Down Expand Up @@ -392,7 +394,7 @@ tape('Preparing an async app with componentDidUpdate option', t => {
let numRenders = 0;
let numChildRenders = 0;
let numPrepares = 0;
class SimpleComponent extends Component {
class SimpleComponent extends Component<any> {
constructor(props, context) {
super(props, context);
t.equal(
Expand Down Expand Up @@ -445,6 +447,7 @@ tape('Preparing an async app with componentDidUpdate option', t => {

tape('Preparing a Fragment', t => {
const app = (
// $FlowFixMe
<React.Fragment>
<span>1</span>
<span>2</span>
Expand Down Expand Up @@ -476,6 +479,7 @@ tape('Preparing a fragment with async children', t => {
return Promise.resolve();
})(SimplePresentational);
const app = (
// $FlowFixMe
<React.Fragment>
<AsyncChild data="test" />
<AsyncChild data="test" />
Expand All @@ -491,6 +495,7 @@ tape('Preparing a fragment with async children', t => {
});

tape('Preparing React.createContext()', t => {
// $FlowFixMe
const {Provider, Consumer} = React.createContext('light');

const app = (
Expand All @@ -511,6 +516,7 @@ tape('Preparing React.createContext()', t => {
});

tape('Preparing React.createContext() with async children', t => {
// $FlowFixMe
const {Provider, Consumer} = React.createContext('light');

let numChildRenders = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/__node__/split.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

/* eslint-disable react/no-multi-comp */
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/index.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

/* eslint-env node */
Expand Down
Loading

0 comments on commit 06f2ad5

Please sign in to comment.