├── .gitignore ├── .prettierignore ├── .travis.yml ├── src ├── react-dom │ ├── server.js │ ├── server.node.js │ ├── test-utils.js │ ├── server.browser.js │ ├── unstable-native-dependencies.js │ ├── README.md │ ├── LICENSE │ ├── index.js │ ├── cjs │ │ ├── react-dom-test-utils.production.min.js │ │ ├── react-dom-unstable-native-dependencies.production.min.js │ │ ├── react-dom-server.browser.production.min.js │ │ └── react-dom-server.node.production.min.js │ └── umd │ │ ├── react-dom-test-utils.production.min.js │ │ ├── react-dom-unstable-native-dependencies.production.min.js │ │ └── react-dom-server.browser.production.min.js ├── enzyme-adapter-react-16 │ ├── index.js │ ├── findCurrentFiberUsingSlowPath.js │ └── detectFiberTags.js └── tasks │ ├── legacy.js │ ├── index.js │ ├── index.d.ts │ ├── global.js │ ├── redux.js │ ├── test-utils.js │ └── core.js ├── .babelrc ├── .prettierrc ├── .npmignore ├── .flowconfig ├── flow-typed └── npm │ ├── flow-bin_v0.x.x.js │ ├── babel-preset-flow_vx.x.x.js │ ├── redux_v4.x.x.js │ ├── babel-preset-env_vx.x.x.js │ ├── babel-cli_vx.x.x.js │ ├── sinon_vx.x.x.js │ └── jest_v22.x.x.js ├── CHANGELOG.md ├── LICENSE.md ├── test ├── fixtures.js ├── task.spec.js └── combinators.spec.js ├── package.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | *.log 3 | node_modules/ 4 | .idea/ 5 | .vscode -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | *.md 2 | flow-typed/* 3 | *.json 4 | .travis.yml 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 8 4 | - 10 5 | -------------------------------------------------------------------------------- /src/react-dom/server.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = require('./server.node'); 4 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env", "@babel/preset-react", "@babel/preset-flow"] 3 | } 4 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "flow", 3 | "bracketSpacing": false, 4 | "singleQuote": true 5 | } 6 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | 3 | src/ 4 | test/ 5 | bin/ 6 | docs/ 7 | example/ 8 | 9 | .gitignore 10 | -------------------------------------------------------------------------------- /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | .*/coverage/* 3 | .*/node_modules/* 4 | 5 | [include] 6 | 7 | [libs] 8 | 9 | [options] 10 | -------------------------------------------------------------------------------- /src/enzyme-adapter-react-16/index.js: -------------------------------------------------------------------------------- 1 | /* eslint global-require: 0 */ 2 | module.exports = require('./ReactSixteenAdapter'); 3 | -------------------------------------------------------------------------------- /flow-typed/npm/flow-bin_v0.x.x.js: -------------------------------------------------------------------------------- 1 | // flow-typed signature: 6a5610678d4b01e13bbfbbc62bdaf583 2 | // flow-typed version: 3817bc6980/flow-bin_v0.x.x/flow_>=v0.25.x 3 | 4 | declare module "flow-bin" { 5 | declare module.exports: string; 6 | } 7 | -------------------------------------------------------------------------------- /src/react-dom/server.node.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | if (process.env.NODE_ENV === 'production') { 4 | module.exports = require('./cjs/react-dom-server.node.production.min.js'); 5 | } else { 6 | module.exports = require('./cjs/react-dom-server.node.development.js'); 7 | } 8 | -------------------------------------------------------------------------------- /src/react-dom/test-utils.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | if (process.env.NODE_ENV === 'production') { 4 | module.exports = require('./cjs/react-dom-test-utils.production.min.js'); 5 | } else { 6 | module.exports = require('./cjs/react-dom-test-utils.development.js'); 7 | } 8 | -------------------------------------------------------------------------------- /src/react-dom/server.browser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | if (process.env.NODE_ENV === 'production') { 4 | module.exports = require('./cjs/react-dom-server.browser.production.min.js'); 5 | } else { 6 | module.exports = require('./cjs/react-dom-server.browser.development.js'); 7 | } 8 | -------------------------------------------------------------------------------- /src/react-dom/unstable-native-dependencies.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | if (process.env.NODE_ENV === 'production') { 4 | module.exports = require('./cjs/react-dom-unstable-native-dependencies.production.min.js'); 5 | } else { 6 | module.exports = require('./cjs/react-dom-unstable-native-dependencies.development.js'); 7 | } 8 | -------------------------------------------------------------------------------- /src/react-dom/README.md: -------------------------------------------------------------------------------- 1 | # This is a custom build of the react-dom library 2 | 3 | It includes a patch which adds a listener for values returned from 4 | event listeners. 5 | 6 | - [A link to the original patch](https://github.com/btford/react/commit/0ea9ce066f3e25e73757bc745bf54f3dd565c94c) 7 | - [Latest patch](https://github.com/chrisirhc/react/compare/v16.8.4...chrisirhc:feat-event-bus-react-16.8.4) -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | ## [3.3.4] - Aug 31 2020 3 | - b8ef6ae add onProgress to fromPromiseWithProgress payload 4 | 5 | ## [3.3.3] - Aug 31 2020 6 | - 21897f7 export fromPromiseWithProgress 7 | 8 | ## [3.3.2] - Aug 31 2020 9 | - 0c66add feat(redux): bind onProgress to dispatch (#46) 10 | - 2747f88 docs: Improve API examples in the README 11 | - e83e857 add more details to README, add typescript types 12 | - 7431f2d docs: remove scary thing in the readme -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019 Brian Ford 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /flow-typed/npm/babel-preset-flow_vx.x.x.js: -------------------------------------------------------------------------------- 1 | // flow-typed signature: c1f018f24631f97a8c7cd17bd7539e2f 2 | // flow-typed version: <>/babel-preset-flow_v^6.23.0/flow_v0.66.0 3 | 4 | /** 5 | * This is an autogenerated libdef stub for: 6 | * 7 | * 'babel-preset-flow' 8 | * 9 | * Fill this stub out by replacing all the `any` types. 10 | * 11 | * Once filled out, we encourage you to share your work with the 12 | * community by sending a pull request to: 13 | * https://github.com/flowtype/flow-typed 14 | */ 15 | 16 | declare module 'babel-preset-flow' { 17 | declare module.exports: any; 18 | } 19 | 20 | /** 21 | * We include stubs for each file inside this npm package in case you need to 22 | * require those files directly. Feel free to delete any files that aren't 23 | * needed. 24 | */ 25 | declare module 'babel-preset-flow/lib/index' { 26 | declare module.exports: any; 27 | } 28 | 29 | // Filename aliases 30 | declare module 'babel-preset-flow/lib/index.js' { 31 | declare module.exports: $Exports<'babel-preset-flow/lib/index'>; 32 | } 33 | -------------------------------------------------------------------------------- /src/tasks/legacy.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import {taskCreator_, type Task} from './core'; 3 | 4 | /** 5 | * # Legacy APIs 6 | * 7 | * These are provided as a stop-gap to avoid breaking changes. 8 | * They are currently re-exported by default, but that will 9 | * probaby change in the future. 10 | */ 11 | 12 | /** 13 | * ## `taskCreator` 14 | * 15 | * Given a function: `(arg, successCb, errorCb) => any` 16 | * Returns a task creator function: `(arg) => Task`. 17 | * 18 | * This API is a bit cumbersome. 19 | * You probably want to use `Task.fromCallback` or `Task.fromPromise` instead, 20 | * which do the same thing but with less boilerplate. 21 | */ 22 | export function taskCreator( 23 | fn: (Arg, (Inbound) => mixed, (ErrorT) => mixed) => mixed, 24 | label: string 25 | ): Arg => Task { 26 | const creator = (outbound: Arg) => 27 | taskCreator_( 28 | (success, error) => fn(outbound, success, error), 29 | outbound, 30 | label 31 | ); 32 | 33 | creator.type = label; 34 | 35 | return creator; 36 | } 37 | -------------------------------------------------------------------------------- /src/tasks/index.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import { 3 | all, 4 | allSettled, 5 | fromCallback, 6 | fromPromise, 7 | fromPromiseWithProgress 8 | } from './core'; 9 | export {reportTasksForTesting} from './core'; 10 | export type { 11 | Task, 12 | TaskCreator, 13 | AnyTask, 14 | AnyTasks, 15 | MixedTask, 16 | MixedTasks, 17 | EffectReport 18 | } from './core'; 19 | 20 | // export individual functions 21 | export { 22 | all, 23 | allSettled, 24 | fromCallback, 25 | fromPromise, 26 | fromPromiseWithProgress 27 | } from './core'; 28 | 29 | export {taskCreator} from './legacy'; 30 | export { 31 | taskMiddleware, 32 | withTask, 33 | withTasks, 34 | disableStackCapturing 35 | } from './redux'; 36 | 37 | export {getGlobalTaskQueue} from './global'; 38 | // In the future, test utils will not be exported from 39 | // this main bundle 40 | export * from './test-utils'; 41 | 42 | // ``` 43 | // import {Task} from 'react-palm/tasks'; 44 | // Task.all([...]) 45 | // ``` 46 | 47 | export const Tasks = { 48 | all, 49 | allSettled, 50 | fromCallback, 51 | fromPromise, 52 | fromPromiseWithProgress 53 | }; 54 | 55 | export default Tasks; 56 | -------------------------------------------------------------------------------- /src/react-dom/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Facebook, Inc. and its affiliates. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /test/fixtures.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import Task, { 3 | taskMiddleware, 4 | taskCreator, 5 | drainTasksForTesting 6 | } from '../src/tasks'; 7 | 8 | import {createStore, applyMiddleware, type Reducer, type Store} from 'redux'; 9 | 10 | export const ECHO_TASK = taskCreator( 11 | (payload, success) => success(payload), 12 | 'ECHO_TASK' 13 | ); 14 | 15 | // sync set task 16 | export const SET_TASK_SYNC = taskCreator( 17 | (payload, success) => success(payload), 18 | 'SET_TASK_SYNC' 19 | ); 20 | 21 | // async set task 22 | export const SET_TASK_ASYNC = taskCreator( 23 | (payload, success) => 24 | new Promise(resolve => { 25 | setTimeout(() => { 26 | success(payload); 27 | resolve(); 28 | }, 0); 29 | }), 30 | 'SET_TASK_ASYNC' 31 | ); 32 | 33 | // action creators 34 | export const ADD = (payload: number) => ({type: ADD, payload}); 35 | export const SET_SYNC = (payload: any) => ({type: SET_SYNC, payload}); 36 | export const SET_ASYNC = (payload: any) => ({type: SET_ASYNC, payload}); 37 | export const SET_SUCCESS = (payload: any) => ({type: SET_SUCCESS, payload}); 38 | export const BAD = () => ({type: BAD, payload: {}}); 39 | 40 | export function taskStore(reducer: Reducer): Store { 41 | return (createStore(reducer, applyMiddleware(taskMiddleware)): any); 42 | } 43 | -------------------------------------------------------------------------------- /src/react-dom/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | function checkDCE() { 4 | /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ 5 | if ( 6 | typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined' || 7 | typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE !== 'function' 8 | ) { 9 | return; 10 | } 11 | if (process.env.NODE_ENV !== 'production') { 12 | // This branch is unreachable because this function is only called 13 | // in production, but the condition is true only in development. 14 | // Therefore if the branch is still here, dead code elimination wasn't 15 | // properly applied. 16 | // Don't change the message. React DevTools relies on it. Also make sure 17 | // this message doesn't occur elsewhere in this function, or it will cause 18 | // a false positive. 19 | throw new Error('^_^'); 20 | } 21 | try { 22 | // Verify that the code above has been dead code eliminated (DCE'd). 23 | __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(checkDCE); 24 | } catch (err) { 25 | // DevTools shouldn't crash React, no matter what. 26 | // We should still report in case we break this code. 27 | console.error(err); 28 | } 29 | } 30 | 31 | if (process.env.NODE_ENV === 'production') { 32 | // DCE check should happen before ReactDOM bundle executes so that 33 | // DevTools can report bad minification during injection. 34 | checkDCE(); 35 | module.exports = require('./cjs/react-dom.production.min.js'); 36 | } else { 37 | module.exports = require('./cjs/react-dom.development.js'); 38 | } 39 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-palm", 3 | "version": "3.3.11", 4 | "description": "Elm-like architecture for React apps", 5 | "main": "dist/src", 6 | "homepage": "https://github.com/btford/react-palm", 7 | "scripts": { 8 | "build": "rm -rf dist && babel src --out-dir dist && flow-copy-source -v src/ dist && cp package.json ./dist && cp LICENSE.md ./dist", 9 | "test": "jest", 10 | "precommit": "pretty-quick --staged" 11 | }, 12 | "keywords": [ 13 | "react", 14 | "redux", 15 | "elm", 16 | "tasks", 17 | "side-effects" 18 | ], 19 | "author": "Brian Ford ", 20 | "repository": { 21 | "type": "git", 22 | "url": "git+https://github.com/btford/react-palm.git" 23 | }, 24 | "license": "MIT", 25 | "dependencies": { 26 | "function.prototype.name": "^1.1.0", 27 | "react-dom": "^16.4.2", 28 | "react-reconciler": "^0.12.0", 29 | "react-test-renderer": "^16.4.2" 30 | }, 31 | "devDependencies": { 32 | "@babel/cli": "7.2.3", 33 | "@babel/core": "7.4.0", 34 | "@babel/preset-env": "7.4.2", 35 | "@babel/preset-flow": "7.0.0", 36 | "@babel/preset-react": "7.0.0", 37 | "flow-bin": "0.95.1", 38 | "flow-copy-source": "^1.3.0", 39 | "husky": "^0.14.3", 40 | "jest": "^24.5.0", 41 | "prettier": "1.16.4", 42 | "pretty-quick": "^1.4.1", 43 | "react": "^16.4.2", 44 | "redux": "4.0.1", 45 | "sinon": "^1.17.4" 46 | }, 47 | "peerDependencies": { 48 | "enzyme": "^3.6.0", 49 | "enzyme-adapter-utils": "^1.13.0", 50 | "react": "^16.4.1", 51 | "react-test-renderer": "^16.4.1" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/tasks/index.d.ts: -------------------------------------------------------------------------------- 1 | export type Task = { 2 | type: string, 3 | 4 | map: (onSuccess: (res: Success) => NextSuccess) => Task, 5 | 6 | bimap: (onSuccess: (res: Success) => NextSuccess, onError: (err: Failure) => NextFailure) => 7 | Task, 8 | 9 | chain: (next: (res: Success) => Task) => 10 | Task 11 | }; 12 | 13 | 14 | export declare function fromCallback(fn: (arg: void, cb: () => void) => void, type: string): () => Task; 15 | export declare function fromCallback(fn: (arg: Arg, cb: () => void) => void, type: string): (arg: Arg) => Task; 16 | export declare function fromCallback(fn: (arg: void, cb: (err: Failure | null, res: Success | null) => void) => void, type: string): () => Task; 17 | export declare function fromCallback(fn: (arg: Arg, cb: (err: Failure | null, res: Success | null) => void) => void, type: string): (arg: Arg) => Task; 18 | 19 | export declare function fromPromise(fn: (arg: Arg) => Promise, type: string): (arg: Arg) => Task; 20 | 21 | export declare function withTask(state: State, task: Task | Task[]): State; 22 | export declare function withTasks(state: State, tasks: Task[]): State; 23 | 24 | export declare function disableStackCapturing(): void; 25 | 26 | export declare function all(tasks: Task[]): Task; 27 | 28 | export declare function getGlobalTaskQueue(): Task[]; 29 | -------------------------------------------------------------------------------- /src/tasks/global.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import type {Task, AnyTasks} from './core'; 3 | /** 4 | * For apps using Redux, we provide `withTasks` for `lift`ing tasks 5 | * out of a "sub-reducer" into the top-level app's space. This helps remove 6 | * extra plumbing that would potentially add boilerplate. 7 | * 8 | * To support this, we create a global record to collect tasks (and debug info). 9 | * Although this queue is global, we reset it between dispatches to the store. 10 | * You can think of this queue as a "thread local." 11 | * 12 | * We also want to make sure that if multiple versions of react-palm are loaded, 13 | * that we're able to have just a single queue. 14 | * 15 | * End users should not use any of these APIs directly. Instead, use the 16 | * redux middleware. 17 | */ 18 | 19 | // We attach an object to `window` or `global` with this name. 20 | // This is probably unique enough to avoid collision. 21 | const GLOBAL_TASK_STATE: '___GLOBAL_TASK_STATE_e3b0c442' = 22 | '___GLOBAL_TASK_STATE_e3b0c442'; 23 | 24 | type TaskGlobals = { 25 | tasks: AnyTasks, 26 | lastWithTaskCall: Error | null 27 | }; 28 | 29 | // Try to determine the object representing the global namespace. 30 | // As a fallback, create a new object within this module. 31 | const GLOBAL: { 32 | +[typeof GLOBAL_TASK_STATE]: TaskGlobals 33 | } = 34 | typeof window !== 'undefined' 35 | ? window 36 | : typeof global !== 'undefined' ? global : {}; 37 | 38 | if (typeof GLOBAL[GLOBAL_TASK_STATE] !== 'undefined') { 39 | console.warn( 40 | 'More than one copy of react-palm was loaded. This may cause problems.' 41 | ); 42 | } else { 43 | Object.defineProperty(GLOBAL, GLOBAL_TASK_STATE, { 44 | ennumerable: false, 45 | value: { 46 | tasks: [], 47 | lastWithTaskCall: null 48 | } 49 | }); 50 | } 51 | 52 | /* 53 | * Getters and setters used by test utils and redux middlware. 54 | * Again, you probably don't need to ever use these directly. 55 | */ 56 | export function getGlobalTaskQueue(): $ReadOnlyArray> { 57 | return GLOBAL[GLOBAL_TASK_STATE].tasks; 58 | } 59 | 60 | export function updateGlobalTaskQueue(newQueue: AnyTasks): void { 61 | GLOBAL[GLOBAL_TASK_STATE].tasks = newQueue; 62 | } 63 | 64 | export function getLastWithTaskCall(): Error | null { 65 | return GLOBAL[GLOBAL_TASK_STATE].lastWithTaskCall; 66 | } 67 | 68 | export function setLastWithTaskCall(last: Error): void { 69 | GLOBAL[GLOBAL_TASK_STATE].lastWithTaskCall = last; 70 | } 71 | 72 | export function clearLastWithTaskCall(): void { 73 | GLOBAL[GLOBAL_TASK_STATE].lastWithTaskCall = null; 74 | } 75 | -------------------------------------------------------------------------------- /flow-typed/npm/redux_v4.x.x.js: -------------------------------------------------------------------------------- 1 | // flow-typed signature: df80bdd535bfed9cf3223e077f3b4543 2 | // flow-typed version: c4c8963c9c/redux_v4.x.x/flow_>=v0.55.x 3 | 4 | declare module 'redux' { 5 | 6 | /* 7 | 8 | S = State 9 | A = Action 10 | D = Dispatch 11 | 12 | */ 13 | 14 | declare export type DispatchAPI = (action: A) => A; 15 | declare export type Dispatch }> = DispatchAPI; 16 | 17 | declare export type MiddlewareAPI> = { 18 | dispatch: D; 19 | getState(): S; 20 | }; 21 | 22 | declare export type Store> = { 23 | // rewrite MiddlewareAPI members in order to get nicer error messages (intersections produce long messages) 24 | dispatch: D; 25 | getState(): S; 26 | subscribe(listener: () => void): () => void; 27 | replaceReducer(nextReducer: Reducer): void 28 | }; 29 | 30 | declare export type Reducer = (state: S | void, action: A) => S; 31 | 32 | declare export type CombinedReducer = (state: $Shape & {} | void, action: A) => S; 33 | 34 | declare export type Middleware> = 35 | (api: MiddlewareAPI) => 36 | (next: D) => D; 37 | 38 | declare export type StoreCreator> = { 39 | (reducer: Reducer, enhancer?: StoreEnhancer): Store; 40 | (reducer: Reducer, preloadedState: S, enhancer?: StoreEnhancer): Store; 41 | }; 42 | 43 | declare export type StoreEnhancer> = (next: StoreCreator) => StoreCreator; 44 | 45 | declare export function createStore(reducer: Reducer, enhancer?: StoreEnhancer): Store; 46 | declare export function createStore(reducer: Reducer, preloadedState?: S, enhancer?: StoreEnhancer): Store; 47 | 48 | declare export function applyMiddleware(...middlewares: Array>): StoreEnhancer; 49 | 50 | declare export type ActionCreator = (...args: Array) => A; 51 | declare export type ActionCreators = { [key: K]: ActionCreator }; 52 | 53 | declare export function bindActionCreators, D: DispatchAPI>(actionCreator: C, dispatch: D): C; 54 | declare export function bindActionCreators, D: DispatchAPI>(actionCreators: C, dispatch: D): C; 55 | 56 | declare export function combineReducers(reducers: O): CombinedReducer<$ObjMap(r: Reducer) => S>, A>; 57 | 58 | declare export var compose: $Compose; 59 | } 60 | -------------------------------------------------------------------------------- /flow-typed/npm/babel-preset-env_vx.x.x.js: -------------------------------------------------------------------------------- 1 | // flow-typed signature: 5a1a4dec7379a9f707ffd1d9fcd89697 2 | // flow-typed version: <>/babel-preset-env_v^1.6.1/flow_v0.66.0 3 | 4 | /** 5 | * This is an autogenerated libdef stub for: 6 | * 7 | * 'babel-preset-env' 8 | * 9 | * Fill this stub out by replacing all the `any` types. 10 | * 11 | * Once filled out, we encourage you to share your work with the 12 | * community by sending a pull request to: 13 | * https://github.com/flowtype/flow-typed 14 | */ 15 | 16 | declare module 'babel-preset-env' { 17 | declare module.exports: any; 18 | } 19 | 20 | /** 21 | * We include stubs for each file inside this npm package in case you need to 22 | * require those files directly. Feel free to delete any files that aren't 23 | * needed. 24 | */ 25 | declare module 'babel-preset-env/data/built-in-features' { 26 | declare module.exports: any; 27 | } 28 | 29 | declare module 'babel-preset-env/data/plugin-features' { 30 | declare module.exports: any; 31 | } 32 | 33 | declare module 'babel-preset-env/lib/default-includes' { 34 | declare module.exports: any; 35 | } 36 | 37 | declare module 'babel-preset-env/lib/index' { 38 | declare module.exports: any; 39 | } 40 | 41 | declare module 'babel-preset-env/lib/module-transformations' { 42 | declare module.exports: any; 43 | } 44 | 45 | declare module 'babel-preset-env/lib/normalize-options' { 46 | declare module.exports: any; 47 | } 48 | 49 | declare module 'babel-preset-env/lib/targets-parser' { 50 | declare module.exports: any; 51 | } 52 | 53 | declare module 'babel-preset-env/lib/transform-polyfill-require-plugin' { 54 | declare module.exports: any; 55 | } 56 | 57 | declare module 'babel-preset-env/lib/utils' { 58 | declare module.exports: any; 59 | } 60 | 61 | // Filename aliases 62 | declare module 'babel-preset-env/data/built-in-features.js' { 63 | declare module.exports: $Exports<'babel-preset-env/data/built-in-features'>; 64 | } 65 | declare module 'babel-preset-env/data/plugin-features.js' { 66 | declare module.exports: $Exports<'babel-preset-env/data/plugin-features'>; 67 | } 68 | declare module 'babel-preset-env/lib/default-includes.js' { 69 | declare module.exports: $Exports<'babel-preset-env/lib/default-includes'>; 70 | } 71 | declare module 'babel-preset-env/lib/index.js' { 72 | declare module.exports: $Exports<'babel-preset-env/lib/index'>; 73 | } 74 | declare module 'babel-preset-env/lib/module-transformations.js' { 75 | declare module.exports: $Exports<'babel-preset-env/lib/module-transformations'>; 76 | } 77 | declare module 'babel-preset-env/lib/normalize-options.js' { 78 | declare module.exports: $Exports<'babel-preset-env/lib/normalize-options'>; 79 | } 80 | declare module 'babel-preset-env/lib/targets-parser.js' { 81 | declare module.exports: $Exports<'babel-preset-env/lib/targets-parser'>; 82 | } 83 | declare module 'babel-preset-env/lib/transform-polyfill-require-plugin.js' { 84 | declare module.exports: $Exports<'babel-preset-env/lib/transform-polyfill-require-plugin'>; 85 | } 86 | declare module 'babel-preset-env/lib/utils.js' { 87 | declare module.exports: $Exports<'babel-preset-env/lib/utils'>; 88 | } 89 | -------------------------------------------------------------------------------- /flow-typed/npm/babel-cli_vx.x.x.js: -------------------------------------------------------------------------------- 1 | // flow-typed signature: 904df3d3f1a067e0190edaa0e695a96e 2 | // flow-typed version: <>/babel-cli_v^6.26.0/flow_v0.66.0 3 | 4 | /** 5 | * This is an autogenerated libdef stub for: 6 | * 7 | * 'babel-cli' 8 | * 9 | * Fill this stub out by replacing all the `any` types. 10 | * 11 | * Once filled out, we encourage you to share your work with the 12 | * community by sending a pull request to: 13 | * https://github.com/flowtype/flow-typed 14 | */ 15 | 16 | declare module 'babel-cli' { 17 | declare module.exports: any; 18 | } 19 | 20 | /** 21 | * We include stubs for each file inside this npm package in case you need to 22 | * require those files directly. Feel free to delete any files that aren't 23 | * needed. 24 | */ 25 | declare module 'babel-cli/bin/babel-doctor' { 26 | declare module.exports: any; 27 | } 28 | 29 | declare module 'babel-cli/bin/babel-external-helpers' { 30 | declare module.exports: any; 31 | } 32 | 33 | declare module 'babel-cli/bin/babel-node' { 34 | declare module.exports: any; 35 | } 36 | 37 | declare module 'babel-cli/bin/babel' { 38 | declare module.exports: any; 39 | } 40 | 41 | declare module 'babel-cli/lib/_babel-node' { 42 | declare module.exports: any; 43 | } 44 | 45 | declare module 'babel-cli/lib/babel-external-helpers' { 46 | declare module.exports: any; 47 | } 48 | 49 | declare module 'babel-cli/lib/babel-node' { 50 | declare module.exports: any; 51 | } 52 | 53 | declare module 'babel-cli/lib/babel/dir' { 54 | declare module.exports: any; 55 | } 56 | 57 | declare module 'babel-cli/lib/babel/file' { 58 | declare module.exports: any; 59 | } 60 | 61 | declare module 'babel-cli/lib/babel/index' { 62 | declare module.exports: any; 63 | } 64 | 65 | declare module 'babel-cli/lib/babel/util' { 66 | declare module.exports: any; 67 | } 68 | 69 | // Filename aliases 70 | declare module 'babel-cli/bin/babel-doctor.js' { 71 | declare module.exports: $Exports<'babel-cli/bin/babel-doctor'>; 72 | } 73 | declare module 'babel-cli/bin/babel-external-helpers.js' { 74 | declare module.exports: $Exports<'babel-cli/bin/babel-external-helpers'>; 75 | } 76 | declare module 'babel-cli/bin/babel-node.js' { 77 | declare module.exports: $Exports<'babel-cli/bin/babel-node'>; 78 | } 79 | declare module 'babel-cli/bin/babel.js' { 80 | declare module.exports: $Exports<'babel-cli/bin/babel'>; 81 | } 82 | declare module 'babel-cli/index' { 83 | declare module.exports: $Exports<'babel-cli'>; 84 | } 85 | declare module 'babel-cli/index.js' { 86 | declare module.exports: $Exports<'babel-cli'>; 87 | } 88 | declare module 'babel-cli/lib/_babel-node.js' { 89 | declare module.exports: $Exports<'babel-cli/lib/_babel-node'>; 90 | } 91 | declare module 'babel-cli/lib/babel-external-helpers.js' { 92 | declare module.exports: $Exports<'babel-cli/lib/babel-external-helpers'>; 93 | } 94 | declare module 'babel-cli/lib/babel-node.js' { 95 | declare module.exports: $Exports<'babel-cli/lib/babel-node'>; 96 | } 97 | declare module 'babel-cli/lib/babel/dir.js' { 98 | declare module.exports: $Exports<'babel-cli/lib/babel/dir'>; 99 | } 100 | declare module 'babel-cli/lib/babel/file.js' { 101 | declare module.exports: $Exports<'babel-cli/lib/babel/file'>; 102 | } 103 | declare module 'babel-cli/lib/babel/index.js' { 104 | declare module.exports: $Exports<'babel-cli/lib/babel/index'>; 105 | } 106 | declare module 'babel-cli/lib/babel/util.js' { 107 | declare module.exports: $Exports<'babel-cli/lib/babel/util'>; 108 | } 109 | -------------------------------------------------------------------------------- /test/task.spec.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import {spy} from 'sinon'; 3 | 4 | import { 5 | taskMiddleware, 6 | withTask, 7 | withTasks, 8 | taskCreator, 9 | drainTasksForTesting 10 | } from '../src/tasks'; 11 | 12 | import {taskStore, SET_TASK_SYNC, SET_TASK_ASYNC} from './fixtures'; 13 | 14 | // tasks 15 | const xhrHandlerSpy = spy(); 16 | const XHR_TASK = taskCreator(xhrHandlerSpy, 'XHR_TASK'); 17 | 18 | const ADD = payload => ({type: ADD, payload}); 19 | const SET_SYNC = payload => ({type: SET_SYNC, payload}); 20 | const SET_ASYNC = payload => ({type: SET_ASYNC, payload}); 21 | const SET_SUCCESS = payload => ({type: SET_SUCCESS, payload}); 22 | const BAD = () => ({type: BAD, payload: {}}); 23 | 24 | export const reducer = ( 25 | state?: number = 0, 26 | action: {type: string, payload: any} 27 | ) => { 28 | const {payload} = action; 29 | 30 | switch (action.type) { 31 | case ADD: 32 | const newAmount = state + payload; 33 | return withTasks(newAmount, [XHR_TASK(newAmount)]); 34 | case SET_SYNC: 35 | return withTasks(state, [SET_TASK_SYNC(payload).map(SET_SUCCESS)]); 36 | case SET_ASYNC: 37 | return withTasks(state, [SET_TASK_ASYNC(payload).map(SET_SUCCESS)]); 38 | case SET_SUCCESS: 39 | return payload; 40 | case BAD: 41 | return withTask(state, (BAD(): any)); 42 | default: 43 | return state; 44 | } 45 | }; 46 | 47 | test('Task middleware runs handlers', () => { 48 | const store = taskStore(reducer); 49 | store.dispatch(ADD(3)); 50 | const firstCallFirstArg = xhrHandlerSpy.args[0][0]; 51 | expect(firstCallFirstArg).toBe(3); 52 | expect(store.getState()).toBe(3); 53 | 54 | // the middleware should consume all of the tasks 55 | const tasks = drainTasksForTesting(); 56 | expect(tasks).toEqual([]); 57 | }); 58 | 59 | test('Task middleware throws when task not created properly', () => { 60 | const store = taskStore(reducer); 61 | expect(() => store.dispatch(BAD())).toThrowError( 62 | `Attempted to run something that is not a task.` 63 | ); 64 | }); 65 | 66 | test('Task middleware throws when tasks were added incorrectly', () => { 67 | const store = taskStore(reducer); 68 | 69 | const incorrectTaskAdd = () => withTask(null, XHR_TASK('test123')); 70 | 71 | incorrectTaskAdd(); 72 | expect(() => store.dispatch(ADD(3))).toThrowError( 73 | `Tasks should not be added outside of reducers.` 74 | ); 75 | 76 | drainTasksForTesting(); 77 | let stack = ''; 78 | 79 | try { 80 | incorrectTaskAdd(); 81 | store.dispatch(ADD(3)); 82 | } catch (e) { 83 | stack = e.stack; 84 | } 85 | 86 | expect(stack).toMatch(/incorrectTaskAdd/); 87 | 88 | drainTasksForTesting(); 89 | }); 90 | 91 | test('Task middleware works with sync task handler', () => { 92 | const store = taskStore(reducer); 93 | 94 | expect(store.getState()).toBe(0); 95 | store.dispatch(SET_SYNC(42)); 96 | 97 | // Fake tick to wait for the dispatchAsync to be finished 98 | setTimeout(() => { 99 | expect(store.getState()).toBe(42); 100 | }); 101 | 102 | const tasks = drainTasksForTesting(); 103 | expect(tasks).toEqual([]); 104 | }); 105 | 106 | test('Task middleware works with async task handler', () => { 107 | const store = taskStore(reducer); 108 | 109 | expect(store.getState()).toBe(0); 110 | const promise = store.dispatch(SET_ASYNC(43)); 111 | 112 | expect(store.getState()).toBe(0); 113 | 114 | const tasks = drainTasksForTesting(); 115 | expect(tasks).toEqual([]); 116 | 117 | promise.then(() => { 118 | expect(store.getState()).toBe(43); 119 | }); 120 | }); 121 | -------------------------------------------------------------------------------- /src/enzyme-adapter-react-16/findCurrentFiberUsingSlowPath.js: -------------------------------------------------------------------------------- 1 | // Extracted from https://github.com/facebook/react/blob/7bdf93b17a35a5d8fcf0ceae0bf48ed5e6b16688/src/renderers/shared/fiber/ReactFiberTreeReflection.js#L104-L228 2 | function findCurrentFiberUsingSlowPath(fiber) { 3 | const { alternate } = fiber; 4 | if (!alternate) { 5 | return fiber; 6 | } 7 | // If we have two possible branches, we'll walk backwards up to the root 8 | // to see what path the root points to. On the way we may hit one of the 9 | // special cases and we'll deal with them. 10 | let a = fiber; 11 | let b = alternate; 12 | while (true) { // eslint-disable-line 13 | const parentA = a.return; 14 | const parentB = parentA ? parentA.alternate : null; 15 | if (!parentA || !parentB) { 16 | // We're at the root. 17 | break; 18 | } 19 | 20 | // If both copies of the parent fiber point to the same child, we can 21 | // assume that the child is current. This happens when we bailout on low 22 | // priority: the bailed out fiber's child reuses the current child. 23 | if (parentA.child === parentB.child) { 24 | let { child } = parentA; 25 | while (child) { 26 | if (child === a) { 27 | // We've determined that A is the current branch. 28 | return fiber; 29 | } 30 | if (child === b) { 31 | // We've determined that B is the current branch. 32 | return alternate; 33 | } 34 | child = child.sibling; 35 | } 36 | // We should never have an alternate for any mounting node. So the only 37 | // way this could possibly happen is if this was unmounted, if at all. 38 | throw new Error('Unable to find node on an unmounted component.'); 39 | } 40 | 41 | if (a.return !== b.return) { 42 | // The return pointer of A and the return pointer of B point to different 43 | // fibers. We assume that return pointers never criss-cross, so A must 44 | // belong to the child set of A.return, and B must belong to the child 45 | // set of B.return. 46 | a = parentA; 47 | b = parentB; 48 | } else { 49 | // The return pointers point to the same fiber. We'll have to use the 50 | // default, slow path: scan the child sets of each parent alternate to see 51 | // which child belongs to which set. 52 | // 53 | // Search parent A's child set 54 | let didFindChild = false; 55 | let { child } = parentA; 56 | while (child) { 57 | if (child === a) { 58 | didFindChild = true; 59 | a = parentA; 60 | b = parentB; 61 | break; 62 | } 63 | if (child === b) { 64 | didFindChild = true; 65 | b = parentA; 66 | a = parentB; 67 | break; 68 | } 69 | child = child.sibling; 70 | } 71 | if (!didFindChild) { 72 | // Search parent B's child set 73 | ({ child } = parentB); 74 | while (child) { 75 | if (child === a) { 76 | didFindChild = true; 77 | a = parentB; 78 | b = parentA; 79 | break; 80 | } 81 | if (child === b) { 82 | didFindChild = true; 83 | b = parentB; 84 | a = parentA; 85 | break; 86 | } 87 | child = child.sibling; 88 | } 89 | if (!didFindChild) { 90 | throw new Error('Child was not found in either parent set. This indicates a bug ' 91 | + 'in React related to the return pointer. Please file an issue.'); 92 | } 93 | } 94 | } 95 | } 96 | if (a.stateNode.current === a) { 97 | // We've determined that A is the current branch. 98 | return fiber; 99 | } 100 | // Otherwise B has to be current branch. 101 | return alternate; 102 | } 103 | 104 | module.exports = findCurrentFiberUsingSlowPath; 105 | -------------------------------------------------------------------------------- /src/tasks/redux.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import {type AnyTask, type AnyTasks, _run} from './core'; 3 | import { 4 | getGlobalTaskQueue, 5 | updateGlobalTaskQueue, 6 | clearLastWithTaskCall, 7 | setLastWithTaskCall, 8 | getLastWithTaskCall 9 | } from './global'; 10 | 11 | const CACHED_PROMISE: Promise = Promise.resolve(); 12 | const makeDispatchAsync = (dispatch: Function) => (action: Object) => 13 | CACHED_PROMISE.then(() => dispatch(action)); 14 | 15 | // The way webpack does hot-reloading seems to break the checks we 16 | // do against the stack trace. 17 | const WEBPACK_HOT_RELOAD_ENABLED: boolean = Boolean((module: any).hot); 18 | let enableStackCapture = !WEBPACK_HOT_RELOAD_ENABLED; 19 | const IMPROPER_TASK_USAGE = `Tasks should not be added outside of reducers.`; 20 | 21 | /** 22 | * You need to install this middleware for tasks to have their handlers run. 23 | * 24 | * You probably do not want to use this middleware within your test environment. 25 | * Instead, use `drainTasksForTesting` to retrieve and make assertions about them. 26 | * 27 | * This middleware changes the behavior of `store.dispatch` to return a promise. 28 | * That promise will resolve when all pending tasks for that call to `dispatch` 29 | * have finished (including calls transitively enqueued by tasks that dispatch actions). 30 | */ 31 | export const taskMiddleware = (store: {dispatch: Object => any}) => ( 32 | next: Object => void 33 | ) => (action: Object) => { 34 | // If we begin a call to dispatch with tasks still in the queue, 35 | // we have a problem. 36 | if (enableStackCapture && getGlobalTaskQueue().length > 0) { 37 | const err = getLastWithTaskCall(); 38 | clearLastWithTaskCall(); 39 | throw err; 40 | } 41 | 42 | next(action); 43 | const dispatch = makeDispatchAsync(store.dispatch); 44 | 45 | if (getGlobalTaskQueue().length > 0) { 46 | const taskResolutions = getGlobalTaskQueue().map(runTaskActual(dispatch)); 47 | 48 | updateGlobalTaskQueue([]); 49 | clearLastWithTaskCall(); 50 | return Promise.all(taskResolutions); 51 | } 52 | 53 | return CACHED_PROMISE; 54 | }; 55 | 56 | // Given a function that accepts two continuations (one for success, one for error), 57 | // call the function supplying the provided continuations. 58 | const biApply = (f, s, e, c) => f(s, e, c); 59 | 60 | // Run the task with the proper effect 61 | function runTaskActual(dispatch) { 62 | return function(task: AnyTask) { 63 | // unsafe coerce this because it doesn't matter 64 | return _run( 65 | task, 66 | biApply, 67 | dispatch, 68 | dispatch, 69 | ({onProgress: dispatch}: any) 70 | ); 71 | }; 72 | } 73 | 74 | /** 75 | * Use this function in your reducer to add tasks to an action handler. 76 | * The task will be lifted up to the top of your app. Returns the same 77 | * state object passed into it. 78 | */ 79 | export function withTasks(state: State, tasks: AnyTasks): State { 80 | if (enableStackCapture && !getLastWithTaskCall()) { 81 | setLastWithTaskCall(trace(IMPROPER_TASK_USAGE)); 82 | } 83 | updateGlobalTaskQueue( 84 | getGlobalTaskQueue().concat(tasks instanceof Array ? tasks : [tasks]) 85 | ); 86 | return state; 87 | } 88 | 89 | /** 90 | * A helpful alias for providing just one task. 91 | * `withTask(state, task1)` is the same as `withTasks(state, [task1])`. 92 | */ 93 | export const withTask: ( 94 | state: State, 95 | task: AnyTask 96 | ) => State = (withTasks: any); 97 | 98 | /** 99 | * In order to make it easy to track down incorrect uses for `withTask`, we capture exception 100 | * objects for every call to withTask. This has some performance overhead, so you'll 101 | * probably want to disable it in production. 102 | * 103 | * Note that if you're using Webpack's hot reload, we disable this functionality by default. 104 | */ 105 | export function disableStackCapturing(): void { 106 | enableStackCapture = false; 107 | } 108 | 109 | /* 110 | * Helpers 111 | */ 112 | function trace(message: string): Error { 113 | try { 114 | throw new Error(message); 115 | } catch (e) { 116 | return e; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/enzyme-adapter-react-16/detectFiberTags.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from '../react-dom'; 3 | import { fakeDynamicImport } from 'enzyme-adapter-utils'; 4 | 5 | function getFiber(element) { 6 | const container = global.document.createElement('div'); 7 | let inst = null; 8 | class Tester extends React.Component { 9 | render() { 10 | inst = this; 11 | return element; 12 | } 13 | } 14 | ReactDOM.render(React.createElement(Tester), container); 15 | return inst._reactInternalFiber.child; 16 | } 17 | 18 | function getLazyFiber(LazyComponent) { 19 | const container = global.document.createElement('div'); 20 | let inst = null; 21 | // eslint-disable-next-line react/prefer-stateless-function 22 | class Tester extends React.Component { 23 | render() { 24 | inst = this; 25 | return React.createElement(LazyComponent); 26 | } 27 | } 28 | // eslint-disable-next-line react/prefer-stateless-function 29 | class SuspenseWrapper extends React.Component { 30 | render() { 31 | return React.createElement( 32 | React.Suspense, 33 | { fallback: false }, 34 | React.createElement(Tester), 35 | ); 36 | } 37 | } 38 | ReactDOM.render(React.createElement(SuspenseWrapper), container); 39 | return inst._reactInternalFiber.child; 40 | } 41 | 42 | module.exports = function detectFiberTags() { 43 | const supportsMode = typeof React.StrictMode !== 'undefined'; 44 | const supportsContext = typeof React.createContext !== 'undefined'; 45 | const supportsForwardRef = typeof React.forwardRef !== 'undefined'; 46 | const supportsMemo = typeof React.memo !== 'undefined'; 47 | const supportsProfiler = typeof React.unstable_Profiler !== 'undefined' || typeof React.Profiler !== 'undefined'; 48 | const supportsSuspense = typeof React.Suspense !== 'undefined'; 49 | const supportsLazy = typeof React.lazy !== 'undefined'; 50 | 51 | function Fn() { 52 | return null; 53 | } 54 | // eslint-disable-next-line react/prefer-stateless-function 55 | class Cls extends React.Component { 56 | render() { 57 | return null; 58 | } 59 | } 60 | let Ctx = null; 61 | let FwdRef = null; 62 | let LazyComponent = null; 63 | if (supportsContext) { 64 | Ctx = React.createContext(); 65 | } 66 | if (supportsForwardRef) { 67 | // React will warn if we don't have both arguments. 68 | // eslint-disable-next-line no-unused-vars 69 | FwdRef = React.forwardRef((props, ref) => null); 70 | } 71 | if (supportsLazy) { 72 | LazyComponent = React.lazy(() => fakeDynamicImport(() => null)); 73 | } 74 | 75 | return { 76 | HostRoot: getFiber('test').return.return.tag, // Go two levels above to find the root 77 | ClassComponent: getFiber(React.createElement(Cls)).tag, 78 | Fragment: getFiber([['nested']]).tag, 79 | FunctionalComponent: getFiber(React.createElement(Fn)).tag, 80 | MemoSFC: supportsMemo 81 | ? getFiber(React.createElement(React.memo(Fn))).tag 82 | : -1, 83 | MemoClass: supportsMemo 84 | ? getFiber(React.createElement(React.memo(Cls))).tag 85 | : -1, 86 | HostPortal: getFiber(ReactDOM.createPortal(null, global.document.createElement('div'))).tag, 87 | HostComponent: getFiber(React.createElement('span')).tag, 88 | HostText: getFiber('text').tag, 89 | Mode: supportsMode 90 | ? getFiber(React.createElement(React.StrictMode)).tag 91 | : -1, 92 | ContextConsumer: supportsContext 93 | ? getFiber(React.createElement(Ctx.Consumer, null, () => null)).tag 94 | : -1, 95 | ContextProvider: supportsContext 96 | ? getFiber(React.createElement(Ctx.Provider, { value: null }, null)).tag 97 | : -1, 98 | ForwardRef: supportsForwardRef 99 | ? getFiber(React.createElement(FwdRef)).tag 100 | : -1, 101 | Profiler: supportsProfiler 102 | ? getFiber(React.createElement((React.Profiler || React.unstable_Profiler), { id: 'mock', onRender() {} })).tag 103 | : -1, 104 | Suspense: supportsSuspense 105 | ? getFiber(React.createElement(React.Suspense, { fallback: false })).tag 106 | : -1, 107 | Lazy: supportsLazy 108 | ? getLazyFiber(LazyComponent).tag 109 | : -1, 110 | }; 111 | }; 112 | -------------------------------------------------------------------------------- /src/tasks/test-utils.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import {_run, type Task, type MixedTask, type BiApplicative} from './core'; 3 | import { 4 | getGlobalTaskQueue, 5 | updateGlobalTaskQueue, 6 | clearLastWithTaskCall 7 | } from './global'; 8 | 9 | /** 10 | * # Test Utils 11 | * 12 | * These SHOULD NOT be used in production. 13 | * 14 | * If you want to display information about tasks in your component, 15 | * add that information to your state tree when you create the task. 16 | * 17 | * If you want to get access to the current tasks, do so by returning the 18 | * tasks from helpers, and inspecting them before passing them to `withTask`. 19 | */ 20 | 21 | // A dual to "BiApplicative," but using dummy objects 22 | export type Simulator = ( 23 | DummyEffector, 24 | (Inbound) => mixed, 25 | (InboundError) => mixed 26 | ) => mixed; 27 | 28 | // Although we pass the actual Effector to the Simulator, 29 | // we only expose the type and payload fields. 30 | type DummyEffector = $ReadOnly<{ 31 | type: string, 32 | payload: Arg 33 | }>; 34 | 35 | /** 36 | * Get the resulting value of a task, providing the given value as the inbound result. 37 | * If your task uses `.chain` or `Task.all`, you probably want to use `simulateTask` 38 | * or `succeedTaskWithValues` instead. 39 | */ 40 | export function succeedTaskInTest( 41 | someTask: Task<*, Inbound, *, Result>, 42 | value: Inbound 43 | ): Result { 44 | return _runAndCaptureResult(someTask, (_, s, _e) => s(value)); 45 | } 46 | 47 | /** 48 | * Get the failure value of a task, providing the given value as the inbound error. 49 | * 50 | * If your task uses `.chain` or `Task.all`, you probably want to use `simulateTask` 51 | * instead. 52 | */ 53 | export function errorTaskInTest( 54 | someTask: Task<*, *, InboundError, *, ErrorT>, 55 | value: InboundError 56 | ): ErrorT { 57 | return _runAndCaptureResult(someTask, (_, _s, e) => e(value)); 58 | } 59 | 60 | /** 61 | * Run a task, using `simulator` for bi-application. `simulator` recieves: 62 | * 63 | * 1. an object representing a side-effect with `payload` and `type`. 64 | * 2. a success handler to call with a mocked response. 65 | * 3. an error handler to call with a mocked out response. 66 | * 67 | * A simulator might be called more than once in the case of `Task.all` 68 | * or `task.chain`. 69 | */ 70 | export function simulateTask( 71 | someTask: Task, 72 | simulator: Simulator 73 | ): Result | ErrorT { 74 | return _runAndCaptureResult(someTask, simulator); 75 | } 76 | 77 | /** 78 | * Given some task, and array of values, 79 | */ 80 | export function succeedTaskWithValues( 81 | someTask: Task<*, *, *, Result>, 82 | values: $ReadOnlyArray 83 | ): Result | null { 84 | let index: number = 0; 85 | return _runAndCaptureResult(someTask, (_, s) => { 86 | if (index >= values.length) { 87 | throw new Error('Not enough values were provided!'); 88 | } 89 | const returned = s(values[index]); 90 | index += 1; 91 | return returned; 92 | }); 93 | } 94 | 95 | /** 96 | * This function should only be used in test environments to make assertions about 97 | * tasks as part of the test. Application code should not be mucking around with 98 | * the list of tasks. 99 | * 100 | * If you want to display information about tasks in your component, 101 | * add that information to your state tree when you create the task. 102 | * 103 | * If you want to get access to the current tasks, do so by returning the 104 | * tasks from helpers, and inspecting them before passing them to `withTask`. 105 | */ 106 | export function drainTasksForTesting(): $ReadOnlyArray { 107 | const drained = getGlobalTaskQueue(); 108 | updateGlobalTaskQueue([]); 109 | clearLastWithTaskCall(); 110 | return drained; 111 | } 112 | 113 | function _runAndCaptureResult( 114 | someTask: Task<*, Inbound, InboundError, Result, ErrorT>, 115 | simulator 116 | ): Result | ErrorT { 117 | let returned; 118 | const setReturned = val => { 119 | returned = val; 120 | }; 121 | _run( 122 | someTask, 123 | ((simulator: any): BiApplicative<*, *>), 124 | setReturned, 125 | setReturned 126 | ); 127 | if (typeof returned === 'undefined') { 128 | throw new Error('A success or error handler was never called!'); 129 | } 130 | return returned; 131 | } 132 | -------------------------------------------------------------------------------- /test/combinators.spec.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import Task, { 3 | taskCreator, 4 | succeedTaskInTest, 5 | simulateTask, 6 | withTask 7 | } from '../src/tasks'; 8 | import {SET_SYNC, ADD, taskStore} from './fixtures'; 9 | 10 | const ECHO_TASK = taskCreator( 11 | (payload: string | number, success, _) => success(payload), 12 | 'ECHO_TASK' 13 | ); 14 | 15 | const appendB = x => `${x}b`; 16 | const appendC = x => `${x}c`; 17 | 18 | // This tests that Tasks obey the Functor Laws 19 | // - https://en.wikipedia.org/wiki/Functor_category 20 | test('t.map(f).map(g) === t.map(x => g(f(x)))', () => { 21 | const T1 = ECHO_TASK('out') 22 | .map(appendB) 23 | .map(appendC); 24 | const T2 = ECHO_TASK('out').map(x => appendC(appendB(x))); 25 | 26 | const r1 = succeedTaskInTest(T1, 'a'); 27 | const r2 = succeedTaskInTest(T2, 'a'); 28 | 29 | expect(r1).toBe(r2); 30 | }); 31 | 32 | test('Task.all([t.map(f)]) === Task.all([t]).map([r] => f(r))', () => { 33 | const T1 = Task.all([ECHO_TASK('out').map(appendB)]).map(first); 34 | const T2 = Task.all([ECHO_TASK('out')]).map(([r]) => appendB(r)); 35 | 36 | const r1 = succeedTaskInTest(T1, 'a'); 37 | const r2 = succeedTaskInTest(T2, 'a'); 38 | 39 | expect(r1).toBe(r2); 40 | }); 41 | 42 | test('Tasks can be used in polymorphic functions', () => { 43 | type TT1 = {| 44 | config: {|+name: string|}, 45 | type: 'one' 46 | |}; 47 | const T1 = Task.fromCallback<{|+name: string|}, {|+name: string|}, _>( 48 | (v, cb) => cb(undefined, v), 49 | 'T1' 50 | ); 51 | 52 | type TT2 = {|config: {|+age: number|}, type: 'two'|}; 53 | const T2 = Task.fromCallback<{|+age: number|}, {|+age: number|}, _>( 54 | (v, cb) => cb(undefined, v), 55 | 'T2' 56 | ); 57 | 58 | const foo = (a: TT1 | TT2) => { 59 | switch (a.type) { 60 | case 'one': 61 | return T1(a.config); 62 | case 'two': 63 | return T2(a.config); 64 | } 65 | }; 66 | 67 | const aa = {config: {name: 'foo'}, type: 'one'}; 68 | foo(aa); 69 | 70 | T1(aa.config); 71 | }); 72 | 73 | test('Task.all creates a new task which runs its delegates', () => { 74 | const MULTI_TASK = Task.all([ 75 | ECHO_TASK('1'), 76 | ECHO_TASK('2'), 77 | ECHO_TASK('3') 78 | ]).map(SET_SYNC); 79 | 80 | const reducer = (state = [], action) => { 81 | return action.type === ADD 82 | ? withTask(state, MULTI_TASK) 83 | : action.type === SET_SYNC 84 | ? action.payload 85 | : state; 86 | }; 87 | 88 | const store = taskStore(reducer); 89 | 90 | expect(MULTI_TASK.type).toBe('Task.all(ECHO_TASK, ECHO_TASK, ECHO_TASK)'); 91 | 92 | store.dispatch(ADD(1)).then(_ => { 93 | expect(store.getState()).toEqual(['1', '2', '3']); 94 | }); 95 | }); 96 | 97 | test('Task.all resolves with an empty array', done => { 98 | const MULTI_TASK = Task.all([]).map(SET_SYNC); 99 | 100 | const reducer = (state = ['1', '2', '3'], action) => { 101 | return action.type === ADD 102 | ? withTask(state, MULTI_TASK) 103 | : action.type === SET_SYNC 104 | ? action.payload 105 | : state; 106 | }; 107 | 108 | const store = taskStore(reducer); 109 | 110 | expect(MULTI_TASK.type).toBe('Task.all()'); 111 | 112 | store.dispatch(ADD(1)).then(_ => { 113 | expect(store.getState()).toEqual([]); 114 | done(); 115 | }); 116 | }); 117 | 118 | test('Task.map works in a real store', done => { 119 | const MAP_TASK = ECHO_TASK('5') 120 | .map(x => x + 1) 121 | .map(SET_SYNC); 122 | 123 | const reducer = (state = 0, action) => { 124 | return action.type === ADD 125 | ? withTask(state, MAP_TASK) 126 | : action.type === SET_SYNC 127 | ? action.payload 128 | : state; 129 | }; 130 | 131 | const store = taskStore(reducer); 132 | 133 | store.dispatch(ADD(1)).then(_ => { 134 | expect(store.getState()).toEqual('51'); 135 | done(); 136 | }); 137 | }); 138 | 139 | test('Task.chain works with a real store', done => { 140 | const CHAIN_TASK = ECHO_TASK('Balthazar') 141 | .chain(result => ECHO_TASK(`Hello ${result}`)) 142 | .map(SET_SYNC); 143 | 144 | const reducer = (state = 0, action) => { 145 | return action.type === ADD 146 | ? withTask(state, CHAIN_TASK) 147 | : action.type === SET_SYNC 148 | ? action.payload 149 | : state; 150 | }; 151 | 152 | const store = taskStore(reducer); 153 | 154 | store.dispatch(ADD(1)).then(_ => { 155 | expect(store.getState()).toEqual('Hello Balthazar'); 156 | done(); 157 | }); 158 | }); 159 | 160 | test('Task.chain works with succeedTaskInTest', () => { 161 | const task = ECHO_TASK(''); 162 | const chainTask = task.chain(who => ECHO_TASK(`Hello ${who}`)); 163 | 164 | expect(chainTask.type).toBe('Chain(ECHO_TASK)'); 165 | 166 | const expectations = [ 167 | (effect, s, e) => { 168 | expect(effect.type).toBe('ECHO_TASK'); 169 | expect(effect.payload).toBe(''); 170 | return s('Balthazar'); 171 | }, 172 | (effect, s, e) => { 173 | expect(effect.type).toBe('ECHO_TASK'); 174 | expect(effect.payload).toBe('Hello Balthazar'); 175 | return s('Result'); 176 | } 177 | ]; 178 | 179 | const result = simulateTask(chainTask, (effect, s: string => mixed, e) => 180 | expectations.shift()(effect, s, e) 181 | ); 182 | 183 | expect(result).toBe('Result'); 184 | }); 185 | 186 | function first(list: T[]): T { 187 | return list[0]; 188 | } 189 | -------------------------------------------------------------------------------- /flow-typed/npm/sinon_vx.x.x.js: -------------------------------------------------------------------------------- 1 | // flow-typed signature: 60ce24c5c7578aea138bc9563b15c68b 2 | // flow-typed version: <>/sinon_v^1.17.4/flow_v0.66.0 3 | 4 | /** 5 | * This is an autogenerated libdef stub for: 6 | * 7 | * 'sinon' 8 | * 9 | * Fill this stub out by replacing all the `any` types. 10 | * 11 | * Once filled out, we encourage you to share your work with the 12 | * community by sending a pull request to: 13 | * https://github.com/flowtype/flow-typed 14 | */ 15 | 16 | declare module 'sinon' { 17 | declare module.exports: any; 18 | } 19 | 20 | /** 21 | * We include stubs for each file inside this npm package in case you need to 22 | * require those files directly. Feel free to delete any files that aren't 23 | * needed. 24 | */ 25 | declare module 'sinon/lib/sinon' { 26 | declare module.exports: any; 27 | } 28 | 29 | declare module 'sinon/lib/sinon/assert' { 30 | declare module.exports: any; 31 | } 32 | 33 | declare module 'sinon/lib/sinon/behavior' { 34 | declare module.exports: any; 35 | } 36 | 37 | declare module 'sinon/lib/sinon/call' { 38 | declare module.exports: any; 39 | } 40 | 41 | declare module 'sinon/lib/sinon/collection' { 42 | declare module.exports: any; 43 | } 44 | 45 | declare module 'sinon/lib/sinon/extend' { 46 | declare module.exports: any; 47 | } 48 | 49 | declare module 'sinon/lib/sinon/format' { 50 | declare module.exports: any; 51 | } 52 | 53 | declare module 'sinon/lib/sinon/log_error' { 54 | declare module.exports: any; 55 | } 56 | 57 | declare module 'sinon/lib/sinon/match' { 58 | declare module.exports: any; 59 | } 60 | 61 | declare module 'sinon/lib/sinon/mock' { 62 | declare module.exports: any; 63 | } 64 | 65 | declare module 'sinon/lib/sinon/sandbox' { 66 | declare module.exports: any; 67 | } 68 | 69 | declare module 'sinon/lib/sinon/spy' { 70 | declare module.exports: any; 71 | } 72 | 73 | declare module 'sinon/lib/sinon/stub' { 74 | declare module.exports: any; 75 | } 76 | 77 | declare module 'sinon/lib/sinon/test_case' { 78 | declare module.exports: any; 79 | } 80 | 81 | declare module 'sinon/lib/sinon/test' { 82 | declare module.exports: any; 83 | } 84 | 85 | declare module 'sinon/lib/sinon/times_in_words' { 86 | declare module.exports: any; 87 | } 88 | 89 | declare module 'sinon/lib/sinon/typeOf' { 90 | declare module.exports: any; 91 | } 92 | 93 | declare module 'sinon/lib/sinon/util/core' { 94 | declare module.exports: any; 95 | } 96 | 97 | declare module 'sinon/lib/sinon/util/event' { 98 | declare module.exports: any; 99 | } 100 | 101 | declare module 'sinon/lib/sinon/util/fake_server_with_clock' { 102 | declare module.exports: any; 103 | } 104 | 105 | declare module 'sinon/lib/sinon/util/fake_server' { 106 | declare module.exports: any; 107 | } 108 | 109 | declare module 'sinon/lib/sinon/util/fake_timers' { 110 | declare module.exports: any; 111 | } 112 | 113 | declare module 'sinon/lib/sinon/util/fake_xdomain_request' { 114 | declare module.exports: any; 115 | } 116 | 117 | declare module 'sinon/lib/sinon/util/fake_xml_http_request' { 118 | declare module.exports: any; 119 | } 120 | 121 | declare module 'sinon/lib/sinon/util/timers_ie' { 122 | declare module.exports: any; 123 | } 124 | 125 | declare module 'sinon/lib/sinon/util/xdr_ie' { 126 | declare module.exports: any; 127 | } 128 | 129 | declare module 'sinon/lib/sinon/util/xhr_ie' { 130 | declare module.exports: any; 131 | } 132 | 133 | declare module 'sinon/lib/sinon/walk' { 134 | declare module.exports: any; 135 | } 136 | 137 | declare module 'sinon/pkg/sinon-1.17.7' { 138 | declare module.exports: any; 139 | } 140 | 141 | declare module 'sinon/pkg/sinon-ie-1.17.7' { 142 | declare module.exports: any; 143 | } 144 | 145 | declare module 'sinon/pkg/sinon-ie' { 146 | declare module.exports: any; 147 | } 148 | 149 | declare module 'sinon/pkg/sinon-server-1.17.7' { 150 | declare module.exports: any; 151 | } 152 | 153 | declare module 'sinon/pkg/sinon-server' { 154 | declare module.exports: any; 155 | } 156 | 157 | declare module 'sinon/pkg/sinon' { 158 | declare module.exports: any; 159 | } 160 | 161 | // Filename aliases 162 | declare module 'sinon/lib/sinon.js' { 163 | declare module.exports: $Exports<'sinon/lib/sinon'>; 164 | } 165 | declare module 'sinon/lib/sinon/assert.js' { 166 | declare module.exports: $Exports<'sinon/lib/sinon/assert'>; 167 | } 168 | declare module 'sinon/lib/sinon/behavior.js' { 169 | declare module.exports: $Exports<'sinon/lib/sinon/behavior'>; 170 | } 171 | declare module 'sinon/lib/sinon/call.js' { 172 | declare module.exports: $Exports<'sinon/lib/sinon/call'>; 173 | } 174 | declare module 'sinon/lib/sinon/collection.js' { 175 | declare module.exports: $Exports<'sinon/lib/sinon/collection'>; 176 | } 177 | declare module 'sinon/lib/sinon/extend.js' { 178 | declare module.exports: $Exports<'sinon/lib/sinon/extend'>; 179 | } 180 | declare module 'sinon/lib/sinon/format.js' { 181 | declare module.exports: $Exports<'sinon/lib/sinon/format'>; 182 | } 183 | declare module 'sinon/lib/sinon/log_error.js' { 184 | declare module.exports: $Exports<'sinon/lib/sinon/log_error'>; 185 | } 186 | declare module 'sinon/lib/sinon/match.js' { 187 | declare module.exports: $Exports<'sinon/lib/sinon/match'>; 188 | } 189 | declare module 'sinon/lib/sinon/mock.js' { 190 | declare module.exports: $Exports<'sinon/lib/sinon/mock'>; 191 | } 192 | declare module 'sinon/lib/sinon/sandbox.js' { 193 | declare module.exports: $Exports<'sinon/lib/sinon/sandbox'>; 194 | } 195 | declare module 'sinon/lib/sinon/spy.js' { 196 | declare module.exports: $Exports<'sinon/lib/sinon/spy'>; 197 | } 198 | declare module 'sinon/lib/sinon/stub.js' { 199 | declare module.exports: $Exports<'sinon/lib/sinon/stub'>; 200 | } 201 | declare module 'sinon/lib/sinon/test_case.js' { 202 | declare module.exports: $Exports<'sinon/lib/sinon/test_case'>; 203 | } 204 | declare module 'sinon/lib/sinon/test.js' { 205 | declare module.exports: $Exports<'sinon/lib/sinon/test'>; 206 | } 207 | declare module 'sinon/lib/sinon/times_in_words.js' { 208 | declare module.exports: $Exports<'sinon/lib/sinon/times_in_words'>; 209 | } 210 | declare module 'sinon/lib/sinon/typeOf.js' { 211 | declare module.exports: $Exports<'sinon/lib/sinon/typeOf'>; 212 | } 213 | declare module 'sinon/lib/sinon/util/core.js' { 214 | declare module.exports: $Exports<'sinon/lib/sinon/util/core'>; 215 | } 216 | declare module 'sinon/lib/sinon/util/event.js' { 217 | declare module.exports: $Exports<'sinon/lib/sinon/util/event'>; 218 | } 219 | declare module 'sinon/lib/sinon/util/fake_server_with_clock.js' { 220 | declare module.exports: $Exports<'sinon/lib/sinon/util/fake_server_with_clock'>; 221 | } 222 | declare module 'sinon/lib/sinon/util/fake_server.js' { 223 | declare module.exports: $Exports<'sinon/lib/sinon/util/fake_server'>; 224 | } 225 | declare module 'sinon/lib/sinon/util/fake_timers.js' { 226 | declare module.exports: $Exports<'sinon/lib/sinon/util/fake_timers'>; 227 | } 228 | declare module 'sinon/lib/sinon/util/fake_xdomain_request.js' { 229 | declare module.exports: $Exports<'sinon/lib/sinon/util/fake_xdomain_request'>; 230 | } 231 | declare module 'sinon/lib/sinon/util/fake_xml_http_request.js' { 232 | declare module.exports: $Exports<'sinon/lib/sinon/util/fake_xml_http_request'>; 233 | } 234 | declare module 'sinon/lib/sinon/util/timers_ie.js' { 235 | declare module.exports: $Exports<'sinon/lib/sinon/util/timers_ie'>; 236 | } 237 | declare module 'sinon/lib/sinon/util/xdr_ie.js' { 238 | declare module.exports: $Exports<'sinon/lib/sinon/util/xdr_ie'>; 239 | } 240 | declare module 'sinon/lib/sinon/util/xhr_ie.js' { 241 | declare module.exports: $Exports<'sinon/lib/sinon/util/xhr_ie'>; 242 | } 243 | declare module 'sinon/lib/sinon/walk.js' { 244 | declare module.exports: $Exports<'sinon/lib/sinon/walk'>; 245 | } 246 | declare module 'sinon/pkg/sinon-1.17.7.js' { 247 | declare module.exports: $Exports<'sinon/pkg/sinon-1.17.7'>; 248 | } 249 | declare module 'sinon/pkg/sinon-ie-1.17.7.js' { 250 | declare module.exports: $Exports<'sinon/pkg/sinon-ie-1.17.7'>; 251 | } 252 | declare module 'sinon/pkg/sinon-ie.js' { 253 | declare module.exports: $Exports<'sinon/pkg/sinon-ie'>; 254 | } 255 | declare module 'sinon/pkg/sinon-server-1.17.7.js' { 256 | declare module.exports: $Exports<'sinon/pkg/sinon-server-1.17.7'>; 257 | } 258 | declare module 'sinon/pkg/sinon-server.js' { 259 | declare module.exports: $Exports<'sinon/pkg/sinon-server'>; 260 | } 261 | declare module 'sinon/pkg/sinon.js' { 262 | declare module.exports: $Exports<'sinon/pkg/sinon'>; 263 | } 264 | -------------------------------------------------------------------------------- /src/react-dom/cjs/react-dom-test-utils.production.min.js: -------------------------------------------------------------------------------- 1 | /** @license React v16.8.4+patch 2 | * react-dom-test-utils.production.min.js 3 | * 4 | * Copyright (c) Facebook, Inc. and its affiliates. 5 | * 6 | * This source code is licensed under the MIT license found in the 7 | * LICENSE file in the root directory of this source tree. 8 | */ 9 | 10 | 'use strict';var g=require("object-assign"),l=require("react"),m=require("react-dom");function n(a,b,c,e,d,k,f,h){if(!a){a=void 0;if(void 0===b)a=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var N=[c,e,d,k,f,h],O=0;a=Error(b.replace(/%s/g,function(){return N[O++]}));a.name="Invariant Violation"}a.framesToPop=1;throw a;}} 11 | function p(a){for(var b=arguments.length-1,c="https://reactjs.org/docs/error-decoder.html?invariant="+a,e=0;ethis.eventPool.length&&this.eventPool.push(a)} 18 | function y(a){a.eventPool=[];a.getPooled=z;a.release=A}var B=!("undefined"===typeof window||!window.document||!window.document.createElement);function C(a,b){var c={};c[a.toLowerCase()]=b.toLowerCase();c["Webkit"+a]="webkit"+b;c["Moz"+a]="moz"+b;return c}var D={animationend:C("Animation","AnimationEnd"),animationiteration:C("Animation","AnimationIteration"),animationstart:C("Animation","AnimationStart"),transitionend:C("Transition","TransitionEnd")},E={},F={}; 19 | B&&(F=document.createElement("div").style,"AnimationEvent"in window||(delete D.animationend.animation,delete D.animationiteration.animation,delete D.animationstart.animation),"TransitionEvent"in window||delete D.transitionend.transition);function G(a){if(E[a])return E[a];if(!D[a])return a;var b=D[a],c;for(c in b)if(b.hasOwnProperty(c)&&c in F)return E[a]=b[c];return a} 20 | var H=G("animationend"),I=G("animationiteration"),J=G("animationstart"),K=G("transitionend"),L=m.findDOMNode,M=m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events,P=M[0],Q=M[4],R=M[5],aa=M[6],ba=M[7],ca=M[8],S=M[9],da=M[10];function T(){} 21 | function ea(a,b){if(!a)return[];a=u(a);if(!a)return[];for(var c=a,e=[];;){if(5===c.tag||6===c.tag||1===c.tag||0===c.tag){var d=c.stateNode;b(d)&&e.push(d)}if(c.child)c.child.return=c,c=c.child;else{if(c===a)return e;for(;!c.sibling;){if(!c.return||c.return===a)return e;c=c.return}c.sibling.return=c.return;c=c.sibling}}} 22 | function U(a,b){if(a&&!a._reactInternalFiber){var c=""+a;a=Array.isArray(a)?"an array":a&&1===a.nodeType&&a.tagName?"a DOM node":"[object Object]"===c?"object with keys {"+Object.keys(a).join(", ")+"}":c;p("286",b,a)}} 23 | var V=null,W={renderIntoDocument:function(a){var b=document.createElement("div");return m.render(a,b)},isElement:function(a){return l.isValidElement(a)},isElementOfType:function(a,b){return l.isValidElement(a)&&a.type===b},isDOMComponent:function(a){return!(!a||1!==a.nodeType||!a.tagName)},isDOMComponentElement:function(a){return!!(a&&l.isValidElement(a)&&a.tagName)},isCompositeComponent:function(a){return W.isDOMComponent(a)?!1:null!=a&&"function"===typeof a.render&&"function"===typeof a.setState}, 24 | isCompositeComponentWithType:function(a,b){return W.isCompositeComponent(a)?a._reactInternalFiber.type===b:!1},findAllInRenderedTree:function(a,b){U(a,"findAllInRenderedTree");return a?ea(a._reactInternalFiber,b):[]},scryRenderedDOMComponentsWithClass:function(a,b){U(a,"scryRenderedDOMComponentsWithClass");return W.findAllInRenderedTree(a,function(a){if(W.isDOMComponent(a)){var c=a.className;"string"!==typeof c&&(c=a.getAttribute("class")||"");var d=c.split(/\s+/);Array.isArray(b)||(void 0===b?p("11"): 25 | void 0,b=b.split(/\s+/));return b.every(function(a){return-1!==d.indexOf(a)})}return!1})},findRenderedDOMComponentWithClass:function(a,b){U(a,"findRenderedDOMComponentWithClass");a=W.scryRenderedDOMComponentsWithClass(a,b);if(1!==a.length)throw Error("Did not find exactly one match (found: "+a.length+") for class:"+b);return a[0]},scryRenderedDOMComponentsWithTag:function(a,b){U(a,"scryRenderedDOMComponentsWithTag");return W.findAllInRenderedTree(a,function(a){return W.isDOMComponent(a)&&a.tagName.toUpperCase()=== 26 | b.toUpperCase()})},findRenderedDOMComponentWithTag:function(a,b){U(a,"findRenderedDOMComponentWithTag");a=W.scryRenderedDOMComponentsWithTag(a,b);if(1!==a.length)throw Error("Did not find exactly one match (found: "+a.length+") for tag:"+b);return a[0]},scryRenderedComponentsWithType:function(a,b){U(a,"scryRenderedComponentsWithType");return W.findAllInRenderedTree(a,function(a){return W.isCompositeComponentWithType(a,b)})},findRenderedComponentWithType:function(a,b){U(a,"findRenderedComponentWithType"); 27 | a=W.scryRenderedComponentsWithType(a,b);if(1!==a.length)throw Error("Did not find exactly one match (found: "+a.length+") for componentType:"+b);return a[0]},mockComponent:function(a,b){b=b||a.mockTagName||"div";a.prototype.render.mockImplementation(function(){return l.createElement(b,null,this.props.children)});return this},nativeTouchData:function(a,b){return{touches:[{pageX:a,pageY:b}]}},Simulate:null,SimulateNative:{},act:function(a){null===V&&(V=document.createElement("div"));m.unstable_batchedUpdates(a); 28 | m.render(l.createElement("div",null),V);return{then:function(){}}}};function fa(a){return function(b,c){l.isValidElement(b)?p("228"):void 0;W.isCompositeComponent(b)?p("229"):void 0;var e=Q[a],d=new T;d.target=b;d.type=a.toLowerCase();var k=P(b),f=new x(e,k,d,b);f.persist();g(f,c);e.phasedRegistrationNames?R(f):aa(f);m.unstable_batchedUpdates(function(){ba(b);da(f)});ca()}}W.Simulate={};var X=void 0;for(X in Q)W.Simulate[X]=fa(X); 29 | function ha(a,b){return function(c,e){var d=new T(a);g(d,e);W.isDOMComponent(c)?(c=L(c),d.target=c,S(b,d)):c.tagName&&(d.target=c,S(b,d))}} 30 | [["abort","abort"],[H,"animationEnd"],[I,"animationIteration"],[J,"animationStart"],["blur","blur"],["canplaythrough","canPlayThrough"],["canplay","canPlay"],["cancel","cancel"],["change","change"],["click","click"],["close","close"],["compositionend","compositionEnd"],["compositionstart","compositionStart"],["compositionupdate","compositionUpdate"],["contextmenu","contextMenu"],["copy","copy"],["cut","cut"],["dblclick","doubleClick"],["dragend","dragEnd"],["dragenter","dragEnter"],["dragexit","dragExit"], 31 | ["dragleave","dragLeave"],["dragover","dragOver"],["dragstart","dragStart"],["drag","drag"],["drop","drop"],["durationchange","durationChange"],["emptied","emptied"],["encrypted","encrypted"],["ended","ended"],["error","error"],["focus","focus"],["input","input"],["keydown","keyDown"],["keypress","keyPress"],["keyup","keyUp"],["loadstart","loadStart"],["loadstart","loadStart"],["load","load"],["loadeddata","loadedData"],["loadedmetadata","loadedMetadata"],["mousedown","mouseDown"],["mousemove","mouseMove"], 32 | ["mouseout","mouseOut"],["mouseover","mouseOver"],["mouseup","mouseUp"],["paste","paste"],["pause","pause"],["play","play"],["playing","playing"],["progress","progress"],["ratechange","rateChange"],["scroll","scroll"],["seeked","seeked"],["seeking","seeking"],["selectionchange","selectionChange"],["stalled","stalled"],["suspend","suspend"],["textInput","textInput"],["timeupdate","timeUpdate"],["toggle","toggle"],["touchcancel","touchCancel"],["touchend","touchEnd"],["touchmove","touchMove"],["touchstart", 33 | "touchStart"],[K,"transitionEnd"],["volumechange","volumeChange"],["waiting","waiting"],["wheel","wheel"]].forEach(function(a){var b=a[1];W.SimulateNative[b]=ha(b,a[0])});var Y={default:W},Z=Y&&W||Y;module.exports=Z.default||Z; 34 | -------------------------------------------------------------------------------- /src/react-dom/umd/react-dom-test-utils.production.min.js: -------------------------------------------------------------------------------- 1 | /** @license React v16.8.4+patch 2 | * react-dom-test-utils.production.min.js 3 | * 4 | * Copyright (c) Facebook, Inc. and its affiliates. 5 | * 6 | * This source code is licensed under the MIT license found in the 7 | * LICENSE file in the root directory of this source tree. 8 | */ 9 | 'use strict';(function(g,m){"object"===typeof exports&&"undefined"!==typeof module?module.exports=m(require("react"),require("react-dom")):"function"===typeof define&&define.amd?define(["react","react-dom"],m):g.ReactTestUtils=m(g.React,g.ReactDOM)})(this,function(g,m){function H(a,b,c,e,d,f,h,J){if(!a){a=void 0;if(void 0===b)a=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var g=[c,e,d,f,h,J],I=0;a=Error(b.replace(/%s/g, 10 | function(){return g[I++]}));a.name="Invariant Violation"}a.framesToPop=1;throw a;}}function l(a){for(var b=arguments.length-1,c="https://reactjs.org/docs/error-decoder.html?invariant="+a,e=0;ethis.eventPool.length&&this.eventPool.push(a)}function C(a){a.eventPool=[];a.getPooled=L;a.release=M}function w(a,b){var c={};c[a.toLowerCase()]=b.toLowerCase();c["Webkit"+a]="webkit"+b;c["Moz"+a]="moz"+ 14 | b;return c}function x(a){if(y[a])return y[a];if(!q[a])return a;var b=q[a],c;for(c in b)if(b.hasOwnProperty(c)&&c in D)return y[a]=b[c];return a}function E(a){}function N(a,b){if(!a)return[];a=K(a);if(!a)return[];for(var c=a,e=[];;){if(5===c.tag||6===c.tag||1===c.tag||0===c.tag){var d=c.stateNode;b(d)&&e.push(d)}if(c.child)c.child.return=c,c=c.child;else{if(c===a)return e;for(;!c.sibling;){if(!c.return||c.return===a)return e;c=c.return}c.sibling.return=c.return;c=c.sibling}}}function p(a,b){if(a&& 15 | !a._reactInternalFiber){var c=""+a;a=Array.isArray(a)?"an array":a&&1===a.nodeType&&a.tagName?"a DOM node":"[object Object]"===c?"object with keys {"+Object.keys(a).join(", ")+"}":c;l("286",b,a)}}function O(a){return function(b,c){g.isValidElement(b)?l("228"):void 0;f.isCompositeComponent(b)?l("229"):void 0;var e=F[a],d=new E;d.target=b;d.type=a.toLowerCase();var k=P(b),h=new r(e,k,d,b);h.persist();t(h,c);e.phasedRegistrationNames?Q(h):R(h);m.unstable_batchedUpdates(function(){S(b);T(h)});U()}}function V(a, 16 | b){return function(c,e){var d=new E(a);t(d,e);f.isDOMComponent(c)?(c=W(c),d.target=c,G(b,d)):c.tagName&&(d.target=c,G(b,d))}}var t=g.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.assign,k=g.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;k.hasOwnProperty("ReactCurrentDispatcher")||(k.ReactCurrentDispatcher={current:null});t(r.prototype,{preventDefault:function(){this.defaultPrevented=!0;var a=this.nativeEvent;a&&(a.preventDefault?a.preventDefault():"unknown"!==typeof a.returnValue&&(a.returnValue= 17 | !1),this.isDefaultPrevented=u)},stopPropagation:function(){var a=this.nativeEvent;a&&(a.stopPropagation?a.stopPropagation():"unknown"!==typeof a.cancelBubble&&(a.cancelBubble=!0),this.isPropagationStopped=u)},persist:function(){this.isPersistent=u},isPersistent:v,destructor:function(){var a=this.constructor.Interface,b;for(b in a)this[b]=null;this.nativeEvent=this._targetInst=this.dispatchConfig=null;this.isPropagationStopped=this.isDefaultPrevented=v;this._dispatchInstances=this._dispatchListeners= 18 | null}});r.Interface={type:null,target:null,currentTarget:function(){return null},eventPhase:null,bubbles:null,cancelable:null,timeStamp:function(a){return a.timeStamp||Date.now()},defaultPrevented:null,isTrusted:null};r.extend=function(a){function b(){return c.apply(this,arguments)}var c=this,e=function(){};e.prototype=c.prototype;e=new e;t(e,b.prototype);b.prototype=e;b.prototype.constructor=b;b.Interface=t({},c.Interface,a);b.extend=c.extend;C(b);return b};C(r);k=!("undefined"===typeof window|| 19 | !window.document||!window.document.createElement);var q={animationend:w("Animation","AnimationEnd"),animationiteration:w("Animation","AnimationIteration"),animationstart:w("Animation","AnimationStart"),transitionend:w("Transition","TransitionEnd")},y={},D={};k&&(D=document.createElement("div").style,"AnimationEvent"in window||(delete q.animationend.animation,delete q.animationiteration.animation,delete q.animationstart.animation),"TransitionEvent"in window||delete q.transitionend.transition);k=x("animationend"); 20 | var X=x("animationiteration"),Y=x("animationstart"),Z=x("transitionend"),W=m.findDOMNode,n=m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events,P=n[0],F=n[4],Q=n[5],R=n[6],S=n[7],U=n[8],G=n[9],T=n[10],z=null,f={renderIntoDocument:function(a){var b=document.createElement("div");return m.render(a,b)},isElement:function(a){return g.isValidElement(a)},isElementOfType:function(a,b){return g.isValidElement(a)&&a.type===b},isDOMComponent:function(a){return!(!a||1!==a.nodeType||!a.tagName)},isDOMComponentElement:function(a){return!!(a&& 21 | g.isValidElement(a)&&a.tagName)},isCompositeComponent:function(a){return f.isDOMComponent(a)?!1:null!=a&&"function"===typeof a.render&&"function"===typeof a.setState},isCompositeComponentWithType:function(a,b){return f.isCompositeComponent(a)?a._reactInternalFiber.type===b:!1},findAllInRenderedTree:function(a,b){p(a,"findAllInRenderedTree");return a?N(a._reactInternalFiber,b):[]},scryRenderedDOMComponentsWithClass:function(a,b){p(a,"scryRenderedDOMComponentsWithClass");return f.findAllInRenderedTree(a, 22 | function(a){if(f.isDOMComponent(a)){var c=a.className;"string"!==typeof c&&(c=a.getAttribute("class")||"");var d=c.split(/\s+/);Array.isArray(b)||(void 0===b?l("11"):void 0,b=b.split(/\s+/));return b.every(function(a){return-1!==d.indexOf(a)})}return!1})},findRenderedDOMComponentWithClass:function(a,b){p(a,"findRenderedDOMComponentWithClass");a=f.scryRenderedDOMComponentsWithClass(a,b);if(1!==a.length)throw Error("Did not find exactly one match (found: "+a.length+") for class:"+b);return a[0]},scryRenderedDOMComponentsWithTag:function(a, 23 | b){p(a,"scryRenderedDOMComponentsWithTag");return f.findAllInRenderedTree(a,function(a){return f.isDOMComponent(a)&&a.tagName.toUpperCase()===b.toUpperCase()})},findRenderedDOMComponentWithTag:function(a,b){p(a,"findRenderedDOMComponentWithTag");a=f.scryRenderedDOMComponentsWithTag(a,b);if(1!==a.length)throw Error("Did not find exactly one match (found: "+a.length+") for tag:"+b);return a[0]},scryRenderedComponentsWithType:function(a,b){p(a,"scryRenderedComponentsWithType");return f.findAllInRenderedTree(a, 24 | function(a){return f.isCompositeComponentWithType(a,b)})},findRenderedComponentWithType:function(a,b){p(a,"findRenderedComponentWithType");a=f.scryRenderedComponentsWithType(a,b);if(1!==a.length)throw Error("Did not find exactly one match (found: "+a.length+") for componentType:"+b);return a[0]},mockComponent:function(a,b){b=b||a.mockTagName||"div";a.prototype.render.mockImplementation(function(){return g.createElement(b,null,this.props.children)});return this},nativeTouchData:function(a,b){return{touches:[{pageX:a, 25 | pageY:b}]}},Simulate:null,SimulateNative:{},act:function(a){null===z&&(z=document.createElement("div"));m.unstable_batchedUpdates(a);m.render(g.createElement("div",null),z);return{then:function(){}}}};(function(){f.Simulate={};var a=void 0;for(a in F)f.Simulate[a]=O(a)})();[["abort","abort"],[k,"animationEnd"],[X,"animationIteration"],[Y,"animationStart"],["blur","blur"],["canplaythrough","canPlayThrough"],["canplay","canPlay"],["cancel","cancel"],["change","change"],["click","click"],["close","close"], 26 | ["compositionend","compositionEnd"],["compositionstart","compositionStart"],["compositionupdate","compositionUpdate"],["contextmenu","contextMenu"],["copy","copy"],["cut","cut"],["dblclick","doubleClick"],["dragend","dragEnd"],["dragenter","dragEnter"],["dragexit","dragExit"],["dragleave","dragLeave"],["dragover","dragOver"],["dragstart","dragStart"],["drag","drag"],["drop","drop"],["durationchange","durationChange"],["emptied","emptied"],["encrypted","encrypted"],["ended","ended"],["error","error"], 27 | ["focus","focus"],["input","input"],["keydown","keyDown"],["keypress","keyPress"],["keyup","keyUp"],["loadstart","loadStart"],["loadstart","loadStart"],["load","load"],["loadeddata","loadedData"],["loadedmetadata","loadedMetadata"],["mousedown","mouseDown"],["mousemove","mouseMove"],["mouseout","mouseOut"],["mouseover","mouseOver"],["mouseup","mouseUp"],["paste","paste"],["pause","pause"],["play","play"],["playing","playing"],["progress","progress"],["ratechange","rateChange"],["scroll","scroll"], 28 | ["seeked","seeked"],["seeking","seeking"],["selectionchange","selectionChange"],["stalled","stalled"],["suspend","suspend"],["textInput","textInput"],["timeupdate","timeUpdate"],["toggle","toggle"],["touchcancel","touchCancel"],["touchend","touchEnd"],["touchmove","touchMove"],["touchstart","touchStart"],[Z,"transitionEnd"],["volumechange","volumeChange"],["waiting","waiting"],["wheel","wheel"]].forEach(function(a){var b=a[1];f.SimulateNative[b]=V(b,a[0])});k=(k={default:f},f)||k;return k.default|| 29 | k}); 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | version 4 | 5 | 6 | build 7 | 8 | 9 | downloads 10 | 11 |

12 | 13 |

react-palm

14 | 15 |
A cohesive strategy for managing state, handling side effects, and testing React Apps.
16 | 17 | yarn add react-palm 18 | 19 | ### What is a Task? 20 | 21 | `Task`s can be understood in terms of their relationship to `Promise`s. A `Promise` represents a future value, but for which the computation has already begun. A `Task` represents a future computation, or future side effect. It's like a function that you haven't run yet. `Task`s are lazy, where `Promise`s are eager. 22 | 23 | Why? By capturing side effects this way, we can easily test them without having to build up a large suite of mocks. Code written this way is easy to test. 24 | 25 | // Promise -> new Promise( () => window.fetch('example.com') ) 26 | // Promise -> new Promise( () => Math.random() ) 27 | // Promise -> new Promise( () => localStorage ) 28 | 29 | // Task -> () => new Promise( ... ) 30 | 31 | ### Task Redux Middleware 32 | 33 | `Task`s easily adapt to redux using the provided middleware. This allows you to build a state machine from `Action`s and `Task`s. Make side effects a responsibility of the reducer while keeping the reducer pure. 34 | 35 | ### Why does it matter? 36 | By capturing side effects this way, we can easily test them without having to build up a large suite of mocks. 37 | The computation (when you call task.run()) might include a side-effect, but as long as the task is just sitting there, it's pure. 38 | Keeps reducer pure. At the same time owns the entire flow of doing XHR. 39 | 40 | 41 | 42 | ### Setup 43 | 44 | Add the `taskMiddleware` to your store, or the tasks handlers won't get called. 45 | 46 | ```javascript 47 | import { createStore, applyMiddleware, compose } from 'redux' 48 | import { taskMiddleware } from 'react-palm' 49 | 50 | import reducer from './reducer' 51 | 52 | // using createStore 53 | const store = createStore(reducer, applyMiddleWare(taskMiddleware)) 54 | 55 | // using enhancers 56 | const initialState = {} 57 | const middlewares = [taskMiddleware] 58 | const enhancers = [ 59 | applyMiddleware(...middlewares) 60 | ] 61 | 62 | const store = createStore(reducer, initialState, compose(...enhancers)) 63 | ``` 64 | 65 | 66 | ### Usage 67 | 68 | #### Task.fromPromise 69 | Here is a sample of what a delay task which triggers an action after a 70 | specified amount of time would look like. 71 | 72 | ```javascript 73 | import Task from 'react-palm/tasks'; 74 | 75 | export const DELAY = Task.fromPromise((time) => 76 | new Promise(resolve => window.setTimeout(resolve, time)), 77 | 78 | 'DELAY' 79 | ); 80 | ``` 81 | 82 | You can use the task in your reducer like this: 83 | 84 | ```javascript 85 | import { withTask } from 'react-palm' 86 | import { handleActions, createAction } from 'react-palm/actions' 87 | 88 | import { DELAY } from './tasks/delay' 89 | 90 | export const incrementWithDelay = createAction('DELAY_INCREMENT') 91 | const increment = createAction('INCREMENT') 92 | 93 | handleActions({ 94 | DELAY_INCREMENT: state => 95 | withTask(state, DELAY(1000).map(increment)), 96 | 97 | INCREMENT: state => state + 1 98 | }, 0) 99 | ``` 100 | 101 | Dispatching `incrementWithDelay` will wait one second, then increment our counter state. 102 | 103 | The call to `.map` tells us to wrap the result of the task in an `INCREMENT` action. 104 | 105 | In the above example, we directly pass `state` as the first argument to `withTask`. 106 | Whatever you pass as the first argument will become the updated state, so you 107 | can update your state before the task is executed if you want. This might be useful 108 | to update a loading spinner, for instance. 109 | 110 | #### Task.fromCallback 111 | 112 | Wraps a node-style callback in a Task. `fromPromise` takes a function, which recieves the argument that the task is called with, and a node-style callback function (with type `(err, res) => void`), where the first argument represents the error when present (or `null` when successful), and the second argument represents the success value (or `null` in the case of an error). 113 | 114 | ```javascript 115 | // DELAY is a task that recieves how long to wait (in ms), and that resolves 116 | // with a Date object representing the current time after waiting. 117 | export const DELAY = Task.fromCallback((time, cb) => 118 | window.setTimeout(() => cb(null, new Date()), time), 119 | 120 | 'DELAY' 121 | ); 122 | 123 | // delay 100ms, then do something using the current time. 124 | DELAY(100).map(currentTime => ...); 125 | ``` 126 | 127 | This example is equal to the one above using `Task.fromPromise`. 128 | 129 | #### Task.all 130 | 131 | Like `Promise.all`, but for tasks. Given an array of tasks, returns a new task whose success value will be an array of results. 132 | 133 | ``` 134 | import Task from 'react-palm/tasks'; 135 | 136 | const FETCH = Task.fromPromise((url) => window.fetch(url), 'FETCH'); 137 | 138 | const FETCH_SEVERAL = Task.all([ FETCH('example.com'), FETCH('google.com') ]) 139 | 140 | FETCH_SEVERAL.bimap(([exampleResult, googleResult]) => ..., err => ...); 141 | ``` 142 | 143 | #### task.chain 144 | 145 | `chain` lets you run one task immediately after another. 146 | `task.chain` accepts a function like: `(success) => nextTask`. This function recieves the success value of the first task, and should return another task to be run. 147 | 148 | Using the tasks we defined above, we can create a task that first waits `100ms`, and then issues an HTTP request: 149 | 150 | ```javascript 151 | const WAIT_AND_FETCH = DELAY(100).chain(() => FETCH('example.com')); 152 | 153 | // The resultant Task from chain will have the success payload from FETCH 154 | WAIT_AND_FETCH.bimap(httpResult => ..., err => ...); 155 | ``` 156 | 157 | When used with Redux, this is a good way to avoid having to create extra actions. 158 | 159 | #### task.bimap 160 | 161 | Provide transforms for the success and error payload of a task. Bimap takes 162 | 163 | `bimap` can be chained multiple times: 164 | 165 | ``` 166 | task 167 | .bimap(result => result + 1, error => 'Error: ' + error) 168 | .bimap(result => 2 * result, error => error + '!!') 169 | ``` 170 | 171 | `bimap` preserves composition, so the above is the same as writing: 172 | 173 | ``` 174 | task 175 | .bimap(result => 2 * (result + 1), error => 'Error: ' + error + '!!') 176 | ``` 177 | 178 | When using Tasks with Redux, we typically use `bimap` to transform the result of a Task into actions to be dispatched on completion. 179 | 180 | 181 | ### Testing 182 | 183 | We designed `react-palm` with testing in mind. Since you probably don't want 184 | to create API calls in a testing environment, we provide a `drainTasksForTesting` 185 | utility that will remove all the tasks from the queue and return them. 186 | 187 | You can now assert that they have the expected type and payload. 188 | 189 | ```javascript 190 | import { drainTasksForTesting, succeedTaskInTest, errorTaskInTest } from 'react-palm' 191 | 192 | import reducer, { incrementWithDelay } from './reducer' 193 | import DELAY from './tasks/delay' 194 | 195 | test('The delay task should be valid', t => { 196 | const state = reducer(42, incrementWithDelay()) 197 | const tasks = drainTasksForTesting() 198 | 199 | t.is(state, 42) 200 | t.is(tasks.length, 1) 201 | t.is(tasks[0].type, DELAY) 202 | t.is(tasks[0].action.type, 'INCREMENT') 203 | 204 | 205 | // test success 206 | const successState = reducer(newState, succeedTaskInTest(task1, mockSuccessResult)); 207 | t.deepEqual(successState, expectedState, ‘State should be updated when task succeed'); 208 | 209 | // test LOAD_FILE_TASK error 210 | const errorState = reducer(nextState, errorTaskInTest(task1, mockErrorResult)); 211 | t.deepEqual(errorState, expectedErrorState, ‘State should be updated when task errored); 212 | 213 | t.is(newState, 43) 214 | }) 215 | ``` 216 | 217 | You can also have a look to the [example](./example) directory for a complete 218 | use-case. 219 | 220 | ### FAQ 221 | 222 | ##### Strategy? Framework? Library? 223 | 224 | It's unlikely that you'll create a cohesive architecture if you piecemeal add requirements to 225 | an existing design. 226 | 227 | `react-palm` takes a "subtractive" approach; we start with a full set of concerns and make sure 228 | that they work well together before breaking them up. 229 | This means that as your app grows, you won't have to rethink everything. 230 | 231 | ##### Should I use this? 232 | 233 | Ideally, you should use Elm or PureScript. This architecture is the closest thing to Elm I've managed to 234 | make within the constraints of JavaScript, React, and Redux. I created it as a stop-gap for 235 | specific applications that I work on. It contains trade-offs that may not be generally useful. 236 | 237 | - [Elm](http://elm-lang.org), a friendly, functional, compile-to-JS language. 238 | - [The Elm Architecture (TEA)](https://guide.elm-lang.org/architecture/) 239 | - [PureScript](http://www.purescript.org/), a feature-rich, functional compile-to-JS language. 240 | - [Choo](https://github.com/yoshuawuyts/choo), a small, Elm-like framework for JavaScript. 241 | - [redux-loop](https://github.com/redux-loop/redux-loop) a library that provides a very literal translation of commands and tasks from Elm to Redux. 242 | 243 | ### Developing 244 | 245 | ``` 246 | yarn 247 | ``` 248 | 249 | #### Publishing (to npm) 250 | 251 | 1. Update the version in `package.json` manually or via [`npm version`](https://docs.npmjs.com/getting-started/publishing-npm-packages#how-to-update-the-version-number). 252 | 253 | 2. Commit and push. 254 | 255 | 3. Create tags for the new version. Either: 256 | - use the [GitHub GUI](https://github.com/btford/react-palm/releases/new) to create and push new tags 257 | - or go [the old-fashioned route](https://git-scm.com/book/en/v2/Git-Basics-Tagging) 258 | 259 | 4. Publish: 260 | 261 | Run `build` and publish from the resulting `dist` folder to ensure built artifacts are included in the published package: 262 | 263 | ``` 264 | yarn build 265 | cd dist 266 | npm publish 267 | ``` 268 | -------------------------------------------------------------------------------- /src/react-dom/cjs/react-dom-unstable-native-dependencies.production.min.js: -------------------------------------------------------------------------------- 1 | /** @license React v16.8.4+patch 2 | * react-dom-unstable-native-dependencies.production.min.js 3 | * 4 | * Copyright (c) Facebook, Inc. and its affiliates. 5 | * 6 | * This source code is licensed under the MIT license found in the 7 | * LICENSE file in the root directory of this source tree. 8 | */ 9 | 10 | 'use strict';var k=require("react-dom"),l=require("object-assign");function aa(a,b,c,f,e,d,g,h){if(!a){a=void 0;if(void 0===b)a=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var u=[c,f,e,d,g,h],ba=0;a=Error(b.replace(/%s/g,function(){return u[ba++]}));a.name="Invariant Violation"}a.framesToPop=1;throw a;}} 11 | function m(a){for(var b=arguments.length-1,c="https://reactjs.org/docs/error-decoder.html?invariant="+a,f=0;fthis.eventPool.length&&this.eventPool.push(a)} 21 | function E(a){a.eventPool=[];a.getPooled=ea;a.release=fa}var F=D.extend({touchHistory:function(){return null}});function G(a){return"touchstart"===a||"mousedown"===a}function H(a){return"touchmove"===a||"mousemove"===a}function I(a){return"touchend"===a||"touchcancel"===a||"mouseup"===a}var J=["touchstart","mousedown"],K=["touchmove","mousemove"],L=["touchcancel","touchend","mouseup"],M=[],N={touchBank:M,numberActiveTouches:0,indexOfSingleActiveTouch:-1,mostRecentTimeStamp:0}; 22 | function O(a){return a.timeStamp||a.timestamp}function P(a){a=a.identifier;null==a?m("138"):void 0;return a} 23 | function ha(a){var b=P(a),c=M[b];c?(c.touchActive=!0,c.startPageX=a.pageX,c.startPageY=a.pageY,c.startTimeStamp=O(a),c.currentPageX=a.pageX,c.currentPageY=a.pageY,c.currentTimeStamp=O(a),c.previousPageX=a.pageX,c.previousPageY=a.pageY,c.previousTimeStamp=O(a)):(c={touchActive:!0,startPageX:a.pageX,startPageY:a.pageY,startTimeStamp:O(a),currentPageX:a.pageX,currentPageY:a.pageY,currentTimeStamp:O(a),previousPageX:a.pageX,previousPageY:a.pageY,previousTimeStamp:O(a)},M[b]=c);N.mostRecentTimeStamp=O(a)} 24 | function ia(a){var b=M[P(a)];b?(b.touchActive=!0,b.previousPageX=b.currentPageX,b.previousPageY=b.currentPageY,b.previousTimeStamp=b.currentTimeStamp,b.currentPageX=a.pageX,b.currentPageY=a.pageY,b.currentTimeStamp=O(a),N.mostRecentTimeStamp=O(a)):console.error("Cannot record touch move without a touch start.\nTouch Move: %s\n","Touch Bank: %s",Q(a),R())} 25 | function ja(a){var b=M[P(a)];b?(b.touchActive=!1,b.previousPageX=b.currentPageX,b.previousPageY=b.currentPageY,b.previousTimeStamp=b.currentTimeStamp,b.currentPageX=a.pageX,b.currentPageY=a.pageY,b.currentTimeStamp=O(a),N.mostRecentTimeStamp=O(a)):console.error("Cannot record touch end without a touch start.\nTouch End: %s\n","Touch Bank: %s",Q(a),R())}function Q(a){return JSON.stringify({identifier:a.identifier,pageX:a.pageX,pageY:a.pageY,timestamp:O(a)})} 26 | function R(){var a=JSON.stringify(M.slice(0,20));20this.eventPool.length&&this.eventPool.push(a)}function S(a){a.eventPool=[];a.getPooled=ba;a.release=ca}function A(a){return"touchstart"===a||"mousedown"===a}function F(a){return"touchmove"===a||"mousemove"===a}function G(a){return"touchend"=== 16 | a||"touchcancel"===a||"mouseup"===a}function l(a){return a.timeStamp||a.timestamp}function J(a){a=a.identifier;null==a?x("138"):void 0;return a}function da(a){var b=J(a),c=q[b];c?(c.touchActive=!0,c.startPageX=a.pageX,c.startPageY=a.pageY,c.startTimeStamp=l(a),c.currentPageX=a.pageX,c.currentPageY=a.pageY,c.currentTimeStamp=l(a),c.previousPageX=a.pageX,c.previousPageY=a.pageY,c.previousTimeStamp=l(a)):(c={touchActive:!0,startPageX:a.pageX,startPageY:a.pageY,startTimeStamp:l(a),currentPageX:a.pageX, 17 | currentPageY:a.pageY,currentTimeStamp:l(a),previousPageX:a.pageX,previousPageY:a.pageY,previousTimeStamp:l(a)},q[b]=c);r.mostRecentTimeStamp=l(a)}function ea(a){var b=q[J(a)];b?(b.touchActive=!0,b.previousPageX=b.currentPageX,b.previousPageY=b.currentPageY,b.previousTimeStamp=b.currentTimeStamp,b.currentPageX=a.pageX,b.currentPageY=a.pageY,b.currentTimeStamp=l(a),r.mostRecentTimeStamp=l(a)):console.error("Cannot record touch move without a touch start.\nTouch Move: %s\n","Touch Bank: %s",T(a),U())} 18 | function fa(a){var b=q[J(a)];b?(b.touchActive=!1,b.previousPageX=b.currentPageX,b.previousPageY=b.currentPageY,b.previousTimeStamp=b.currentTimeStamp,b.currentPageX=a.pageX,b.currentPageY=a.pageY,b.currentTimeStamp=l(a),r.mostRecentTimeStamp=l(a)):console.error("Cannot record touch end without a touch start.\nTouch End: %s\n","Touch Bank: %s",T(a),U())}function T(a){return JSON.stringify({identifier:a.identifier,pageX:a.pageX,pageY:a.pageY,timestamp:l(a)})}function U(){var a=JSON.stringify(q.slice(0, 19 | 20));20: $ReadOnly<{ 11 | // This declaration is the public API 12 | 13 | type: string, 14 | payload: Arg, 15 | 16 | map( 17 | successTransform: (Result) => ResultPrime 18 | ): Task, 19 | 20 | bimap( 21 | successTransform: (Result) => ResultPrime, 22 | errorTransform: (Error) => ErrorPrime 23 | ): Task, 24 | 25 | chain( 26 | chainTransform: (Result) => Task<*, *, *, ResultPrime, ErrorPrime> 27 | ): Task 28 | }> = $ReadOnly<{ 29 | // This declaration is the private API. 30 | 31 | kind: 'regular', 32 | type: string, 33 | payload: Arg, 34 | 35 | /* 36 | * This is a little tricky. This `run` takes a lambda and calls either 37 | * the success or error handlers based on the result. We need this so 38 | * we can substitute applying effectful functions for mocking results 39 | * in test. 40 | */ 41 | run( 42 | BiApplicative, 43 | (Result) => mixed, 44 | (Error) => mixed, 45 | context: mixed 46 | ): mixed, 47 | 48 | map( 49 | successTransform: (Result) => ResultPrime 50 | ): Task, 51 | 52 | bimap( 53 | successTransform: (Result) => ResultPrime, 54 | errorTransform: (Error) => ErrorPrime 55 | ): Task, 56 | 57 | chain( 58 | chainTransform: (Result) => Task<*, *, *, ResultPrime, ErrorPrime> 59 | ): Task 60 | }>; 61 | 62 | // A function that does some side-effect when run. 63 | export type Effector = ( 64 | (Inbound) => mixed, 65 | (InboundError) => mixed, 66 | context: mixed 67 | ) => mixed; 68 | 69 | // A function that runs an effector for some environment. 70 | // In test, we provide one that doesn't call the effectful 71 | // function, instead providing a mock response. 72 | export type BiApplicative = ( 73 | Effector, 74 | (S) => mixed, 75 | (E) => mixed, 76 | mixed 77 | ) => mixed; 78 | 79 | // Private API for running a task. Do not use this directly. 80 | // We need this because Task is an opaque type, and we 81 | // hide `.run` outside this file. 82 | export function _run( 83 | task: Task<*, Inbound, InboundError, Result, ErrorT>, 84 | fnApplication: BiApplicative, 85 | success: Result => mixed, 86 | error: ErrorT => mixed, 87 | context?: mixed 88 | ): mixed { 89 | if (typeof task.run !== 'function') { 90 | throw new Error('Attempted to run something that is not a task.'); 91 | } 92 | return task.run(fnApplication, success, error, context); 93 | } 94 | 95 | /* 96 | * A function that takes some Arg and returns a new task. 97 | */ 98 | export type TaskCreator< 99 | Arg, 100 | +Inbound, 101 | +InboundError = mixed, 102 | -Result = Inbound, 103 | -Error = InboundError 104 | > = (Arg => Task) & $ReadOnly<{|type: string|}>; 105 | 106 | /** 107 | * A group of tasks, all of different types 108 | */ 109 | export type AnyTask = Task; 110 | export type AnyTasks = $ReadOnlyArray; 111 | 112 | /** 113 | * Tasks whose type must be disambiguated from their use 114 | * (because they were dynamically hoisted using `withTask`, for instance). 115 | */ 116 | export type MixedTask = Task; 117 | export type MixedTasks = $ReadOnlyArray; 118 | 119 | type Callback = ((err: Error) => mixed) & 120 | ((err: void, result: Result) => mixed); 121 | 122 | /** 123 | * ## `Task.fromCallback` 124 | * Returns a task-creator from a function that returns a promise. 125 | * 126 | * `arg => Promise` -> `arg => Task`. 127 | * 128 | * Uses the second arg as a label for debugging. 129 | */ 130 | export function fromPromise( 131 | fn: Arg => Promise, 132 | label: string 133 | ): TaskCreator { 134 | const creator = outbound => 135 | taskCreator_( 136 | (success, error) => fn(outbound).then(success, error), 137 | outbound, 138 | label 139 | ); 140 | creator.type = label; 141 | return (creator: any); 142 | } 143 | 144 | const noop = () => {}; 145 | 146 | /** 147 | * ## `Task.fromCallbackWithProgress` 148 | * Returns a task-creator from a function that returns a promise. 149 | * 150 | * `({arg, onProgress}) => Promise` -> `({arg, onProgress}) => Task`. 151 | * 152 | * Uses the second arg as a label for debugging. 153 | */ 154 | export function fromPromiseWithProgress( 155 | fn: ({arg: Arg, onProgress: any => void}) => Promise, 156 | label: string 157 | ): TaskCreator { 158 | const creator = ({arg, onProgress}) => { 159 | const task = taskCreator_( 160 | (success, error, context) => 161 | fn({ 162 | arg, 163 | onProgress: 164 | (context ? v => (context: any).onProgress(onProgress(v)) : noop) || 165 | noop 166 | }).then(success, error), 167 | {arg, onProgress}, 168 | label 169 | ); 170 | 171 | return task; 172 | }; 173 | 174 | creator.type = label; 175 | return (creator: any); 176 | } 177 | 178 | /** 179 | * `Task.fromCallback` 180 | * 181 | * Turn a node-style callback function: 182 | * `(arg, cb: (err, res) => void) => void`) 183 | * into a task creator of the same type. 184 | * 185 | * Uses the second arg as a label for debugging. 186 | */ 187 | export function fromCallback( 188 | fn: (Arg, Callback) => mixed, 189 | label: string 190 | ): TaskCreator { 191 | const creator = (outbound: Arg) => 192 | taskCreator_( 193 | (success, error) => 194 | fn(outbound, (err, result) => (err ? error(err) : success(result))), 195 | outbound, 196 | label 197 | ); 198 | creator.type = label; 199 | return (creator: any); 200 | } 201 | 202 | export type EffectReport = 'start' | 'success' | 'error'; 203 | 204 | /* 205 | * This is the private constructor for creating a Task object. End users 206 | * probably want to use `Task.fromCallback` or `task.fromPromise`. 207 | * It adds instrumentation to the effector, and also attaches some info 208 | * useful for making assertions in test. 209 | */ 210 | export function taskCreator_( 211 | effector: ( 212 | (Inbound) => mixed, 213 | (InboundError) => mixed, 214 | context?: mixed 215 | ) => mixed, 216 | payload: Arg, 217 | label: string 218 | ): Task { 219 | // Instrument the task with reporting 220 | const effectorPrime = (success, error, context) => { 221 | reportEffects('start', newTask, payload); 222 | return effector( 223 | result => { 224 | reportEffects('success', newTask, result); 225 | return success(result); 226 | }, 227 | reason => { 228 | reportEffects('error', newTask, reason); 229 | return error(reason); 230 | }, 231 | context 232 | ); 233 | }; 234 | 235 | effectorPrime.payload = payload; 236 | effectorPrime.type = label; 237 | 238 | const newTask = _task( 239 | payload, 240 | (runEffect, success, error, context) => 241 | runEffect(effectorPrime, success, error, context), 242 | label 243 | ); 244 | 245 | return newTask; 246 | } 247 | 248 | // Internal task constructor. 249 | // Note that payload is only kept around for testing/debugging purposes 250 | // It should not be introspected outside of test 251 | function _task( 252 | payload: Arg, 253 | next: ( 254 | runEffect: BiApplicative, 255 | (Result) => mixed, 256 | (Error) => mixed, 257 | context: mixed 258 | ) => mixed, 259 | label: string 260 | ): Task { 261 | return { 262 | label, 263 | type: label, 264 | payload, 265 | 266 | /* 267 | * Given the effector (or a mock), kicks off the task. 268 | * You (the end user) probably don't need to call this 269 | * directly. The middleware should handle it. 270 | */ 271 | run: next, 272 | 273 | /* 274 | * Public Task Methods 275 | */ 276 | chain, 277 | map, 278 | bimap 279 | }; 280 | 281 | function map( 282 | successTransform: Result => ResultPrime 283 | ): Task { 284 | return _task( 285 | payload, 286 | (runEffect, success, error, context) => 287 | next( 288 | runEffect, 289 | (result: Result) => success(successTransform(result)), 290 | error, 291 | context 292 | ), 293 | label 294 | ); 295 | } 296 | 297 | function bimap( 298 | successTransform: Result => ResultPrime, 299 | errorTransform: Error => ErrorPrime 300 | ): Task { 301 | return _task( 302 | payload, 303 | (runEffect, success, error, context) => 304 | next( 305 | runEffect, 306 | (result: Result) => success(successTransform(result)), 307 | (reason: Error) => error(errorTransform(reason)), 308 | context 309 | ), 310 | label 311 | ); 312 | } 313 | 314 | function chain( 315 | chainTransform: Result => Task<*, *, *, ResultPrime, ErrorPrime> 316 | ): Task { 317 | return _task( 318 | payload, 319 | (runEffect, success, error, context) => 320 | next( 321 | runEffect, 322 | (result: Result) => { 323 | const chainTask = chainTransform(result); 324 | return chainTask.run(runEffect, success, error, context); 325 | }, 326 | error, 327 | context 328 | ), 329 | `Chain(${label})` 330 | ); 331 | } 332 | } 333 | 334 | /* 335 | * Record the inputs/outputs of all tasks, for debugging or inspecting. 336 | * This feature should not be used to implement runtime behavior. 337 | */ 338 | let reportEffects: ( 339 | event: EffectReport, 340 | task: AnyTask, 341 | payload: mixed 342 | ) => void = (event: EffectReport, task: AnyTask, payload: mixed) => {}; 343 | 344 | /** 345 | * ## `reportTasksForTesting` 346 | * 347 | * Takes a function that is called whenever a task is dispatched, 348 | * returns, or errors. 349 | * 350 | * Note that only one function can be registered with this hook. 351 | * The last provided function is the one that takes effect. 352 | */ 353 | export function reportTasksForTesting( 354 | fn: (event: EffectReport, task: AnyTask, payload: mixed) => void 355 | ): void { 356 | reportEffects = fn; 357 | } 358 | 359 | // type level utils functions needed for Task.all 360 | type ExtractArg = (Task) => O; 361 | type ExtractResult = (Task<*, *, *, R>) => R; 362 | type ExtractError = (Task<*, *, *, *, E>) => E; 363 | 364 | /* 365 | * ## `Task.all` 366 | * 367 | * Given an array of Tasks, returns a new task that runs all the effects 368 | * of the original in parallel, with an array result where each element 369 | * corresponds to a task. 370 | * 371 | * Acts like `Promise.all`. 372 | */ 373 | export function all>>( 374 | tasks: AllTasks 375 | ): Task< 376 | $TupleMap, 377 | *, 378 | *, 379 | $TupleMap, 380 | mixed 381 | > { 382 | return _task( 383 | tasks.map(task => task.payload), 384 | ( 385 | runEffect, 386 | success: ($TupleMap) => mixed, 387 | error, 388 | context 389 | ) => { 390 | if (tasks.length === 0) { 391 | return success([]); 392 | } 393 | const accumulated = Array(tasks.length); 394 | let complete = 0; 395 | let errorValue = null; 396 | 397 | function allSuccess(index) { 398 | return value => { 399 | if (errorValue) { 400 | return; 401 | } 402 | accumulated[index] = value; 403 | complete += 1; 404 | if (complete === tasks.length) { 405 | return success(accumulated); 406 | } 407 | }; 408 | } 409 | 410 | function anyError(err) { 411 | if (!err) { 412 | return; 413 | } 414 | errorValue = err; 415 | return error(errorValue); 416 | } 417 | 418 | return Promise.all( 419 | tasks.map((task, index) => 420 | task.run(runEffect, allSuccess(index), anyError, context) 421 | ) 422 | ); 423 | }, 424 | 425 | 'Task.all(' + tasks.map(({type}) => type).join(', ') + ')' 426 | ); 427 | } 428 | 429 | type ExtractSettled = ( 430 | Task<*, *, *, R, E> 431 | ) => {|status: 'fulfilled', value: R|} | {|status: 'rejected', value: E|}; 432 | 433 | /* 434 | * ## `Task.allSettled` 435 | * 436 | * Given an array of Tasks, returns a new task that runs all the effects 437 | * of the original in parallel, with an array result where each element 438 | * corresponds to a task. 439 | * 440 | * Acts like `Promise.allSettled`. 441 | */ 442 | export function allSettled>>( 443 | tasks: AllTasks 444 | ): Task< 445 | $TupleMap, 446 | *, 447 | *, 448 | $TupleMap, 449 | mixed 450 | > { 451 | return _task( 452 | tasks.map(task => task.payload), 453 | ( 454 | runEffect, 455 | success: ($TupleMap) => mixed, 456 | error, 457 | context 458 | ) => { 459 | if (tasks.length === 0) { 460 | return success([]); 461 | } 462 | const accumulated = Array(tasks.length); 463 | let complete = 0; 464 | 465 | function onOneTaskFinish(index, status) { 466 | return value => { 467 | accumulated[index] = {status, value}; 468 | complete += 1; 469 | if (complete === tasks.length) { 470 | return success(accumulated); 471 | } 472 | }; 473 | } 474 | 475 | return (Promise: any).allSettled( 476 | tasks.map((task, index) => 477 | task.run( 478 | runEffect, 479 | onOneTaskFinish(index, 'fulfilled'), 480 | onOneTaskFinish(index, 'rejected'), 481 | context 482 | ) 483 | ) 484 | ); 485 | }, 486 | 487 | 'Task.allSettled(' + tasks.map(({type}) => type).join(', ') + ')' 488 | ); 489 | } 490 | -------------------------------------------------------------------------------- /src/react-dom/cjs/react-dom-server.browser.production.min.js: -------------------------------------------------------------------------------- 1 | /** @license React v16.8.4+patch 2 | * react-dom-server.browser.production.min.js 3 | * 4 | * Copyright (c) Facebook, Inc. and its affiliates. 5 | * 6 | * This source code is licensed under the MIT license found in the 7 | * LICENSE file in the root directory of this source tree. 8 | */ 9 | 10 | 'use strict';var p=require("object-assign"),q=require("react");function aa(a,b,d,c,f,e,h,g){if(!a){a=void 0;if(void 0===b)a=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var D=[d,c,f,e,h,g],B=0;a=Error(b.replace(/%s/g,function(){return D[B++]}));a.name="Invariant Violation"}a.framesToPop=1;throw a;}} 11 | function r(a){for(var b=arguments.length-1,d="https://reactjs.org/docs/error-decoder.html?invariant="+a,c=0;cH;H++)G[H]=H+1;G[15]=0; 16 | var ma=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,na=Object.prototype.hasOwnProperty,oa={},pa={}; 17 | function qa(a){if(na.call(pa,a))return!0;if(na.call(oa,a))return!1;if(ma.test(a))return pa[a]=!0;oa[a]=!0;return!1}function ra(a,b,d,c){if(null!==d&&0===d.type)return!1;switch(typeof b){case "function":case "symbol":return!0;case "boolean":if(c)return!1;if(null!==d)return!d.acceptsBooleans;a=a.toLowerCase().slice(0,5);return"data-"!==a&&"aria-"!==a;default:return!1}} 18 | function sa(a,b,d,c){if(null===b||"undefined"===typeof b||ra(a,b,d,c))return!0;if(c)return!1;if(null!==d)switch(d.type){case 3:return!b;case 4:return!1===b;case 5:return isNaN(b);case 6:return isNaN(b)||1>b}return!1}function I(a,b,d,c,f){this.acceptsBooleans=2===b||3===b||4===b;this.attributeName=c;this.attributeNamespace=f;this.mustUseProperty=d;this.propertyName=a;this.type=b}var J={}; 19 | "children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(a){J[a]=new I(a,0,!1,a,null)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(a){var b=a[0];J[b]=new I(b,1,!1,a[1],null)});["contentEditable","draggable","spellCheck","value"].forEach(function(a){J[a]=new I(a,2,!1,a.toLowerCase(),null)}); 20 | ["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(a){J[a]=new I(a,2,!1,a,null)});"allowFullScreen async autoFocus autoPlay controls default defer disabled formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(a){J[a]=new I(a,3,!1,a.toLowerCase(),null)});["checked","multiple","muted","selected"].forEach(function(a){J[a]=new I(a,3,!0,a,null)}); 21 | ["capture","download"].forEach(function(a){J[a]=new I(a,4,!1,a,null)});["cols","rows","size","span"].forEach(function(a){J[a]=new I(a,6,!1,a,null)});["rowSpan","start"].forEach(function(a){J[a]=new I(a,5,!1,a.toLowerCase(),null)});var K=/[\-:]([a-z])/g;function L(a){return a[1].toUpperCase()} 22 | "accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(a){var b=a.replace(K, 23 | L);J[b]=new I(b,1,!1,a,null)});"xlink:actuate xlink:arcrole xlink:href xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(a){var b=a.replace(K,L);J[b]=new I(b,1,!1,a,"http://www.w3.org/1999/xlink")});["xml:base","xml:lang","xml:space"].forEach(function(a){var b=a.replace(K,L);J[b]=new I(b,1,!1,a,"http://www.w3.org/XML/1998/namespace")});["tabIndex","crossOrigin"].forEach(function(a){J[a]=new I(a,1,!1,a.toLowerCase(),null)});var ta=/["'&<>]/; 24 | function M(a){if("boolean"===typeof a||"number"===typeof a)return""+a;a=""+a;var b=ta.exec(a);if(b){var d="",c,f=0;for(c=b.index;cU?void 0:r("301");if(a===N)if(S=!0,a={action:d,next:null},null===T&&(T=new Map),d=T.get(b),void 0===d)T.set(b,a);else{for(b=d;null!==b.next;)b=b.next;b.next=a}}function za(){} 28 | var X=0,Aa={readContext:function(a){var b=X;F(a,b);return a[b]},useContext:function(a){V();var b=X;F(a,b);return a[b]},useMemo:function(a,b){N=V();P=W();b=void 0===b?null:b;if(null!==P){var d=P.memoizedState;if(null!==d&&null!==b){a:{var c=d[1];if(null===c)c=!1;else{for(var f=0;f=e?void 0:r("304");var h=new Uint16Array(e);h.set(f);G=h;G[0]=c+1;for(f=c;f=g.children.length){var D=g.footer;""!==D&&(this.previousWasTextNode=!1);this.stack.pop();if("select"===g.type)this.currentSelectValue=null;else if(null!=g.type&&null!=g.type.type&&g.type.type.$$typeof===z)this.popProvider(g.type);else if(g.type===A){this.suspenseDepth--;var B=f.pop();if(e){e=!1;var n=g.fallbackFrame;n?void 0:r("303");this.stack.push(n);continue}else f[this.suspenseDepth]+=B}f[this.suspenseDepth]+= 41 | D}else{var l=g.children[g.childIndex++],k="";try{k+=this.render(l,g.context,g.domNamespace)}catch(t){throw t;}finally{}f.length<=this.suspenseDepth&&f.push("");f[this.suspenseDepth]+=k}}return f[0]}finally{Ia.current=c,X=b}};a.prototype.render=function(a,d,c){if("string"===typeof a||"number"===typeof a){c=""+a;if(""===c)return"";if(this.makeStaticMarkup)return M(c);if(this.previousWasTextNode)return"\x3c!-- --\x3e"+M(c);this.previousWasTextNode=!0;return M(c)}d=Ra(a,d,this.threadID);a=d.child;d=d.context; 42 | if(null===a||!1===a)return"";if(!q.isValidElement(a)){if(null!=a&&null!=a.$$typeof){var b=a.$$typeof;b===ba?r("257"):void 0;r("258",b.toString())}a=Z(a);this.stack.push({type:null,domNamespace:c,children:a,childIndex:0,context:d,footer:""});return""}b=a.type;if("string"===typeof b)return this.renderDOM(a,d,c);switch(b){case ca:case fa:case da:case x:return a=Z(a.props.children),this.stack.push({type:null,domNamespace:c,children:a,childIndex:0,context:d,footer:""}),"";case A:r("294")}if("object"=== 43 | typeof b&&null!==b)switch(b.$$typeof){case ha:N={};var e=b.render(a.props,a.ref);e=va(b.render,a.props,e,a.ref);e=Z(e);this.stack.push({type:null,domNamespace:c,children:e,childIndex:0,context:d,footer:""});return"";case ia:return a=[q.createElement(b.type,p({ref:a.ref},a.props))],this.stack.push({type:null,domNamespace:c,children:a,childIndex:0,context:d,footer:""}),"";case z:return b=Z(a.props.children),c={type:a,domNamespace:c,children:b,childIndex:0,context:d,footer:""},this.pushProvider(a),this.stack.push(c), 44 | "";case ea:b=a.type;e=a.props;var h=this.threadID;F(b,h);b=Z(e.children(b[h]));this.stack.push({type:a,domNamespace:c,children:b,childIndex:0,context:d,footer:""});return"";case ja:r("295")}r("130",null==b?b:typeof b,"")};a.prototype.renderDOM=function(a,d,c){var b=a.type.toLowerCase();c===Ba.html&&Ca(b);La.hasOwnProperty(b)||(Ka.test(b)?void 0:r("65",b),La[b]=!0);var e=a.props;if("input"===b)e=p({type:void 0},e,{defaultChecked:void 0,defaultValue:void 0,value:null!=e.value?e.value:e.defaultValue, 45 | checked:null!=e.checked?e.checked:e.defaultChecked});else if("textarea"===b){var h=e.value;if(null==h){h=e.defaultValue;var g=e.children;null!=g&&(null!=h?r("92"):void 0,Array.isArray(g)&&(1>=g.length?void 0:r("93"),g=g[0]),h=""+g);null==h&&(h="")}e=p({},e,{value:void 0,children:""+h})}else if("select"===b)this.currentSelectValue=null!=e.value?e.value:e.defaultValue,e=p({},e,{value:void 0});else if("option"===b){g=this.currentSelectValue;var D=Na(e.children);if(null!=g){var B=null!=e.value?e.value+ 46 | "":D;h=!1;if(Array.isArray(g))for(var n=0;n":(y+=">",h="");a:{g=e.dangerouslySetInnerHTML;if(null!=g){if(null!=g.__html){g=g.__html;break a}}else if(g=e.children,"string"===typeof g||"number"===typeof g){g=M(g);break a}g=null}null!=g?(e=[],Ja[b]&&"\n"===g.charAt(0)&&(y+="\n"),y+=g):e=Z(e.children);a=a.type;c=null==c||"http://www.w3.org/1999/xhtml"=== 50 | c?Ca(a):"http://www.w3.org/2000/svg"===c&&"foreignObject"===a?"http://www.w3.org/1999/xhtml":c;this.stack.push({domNamespace:c,type:b,children:e,childIndex:0,context:d,footer:h});this.previousWasTextNode=!1;return y};return a}(),Ta={renderToString:function(a){a=new Sa(a,!1);try{return a.read(Infinity)}finally{a.destroy()}},renderToStaticMarkup:function(a){a=new Sa(a,!0);try{return a.read(Infinity)}finally{a.destroy()}},renderToNodeStream:function(){r("207")},renderToStaticNodeStream:function(){r("208")}, 51 | version:"16.8.4"},Ua={default:Ta},Va=Ua&&Ta||Ua;module.exports=Va.default||Va; 52 | -------------------------------------------------------------------------------- /src/react-dom/umd/react-dom-server.browser.production.min.js: -------------------------------------------------------------------------------- 1 | /** @license React v16.8.4+patch 2 | * react-dom-server.browser.production.min.js 3 | * 4 | * Copyright (c) Facebook, Inc. and its affiliates. 5 | * 6 | * This source code is licensed under the MIT license found in the 7 | * LICENSE file in the root directory of this source tree. 8 | */ 9 | 'use strict';(function(v,E){"object"===typeof exports&&"undefined"!==typeof module?module.exports=E(require("react")):"function"===typeof define&&define.amd?define(["react"],E):v.ReactDOMServer=E(v.React)})(this,function(v){function E(a,b,d,c,f,e,h,g){if(!a){a=void 0;if(void 0===b)a=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var k=[d,c,f,e,h,g],u=0;a=Error(b.replace(/%s/g,function(){return k[u++]}));a.name= 10 | "Invariant Violation"}a.framesToPop=1;throw a;}}function u(a){for(var b=arguments.length-1,d="https://reactjs.org/docs/error-decoder.html?invariant="+a,c=0;cb}return!1}function t(a,b,d,c,f){this.acceptsBooleans=2===b||3===b||4===b;this.attributeName=c;this.attributeNamespace=f;this.mustUseProperty=d;this.propertyName=a;this.type=b}function C(a){if("boolean"===typeof a||"number"=== 14 | typeof a)return""+a;a=""+a;var b=ya.exec(a);if(b){var d="",c,f=0;for(c=b.index;cL?void 0:u("301");if(a===x)if(R=!0,a={action:d,next:null},null===A&&(A=new Map),d=A.get(b),void 0===d)A.set(b,a);else{for(b=d;null!==b.next;)b=b.next;b.next=a}}function S(){}function pa(a){switch(a){case "svg":return"http://www.w3.org/2000/svg";case "math":return"http://www.w3.org/1998/Math/MathML";default:return"http://www.w3.org/1999/xhtml"}}function Aa(a){if(void 0===a||null===a)return a; 17 | var b="";v.Children.forEach(a,function(a){null!=a&&(b+=a)});return b}function qa(a,b){void 0===a&&u("152",J(b)||"Component")}function Ba(a,b,d){function c(c,f){var e=ua(f,b,d),g=[],h=!1,m={isMounted:function(a){return!1},enqueueForceUpdate:function(a){if(null===g)return null},enqueueReplaceState:function(a,b){h=!0;g=[b]},enqueueSetState:function(a,b){if(null===g)return null;g.push(b)}},l=void 0;if(f.prototype&&f.prototype.isReactComponent){if(l=new f(c.props,e,m),"function"===typeof f.getDerivedStateFromProps){var k= 18 | f.getDerivedStateFromProps.call(null,c.props,l.state);null!=k&&(l.state=z({},l.state,k))}}else if(x={},l=f(c.props,e,m),l=ma(f,c.props,l,e),null==l||null==l.render){a=l;qa(a,f);return}l.props=c.props;l.context=e;l.updater=m;m=l.state;void 0===m&&(l.state=m=null);if("function"===typeof l.UNSAFE_componentWillMount||"function"===typeof l.componentWillMount)if("function"===typeof l.componentWillMount&&"function"!==typeof f.getDerivedStateFromProps&&l.componentWillMount(),"function"===typeof l.UNSAFE_componentWillMount&& 19 | "function"!==typeof f.getDerivedStateFromProps&&l.UNSAFE_componentWillMount(),g.length){m=g;var n=h;g=null;h=!1;if(n&&1===m.length)l.state=m[0];else{k=n?m[0]:l.state;var p=!0;for(n=n?1:0;nD;D++)q[D]=D+1;q[15]=0;var va=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/, 22 | ia=Object.prototype.hasOwnProperty,ka={},ja={},w={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(a){w[a]=new t(a,0,!1,a,null)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(a){var b=a[0];w[b]=new t(b,1,!1,a[1],null)});["contentEditable","draggable","spellCheck","value"].forEach(function(a){w[a]=new t(a,2,!1, 23 | a.toLowerCase(),null)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(a){w[a]=new t(a,2,!1,a,null)});"allowFullScreen async autoFocus autoPlay controls default defer disabled formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(a){w[a]=new t(a,3,!1,a.toLowerCase(),null)});["checked","multiple","muted","selected"].forEach(function(a){w[a]=new t(a,3,!0,a,null)});["capture", 24 | "download"].forEach(function(a){w[a]=new t(a,4,!1,a,null)});["cols","rows","size","span"].forEach(function(a){w[a]=new t(a,6,!1,a,null)});["rowSpan","start"].forEach(function(a){w[a]=new t(a,5,!1,a.toLowerCase(),null)});var T=/[\-:]([a-z])/g,U=function(a){return a[1].toUpperCase()};"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(a){var b= 25 | a.replace(T,U);w[b]=new t(b,1,!1,a,null)});"xlink:actuate xlink:arcrole xlink:href xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(a){var b=a.replace(T,U);w[b]=new t(b,1,!1,a,"http://www.w3.org/1999/xlink")});["xml:base","xml:lang","xml:space"].forEach(function(a){var b=a.replace(T,U);w[b]=new t(b,1,!1,a,"http://www.w3.org/XML/1998/namespace")});["tabIndex","crossOrigin"].forEach(function(a){w[a]=new t(a,1,!1,a.toLowerCase(),null)});var ya=/["'&<>]/,x=null,M=null,k=null, 26 | G=!1,R=!1,A=null,L=0,H=0,Da={readContext:function(a,b){b=H;F(a,b);return a[b]},useContext:function(a,b){K();b=H;F(a,b);return a[b]},useMemo:function(a,b){x=K();k=Q();b=void 0===b?null:b;if(null!==k){var d=k.memoizedState;if(null!==d&&null!==b){a:{var c=d[1];if(null===c)c=!1;else{for(var f=0;f=e?void 0:u("304");var h=new Uint16Array(e);h.set(f);q=h;q[0]=c+1;for(f=c;f=g.children.length){var k=g.footer;""!==k&&(this.previousWasTextNode=!1);this.stack.pop();if("select"===g.type)this.currentSelectValue=null;else if(null!=g.type&&null!=g.type.type&&g.type.type.$$typeof===P)this.popProvider(g.type);else if(g.type===O){this.suspenseDepth--;var p=f.pop();if(e){e=!1;var r=g.fallbackFrame;r?void 0:u("303");this.stack.push(r);continue}else f[this.suspenseDepth]+=p}f[this.suspenseDepth]+=k}else{var m=g.children[g.childIndex++],l="";try{l+=this.render(m, 34 | g.context,g.domNamespace)}catch(Ca){throw Ca;}finally{}f.length<=this.suspenseDepth&&f.push("");f[this.suspenseDepth]+=l}}return f[0]}finally{V.current=c,H=b}};a.prototype.render=function(a,d,c){if("string"===typeof a||"number"===typeof a){c=""+a;if(""===c)return"";if(this.makeStaticMarkup)return C(c);if(this.previousWasTextNode)return"\x3c!-- --\x3e"+C(c);this.previousWasTextNode=!0;return C(c)}d=Ba(a,d,this.threadID);a=d.child;d=d.context;if(null===a||!1===a)return"";if(!v.isValidElement(a)){if(null!= 35 | a&&null!=a.$$typeof){var b=a.$$typeof;b===Y?u("257"):void 0;u("258",b.toString())}a=B(a);this.stack.push({type:null,domNamespace:c,children:a,childIndex:0,context:d,footer:""});return""}b=a.type;if("string"===typeof b)return this.renderDOM(a,d,c);switch(b){case aa:case X:case Z:case N:return a=B(a.props.children),this.stack.push({type:null,domNamespace:c,children:a,childIndex:0,context:d,footer:""}),"";case O:u("294")}if("object"===typeof b&&null!==b)switch(b.$$typeof){case ca:x={};var e=b.render(a.props, 36 | a.ref);e=ma(b.render,a.props,e,a.ref);e=B(e);this.stack.push({type:null,domNamespace:c,children:e,childIndex:0,context:d,footer:""});return"";case da:return a=[v.createElement(b.type,z({ref:a.ref},a.props))],this.stack.push({type:null,domNamespace:c,children:a,childIndex:0,context:d,footer:""}),"";case P:return b=B(a.props.children),c={type:a,domNamespace:c,children:b,childIndex:0,context:d,footer:""},this.pushProvider(a),this.stack.push(c),"";case ba:b=a.type;e=a.props;var h=this.threadID;F(b,h); 37 | b=B(e.children(b[h]));this.stack.push({type:a,domNamespace:c,children:b,childIndex:0,context:d,footer:""});return"";case ea:u("295")}u("130",null==b?b:typeof b,"")};a.prototype.renderDOM=function(a,d,c){var b=a.type.toLowerCase();"http://www.w3.org/1999/xhtml"===c&&pa(b);sa.hasOwnProperty(b)||(Ja.test(b)?void 0:u("65",b),sa[b]=!0);var e=a.props;if("input"===b)e=z({type:void 0},e,{defaultChecked:void 0,defaultValue:void 0,value:null!=e.value?e.value:e.defaultValue,checked:null!=e.checked?e.checked: 38 | e.defaultChecked});else if("textarea"===b){var h=e.value;if(null==h){h=e.defaultValue;var g=e.children;null!=g&&(null!=h?u("92"):void 0,Array.isArray(g)&&(1>=g.length?void 0:u("93"),g=g[0]),h=""+g);null==h&&(h="")}e=z({},e,{value:void 0,children:""+h})}else if("select"===b)this.currentSelectValue=null!=e.value?e.value:e.defaultValue,e=z({},e,{value:void 0});else if("option"===b){g=this.currentSelectValue;var k=Aa(e.children);if(null!=g){var p=null!=e.value?e.value+"":k;h=!1;if(Array.isArray(g))for(var r= 39 | 0;r":(y+=">",h="");a:{g=e.dangerouslySetInnerHTML;if(null!=g){if(null!=g.__html){g=g.__html;break a}}else if(g=e.children,"string"===typeof g||"number"===typeof g){g=C(g);break a}g=null}null!=g?(e=[],Ia[b]&&"\n"===g.charAt(0)&&(y+="\n"),y+=g):e=B(e.children);a=a.type;c=null==c||"http://www.w3.org/1999/xhtml"===c?pa(a):"http://www.w3.org/2000/svg"=== 43 | c&&"foreignObject"===a?"http://www.w3.org/1999/xhtml":c;this.stack.push({domNamespace:c,type:b,children:e,childIndex:0,context:d,footer:h});this.previousWasTextNode=!1;return y};return a}();p={renderToString:function(a){a=new ta(a,!1);try{return a.read(Infinity)}finally{a.destroy()}},renderToStaticMarkup:function(a){a=new ta(a,!0);try{return a.read(Infinity)}finally{a.destroy()}},renderToNodeStream:function(){u("207")},renderToStaticNodeStream:function(){u("208")},version:"16.8.4"};p=(D={default:p}, 44 | p)||D;return p.default||p}); 45 | -------------------------------------------------------------------------------- /src/react-dom/cjs/react-dom-server.node.production.min.js: -------------------------------------------------------------------------------- 1 | /** @license React v16.8.4+patch 2 | * react-dom-server.node.production.min.js 3 | * 4 | * Copyright (c) Facebook, Inc. and its affiliates. 5 | * 6 | * This source code is licensed under the MIT license found in the 7 | * LICENSE file in the root directory of this source tree. 8 | */ 9 | 10 | 'use strict';var p=require("object-assign"),q=require("react"),aa=require("stream");function ba(a,b,d,c,f,e,h,g){if(!a){a=void 0;if(void 0===b)a=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var D=[d,c,f,e,h,g],B=0;a=Error(b.replace(/%s/g,function(){return D[B++]}));a.name="Invariant Violation"}a.framesToPop=1;throw a;}} 11 | function r(a){for(var b=arguments.length-1,d="https://reactjs.org/docs/error-decoder.html?invariant="+a,c=0;cH;H++)G[H]=H+1;G[15]=0; 16 | var na=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,oa=Object.prototype.hasOwnProperty,pa={},qa={}; 17 | function ra(a){if(oa.call(qa,a))return!0;if(oa.call(pa,a))return!1;if(na.test(a))return qa[a]=!0;pa[a]=!0;return!1}function sa(a,b,d,c){if(null!==d&&0===d.type)return!1;switch(typeof b){case "function":case "symbol":return!0;case "boolean":if(c)return!1;if(null!==d)return!d.acceptsBooleans;a=a.toLowerCase().slice(0,5);return"data-"!==a&&"aria-"!==a;default:return!1}} 18 | function ta(a,b,d,c){if(null===b||"undefined"===typeof b||sa(a,b,d,c))return!0;if(c)return!1;if(null!==d)switch(d.type){case 3:return!b;case 4:return!1===b;case 5:return isNaN(b);case 6:return isNaN(b)||1>b}return!1}function I(a,b,d,c,f){this.acceptsBooleans=2===b||3===b||4===b;this.attributeName=c;this.attributeNamespace=f;this.mustUseProperty=d;this.propertyName=a;this.type=b}var J={}; 19 | "children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(a){J[a]=new I(a,0,!1,a,null)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(a){var b=a[0];J[b]=new I(b,1,!1,a[1],null)});["contentEditable","draggable","spellCheck","value"].forEach(function(a){J[a]=new I(a,2,!1,a.toLowerCase(),null)}); 20 | ["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(a){J[a]=new I(a,2,!1,a,null)});"allowFullScreen async autoFocus autoPlay controls default defer disabled formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(a){J[a]=new I(a,3,!1,a.toLowerCase(),null)});["checked","multiple","muted","selected"].forEach(function(a){J[a]=new I(a,3,!0,a,null)}); 21 | ["capture","download"].forEach(function(a){J[a]=new I(a,4,!1,a,null)});["cols","rows","size","span"].forEach(function(a){J[a]=new I(a,6,!1,a,null)});["rowSpan","start"].forEach(function(a){J[a]=new I(a,5,!1,a.toLowerCase(),null)});var K=/[\-:]([a-z])/g;function L(a){return a[1].toUpperCase()} 22 | "accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(a){var b=a.replace(K, 23 | L);J[b]=new I(b,1,!1,a,null)});"xlink:actuate xlink:arcrole xlink:href xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(a){var b=a.replace(K,L);J[b]=new I(b,1,!1,a,"http://www.w3.org/1999/xlink")});["xml:base","xml:lang","xml:space"].forEach(function(a){var b=a.replace(K,L);J[b]=new I(b,1,!1,a,"http://www.w3.org/XML/1998/namespace")});["tabIndex","crossOrigin"].forEach(function(a){J[a]=new I(a,1,!1,a.toLowerCase(),null)});var ua=/["'&<>]/; 24 | function M(a){if("boolean"===typeof a||"number"===typeof a)return""+a;a=""+a;var b=ua.exec(a);if(b){var d="",c,f=0;for(c=b.index;cU?void 0:r("301");if(a===N)if(S=!0,a={action:d,next:null},null===T&&(T=new Map),d=T.get(b),void 0===d)T.set(b,a);else{for(b=d;null!==b.next;)b=b.next;b.next=a}}function Aa(){} 28 | var X=0,Ba={readContext:function(a){var b=X;F(a,b);return a[b]},useContext:function(a){V();var b=X;F(a,b);return a[b]},useMemo:function(a,b){N=V();P=W();b=void 0===b?null:b;if(null!==P){var d=P.memoizedState;if(null!==d&&null!==b){a:{var c=d[1];if(null===c)c=!1;else{for(var f=0;f=e?void 0:r("304");var h=new Uint16Array(e);h.set(f);G=h;G[0]=c+1;for(f=c;f=g.children.length){var D=g.footer;""!==D&&(this.previousWasTextNode=!1);this.stack.pop();if("select"===g.type)this.currentSelectValue=null;else if(null!=g.type&&null!=g.type.type&&g.type.type.$$typeof===z)this.popProvider(g.type);else if(g.type===A){this.suspenseDepth--;var B=f.pop();if(e){e=!1;var n=g.fallbackFrame;n?void 0:r("303");this.stack.push(n);continue}else f[this.suspenseDepth]+=B}f[this.suspenseDepth]+= 41 | D}else{var l=g.children[g.childIndex++],k="";try{k+=this.render(l,g.context,g.domNamespace)}catch(t){throw t;}finally{}f.length<=this.suspenseDepth&&f.push("");f[this.suspenseDepth]+=k}}return f[0]}finally{Ja.current=c,X=b}};a.prototype.render=function(a,d,c){if("string"===typeof a||"number"===typeof a){c=""+a;if(""===c)return"";if(this.makeStaticMarkup)return M(c);if(this.previousWasTextNode)return"\x3c!-- --\x3e"+M(c);this.previousWasTextNode=!0;return M(c)}d=Sa(a,d,this.threadID);a=d.child;d=d.context; 42 | if(null===a||!1===a)return"";if(!q.isValidElement(a)){if(null!=a&&null!=a.$$typeof){var b=a.$$typeof;b===ca?r("257"):void 0;r("258",b.toString())}a=Z(a);this.stack.push({type:null,domNamespace:c,children:a,childIndex:0,context:d,footer:""});return""}b=a.type;if("string"===typeof b)return this.renderDOM(a,d,c);switch(b){case da:case ha:case ea:case x:return a=Z(a.props.children),this.stack.push({type:null,domNamespace:c,children:a,childIndex:0,context:d,footer:""}),"";case A:r("294")}if("object"=== 43 | typeof b&&null!==b)switch(b.$$typeof){case ia:N={};var e=b.render(a.props,a.ref);e=wa(b.render,a.props,e,a.ref);e=Z(e);this.stack.push({type:null,domNamespace:c,children:e,childIndex:0,context:d,footer:""});return"";case ja:return a=[q.createElement(b.type,p({ref:a.ref},a.props))],this.stack.push({type:null,domNamespace:c,children:a,childIndex:0,context:d,footer:""}),"";case z:return b=Z(a.props.children),c={type:a,domNamespace:c,children:b,childIndex:0,context:d,footer:""},this.pushProvider(a),this.stack.push(c), 44 | "";case fa:b=a.type;e=a.props;var h=this.threadID;F(b,h);b=Z(e.children(b[h]));this.stack.push({type:a,domNamespace:c,children:b,childIndex:0,context:d,footer:""});return"";case ka:r("295")}r("130",null==b?b:typeof b,"")};a.prototype.renderDOM=function(a,d,c){var b=a.type.toLowerCase();c===Ca.html&&Da(b);Ma.hasOwnProperty(b)||(La.test(b)?void 0:r("65",b),Ma[b]=!0);var e=a.props;if("input"===b)e=p({type:void 0},e,{defaultChecked:void 0,defaultValue:void 0,value:null!=e.value?e.value:e.defaultValue, 45 | checked:null!=e.checked?e.checked:e.defaultChecked});else if("textarea"===b){var h=e.value;if(null==h){h=e.defaultValue;var g=e.children;null!=g&&(null!=h?r("92"):void 0,Array.isArray(g)&&(1>=g.length?void 0:r("93"),g=g[0]),h=""+g);null==h&&(h="")}e=p({},e,{value:void 0,children:""+h})}else if("select"===b)this.currentSelectValue=null!=e.value?e.value:e.defaultValue,e=p({},e,{value:void 0});else if("option"===b){g=this.currentSelectValue;var D=Oa(e.children);if(null!=g){var B=null!=e.value?e.value+ 46 | "":D;h=!1;if(Array.isArray(g))for(var n=0;n":(y+=">",h="");a:{g=e.dangerouslySetInnerHTML;if(null!=g){if(null!=g.__html){g=g.__html;break a}}else if(g=e.children,"string"===typeof g||"number"===typeof g){g=M(g);break a}g=null}null!=g?(e=[],Ka[b]&&"\n"===g.charAt(0)&&(y+="\n"),y+=g):e=Z(e.children);a=a.type;c=null==c||"http://www.w3.org/1999/xhtml"=== 50 | c?Da(a):"http://www.w3.org/2000/svg"===c&&"foreignObject"===a?"http://www.w3.org/1999/xhtml":c;this.stack.push({domNamespace:c,type:b,children:e,childIndex:0,context:d,footer:h});this.previousWasTextNode=!1;return y};return a}(); 51 | function Ua(a,b){if("function"!==typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function, not "+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}});b&&(Object.setPrototypeOf?Object.setPrototypeOf(a,b):a.__proto__=b)} 52 | var Va=function(a){function b(d,c){if(!(this instanceof b))throw new TypeError("Cannot call a class as a function");var f=a.call(this,{});if(!this)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");f=!f||"object"!==typeof f&&"function"!==typeof f?this:f;f.partialRenderer=new Ta(d,c);return f}Ua(b,a);b.prototype._destroy=function(a,b){this.partialRenderer.destroy();b(a)};b.prototype._read=function(a){try{this.push(this.partialRenderer.read(a))}catch(c){this.destroy(c)}}; 53 | return b}(aa.Readable),Wa={renderToString:function(a){a=new Ta(a,!1);try{return a.read(Infinity)}finally{a.destroy()}},renderToStaticMarkup:function(a){a=new Ta(a,!0);try{return a.read(Infinity)}finally{a.destroy()}},renderToNodeStream:function(a){return new Va(a,!1)},renderToStaticNodeStream:function(a){return new Va(a,!0)},version:"16.8.4"},Xa={default:Wa},Ya=Xa&&Wa||Xa;module.exports=Ya.default||Ya; 54 | -------------------------------------------------------------------------------- /flow-typed/npm/jest_v22.x.x.js: -------------------------------------------------------------------------------- 1 | // flow-typed signature: 6e1fc0a644aa956f79029fec0709e597 2 | // flow-typed version: 07ebad4796/jest_v22.x.x/flow_>=v0.39.x 3 | 4 | type JestMockFn, TReturn> = { 5 | (...args: TArguments): TReturn, 6 | /** 7 | * An object for introspecting mock calls 8 | */ 9 | mock: { 10 | /** 11 | * An array that represents all calls that have been made into this mock 12 | * function. Each call is represented by an array of arguments that were 13 | * passed during the call. 14 | */ 15 | calls: Array, 16 | /** 17 | * An array that contains all the object instances that have been 18 | * instantiated from this mock function. 19 | */ 20 | instances: Array 21 | }, 22 | /** 23 | * Resets all information stored in the mockFn.mock.calls and 24 | * mockFn.mock.instances arrays. Often this is useful when you want to clean 25 | * up a mock's usage data between two assertions. 26 | */ 27 | mockClear(): void, 28 | /** 29 | * Resets all information stored in the mock. This is useful when you want to 30 | * completely restore a mock back to its initial state. 31 | */ 32 | mockReset(): void, 33 | /** 34 | * Removes the mock and restores the initial implementation. This is useful 35 | * when you want to mock functions in certain test cases and restore the 36 | * original implementation in others. Beware that mockFn.mockRestore only 37 | * works when mock was created with jest.spyOn. Thus you have to take care of 38 | * restoration yourself when manually assigning jest.fn(). 39 | */ 40 | mockRestore(): void, 41 | /** 42 | * Accepts a function that should be used as the implementation of the mock. 43 | * The mock itself will still record all calls that go into and instances 44 | * that come from itself -- the only difference is that the implementation 45 | * will also be executed when the mock is called. 46 | */ 47 | mockImplementation( 48 | fn: (...args: TArguments) => TReturn 49 | ): JestMockFn, 50 | /** 51 | * Accepts a function that will be used as an implementation of the mock for 52 | * one call to the mocked function. Can be chained so that multiple function 53 | * calls produce different results. 54 | */ 55 | mockImplementationOnce( 56 | fn: (...args: TArguments) => TReturn 57 | ): JestMockFn, 58 | /** 59 | * Just a simple sugar function for returning `this` 60 | */ 61 | mockReturnThis(): void, 62 | /** 63 | * Deprecated: use jest.fn(() => value) instead 64 | */ 65 | mockReturnValue(value: TReturn): JestMockFn, 66 | /** 67 | * Sugar for only returning a value once inside your mock 68 | */ 69 | mockReturnValueOnce(value: TReturn): JestMockFn 70 | }; 71 | 72 | type JestAsymmetricEqualityType = { 73 | /** 74 | * A custom Jasmine equality tester 75 | */ 76 | asymmetricMatch(value: mixed): boolean 77 | }; 78 | 79 | type JestCallsType = { 80 | allArgs(): mixed, 81 | all(): mixed, 82 | any(): boolean, 83 | count(): number, 84 | first(): mixed, 85 | mostRecent(): mixed, 86 | reset(): void 87 | }; 88 | 89 | type JestClockType = { 90 | install(): void, 91 | mockDate(date: Date): void, 92 | tick(milliseconds?: number): void, 93 | uninstall(): void 94 | }; 95 | 96 | type JestMatcherResult = { 97 | message?: string | (() => string), 98 | pass: boolean 99 | }; 100 | 101 | type JestMatcher = (actual: any, expected: any) => JestMatcherResult; 102 | 103 | type JestPromiseType = { 104 | /** 105 | * Use rejects to unwrap the reason of a rejected promise so any other 106 | * matcher can be chained. If the promise is fulfilled the assertion fails. 107 | */ 108 | rejects: JestExpectType, 109 | /** 110 | * Use resolves to unwrap the value of a fulfilled promise so any other 111 | * matcher can be chained. If the promise is rejected the assertion fails. 112 | */ 113 | resolves: JestExpectType 114 | }; 115 | 116 | /** 117 | * Plugin: jest-enzyme 118 | */ 119 | type EnzymeMatchersType = { 120 | toBeChecked(): void, 121 | toBeDisabled(): void, 122 | toBeEmpty(): void, 123 | toBePresent(): void, 124 | toContainReact(element: React$Element): void, 125 | toHaveClassName(className: string): void, 126 | toHaveHTML(html: string): void, 127 | toHaveProp(propKey: string, propValue?: any): void, 128 | toHaveRef(refName: string): void, 129 | toHaveState(stateKey: string, stateValue?: any): void, 130 | toHaveStyle(styleKey: string, styleValue?: any): void, 131 | toHaveTagName(tagName: string): void, 132 | toHaveText(text: string): void, 133 | toIncludeText(text: string): void, 134 | toHaveValue(value: any): void, 135 | toMatchElement(element: React$Element): void, 136 | toMatchSelector(selector: string): void 137 | }; 138 | 139 | type JestExpectType = { 140 | not: JestExpectType & EnzymeMatchersType, 141 | /** 142 | * If you have a mock function, you can use .lastCalledWith to test what 143 | * arguments it was last called with. 144 | */ 145 | lastCalledWith(...args: Array): void, 146 | /** 147 | * toBe just checks that a value is what you expect. It uses === to check 148 | * strict equality. 149 | */ 150 | toBe(value: any): void, 151 | /** 152 | * Use .toHaveBeenCalled to ensure that a mock function got called. 153 | */ 154 | toBeCalled(): void, 155 | /** 156 | * Use .toBeCalledWith to ensure that a mock function was called with 157 | * specific arguments. 158 | */ 159 | toBeCalledWith(...args: Array): void, 160 | /** 161 | * Using exact equality with floating point numbers is a bad idea. Rounding 162 | * means that intuitive things fail. 163 | */ 164 | toBeCloseTo(num: number, delta: any): void, 165 | /** 166 | * Use .toBeDefined to check that a variable is not undefined. 167 | */ 168 | toBeDefined(): void, 169 | /** 170 | * Use .toBeFalsy when you don't care what a value is, you just want to 171 | * ensure a value is false in a boolean context. 172 | */ 173 | toBeFalsy(): void, 174 | /** 175 | * To compare floating point numbers, you can use toBeGreaterThan. 176 | */ 177 | toBeGreaterThan(number: number): void, 178 | /** 179 | * To compare floating point numbers, you can use toBeGreaterThanOrEqual. 180 | */ 181 | toBeGreaterThanOrEqual(number: number): void, 182 | /** 183 | * To compare floating point numbers, you can use toBeLessThan. 184 | */ 185 | toBeLessThan(number: number): void, 186 | /** 187 | * To compare floating point numbers, you can use toBeLessThanOrEqual. 188 | */ 189 | toBeLessThanOrEqual(number: number): void, 190 | /** 191 | * Use .toBeInstanceOf(Class) to check that an object is an instance of a 192 | * class. 193 | */ 194 | toBeInstanceOf(cls: Class<*>): void, 195 | /** 196 | * .toBeNull() is the same as .toBe(null) but the error messages are a bit 197 | * nicer. 198 | */ 199 | toBeNull(): void, 200 | /** 201 | * Use .toBeTruthy when you don't care what a value is, you just want to 202 | * ensure a value is true in a boolean context. 203 | */ 204 | toBeTruthy(): void, 205 | /** 206 | * Use .toBeUndefined to check that a variable is undefined. 207 | */ 208 | toBeUndefined(): void, 209 | /** 210 | * Use .toContain when you want to check that an item is in a list. For 211 | * testing the items in the list, this uses ===, a strict equality check. 212 | */ 213 | toContain(item: any): void, 214 | /** 215 | * Use .toContainEqual when you want to check that an item is in a list. For 216 | * testing the items in the list, this matcher recursively checks the 217 | * equality of all fields, rather than checking for object identity. 218 | */ 219 | toContainEqual(item: any): void, 220 | /** 221 | * Use .toEqual when you want to check that two objects have the same value. 222 | * This matcher recursively checks the equality of all fields, rather than 223 | * checking for object identity. 224 | */ 225 | toEqual(value: any): void, 226 | /** 227 | * Use .toHaveBeenCalled to ensure that a mock function got called. 228 | */ 229 | toHaveBeenCalled(): void, 230 | /** 231 | * Use .toHaveBeenCalledTimes to ensure that a mock function got called exact 232 | * number of times. 233 | */ 234 | toHaveBeenCalledTimes(number: number): void, 235 | /** 236 | * Use .toHaveBeenCalledWith to ensure that a mock function was called with 237 | * specific arguments. 238 | */ 239 | toHaveBeenCalledWith(...args: Array): void, 240 | /** 241 | * Use .toHaveBeenLastCalledWith to ensure that a mock function was last called 242 | * with specific arguments. 243 | */ 244 | toHaveBeenLastCalledWith(...args: Array): void, 245 | /** 246 | * Check that an object has a .length property and it is set to a certain 247 | * numeric value. 248 | */ 249 | toHaveLength(number: number): void, 250 | /** 251 | * 252 | */ 253 | toHaveProperty(propPath: string, value?: any): void, 254 | /** 255 | * Use .toMatch to check that a string matches a regular expression or string. 256 | */ 257 | toMatch(regexpOrString: RegExp | string): void, 258 | /** 259 | * Use .toMatchObject to check that a javascript object matches a subset of the properties of an object. 260 | */ 261 | toMatchObject(object: Object | Array): void, 262 | /** 263 | * This ensures that a React component matches the most recent snapshot. 264 | */ 265 | toMatchSnapshot(name?: string): void, 266 | /** 267 | * Use .toThrow to test that a function throws when it is called. 268 | * If you want to test that a specific error gets thrown, you can provide an 269 | * argument to toThrow. The argument can be a string for the error message, 270 | * a class for the error, or a regex that should match the error. 271 | * 272 | * Alias: .toThrowError 273 | */ 274 | toThrow(message?: string | Error | Class | RegExp): void, 275 | toThrowError(message?: string | Error | Class | RegExp): void, 276 | /** 277 | * Use .toThrowErrorMatchingSnapshot to test that a function throws a error 278 | * matching the most recent snapshot when it is called. 279 | */ 280 | toThrowErrorMatchingSnapshot(): void 281 | }; 282 | 283 | type JestObjectType = { 284 | /** 285 | * Disables automatic mocking in the module loader. 286 | * 287 | * After this method is called, all `require()`s will return the real 288 | * versions of each module (rather than a mocked version). 289 | */ 290 | disableAutomock(): JestObjectType, 291 | /** 292 | * An un-hoisted version of disableAutomock 293 | */ 294 | autoMockOff(): JestObjectType, 295 | /** 296 | * Enables automatic mocking in the module loader. 297 | */ 298 | enableAutomock(): JestObjectType, 299 | /** 300 | * An un-hoisted version of enableAutomock 301 | */ 302 | autoMockOn(): JestObjectType, 303 | /** 304 | * Clears the mock.calls and mock.instances properties of all mocks. 305 | * Equivalent to calling .mockClear() on every mocked function. 306 | */ 307 | clearAllMocks(): JestObjectType, 308 | /** 309 | * Resets the state of all mocks. Equivalent to calling .mockReset() on every 310 | * mocked function. 311 | */ 312 | resetAllMocks(): JestObjectType, 313 | /** 314 | * Restores all mocks back to their original value. 315 | */ 316 | restoreAllMocks(): JestObjectType, 317 | /** 318 | * Removes any pending timers from the timer system. 319 | */ 320 | clearAllTimers(): void, 321 | /** 322 | * The same as `mock` but not moved to the top of the expectation by 323 | * babel-jest. 324 | */ 325 | doMock(moduleName: string, moduleFactory?: any): JestObjectType, 326 | /** 327 | * The same as `unmock` but not moved to the top of the expectation by 328 | * babel-jest. 329 | */ 330 | dontMock(moduleName: string): JestObjectType, 331 | /** 332 | * Returns a new, unused mock function. Optionally takes a mock 333 | * implementation. 334 | */ 335 | fn, TReturn>( 336 | implementation?: (...args: TArguments) => TReturn 337 | ): JestMockFn, 338 | /** 339 | * Determines if the given function is a mocked function. 340 | */ 341 | isMockFunction(fn: Function): boolean, 342 | /** 343 | * Given the name of a module, use the automatic mocking system to generate a 344 | * mocked version of the module for you. 345 | */ 346 | genMockFromModule(moduleName: string): any, 347 | /** 348 | * Mocks a module with an auto-mocked version when it is being required. 349 | * 350 | * The second argument can be used to specify an explicit module factory that 351 | * is being run instead of using Jest's automocking feature. 352 | * 353 | * The third argument can be used to create virtual mocks -- mocks of modules 354 | * that don't exist anywhere in the system. 355 | */ 356 | mock( 357 | moduleName: string, 358 | moduleFactory?: any, 359 | options?: Object 360 | ): JestObjectType, 361 | /** 362 | * Returns the actual module instead of a mock, bypassing all checks on 363 | * whether the module should receive a mock implementation or not. 364 | */ 365 | requireActual(moduleName: string): any, 366 | /** 367 | * Returns a mock module instead of the actual module, bypassing all checks 368 | * on whether the module should be required normally or not. 369 | */ 370 | requireMock(moduleName: string): any, 371 | /** 372 | * Resets the module registry - the cache of all required modules. This is 373 | * useful to isolate modules where local state might conflict between tests. 374 | */ 375 | resetModules(): JestObjectType, 376 | /** 377 | * Exhausts the micro-task queue (usually interfaced in node via 378 | * process.nextTick). 379 | */ 380 | runAllTicks(): void, 381 | /** 382 | * Exhausts the macro-task queue (i.e., all tasks queued by setTimeout(), 383 | * setInterval(), and setImmediate()). 384 | */ 385 | runAllTimers(): void, 386 | /** 387 | * Exhausts all tasks queued by setImmediate(). 388 | */ 389 | runAllImmediates(): void, 390 | /** 391 | * Executes only the macro task queue (i.e. all tasks queued by setTimeout() 392 | * or setInterval() and setImmediate()). 393 | */ 394 | runTimersToTime(msToRun: number): void, 395 | /** 396 | * Executes only the macro-tasks that are currently pending (i.e., only the 397 | * tasks that have been queued by setTimeout() or setInterval() up to this 398 | * point) 399 | */ 400 | runOnlyPendingTimers(): void, 401 | /** 402 | * Explicitly supplies the mock object that the module system should return 403 | * for the specified module. Note: It is recommended to use jest.mock() 404 | * instead. 405 | */ 406 | setMock(moduleName: string, moduleExports: any): JestObjectType, 407 | /** 408 | * Indicates that the module system should never return a mocked version of 409 | * the specified module from require() (e.g. that it should always return the 410 | * real module). 411 | */ 412 | unmock(moduleName: string): JestObjectType, 413 | /** 414 | * Instructs Jest to use fake versions of the standard timer functions 415 | * (setTimeout, setInterval, clearTimeout, clearInterval, nextTick, 416 | * setImmediate and clearImmediate). 417 | */ 418 | useFakeTimers(): JestObjectType, 419 | /** 420 | * Instructs Jest to use the real versions of the standard timer functions. 421 | */ 422 | useRealTimers(): JestObjectType, 423 | /** 424 | * Creates a mock function similar to jest.fn but also tracks calls to 425 | * object[methodName]. 426 | */ 427 | spyOn(object: Object, methodName: string): JestMockFn, 428 | /** 429 | * Set the default timeout interval for tests and before/after hooks in milliseconds. 430 | * Note: The default timeout interval is 5 seconds if this method is not called. 431 | */ 432 | setTimeout(timeout: number): JestObjectType 433 | }; 434 | 435 | type JestSpyType = { 436 | calls: JestCallsType 437 | }; 438 | 439 | /** Runs this function after every test inside this context */ 440 | declare function afterEach( 441 | fn: (done: () => void) => ?Promise, 442 | timeout?: number 443 | ): void; 444 | /** Runs this function before every test inside this context */ 445 | declare function beforeEach( 446 | fn: (done: () => void) => ?Promise, 447 | timeout?: number 448 | ): void; 449 | /** Runs this function after all tests have finished inside this context */ 450 | declare function afterAll( 451 | fn: (done: () => void) => ?Promise, 452 | timeout?: number 453 | ): void; 454 | /** Runs this function before any tests have started inside this context */ 455 | declare function beforeAll( 456 | fn: (done: () => void) => ?Promise, 457 | timeout?: number 458 | ): void; 459 | 460 | /** A context for grouping tests together */ 461 | declare var describe: { 462 | /** 463 | * Creates a block that groups together several related tests in one "test suite" 464 | */ 465 | (name: string, fn: () => void): void, 466 | 467 | /** 468 | * Only run this describe block 469 | */ 470 | only(name: string, fn: () => void): void, 471 | 472 | /** 473 | * Skip running this describe block 474 | */ 475 | skip(name: string, fn: () => void): void 476 | }; 477 | 478 | /** An individual test unit */ 479 | declare var it: { 480 | /** 481 | * An individual test unit 482 | * 483 | * @param {string} Name of Test 484 | * @param {Function} Test 485 | * @param {number} Timeout for the test, in milliseconds. 486 | */ 487 | ( 488 | name: string, 489 | fn?: (done: () => void) => ?Promise, 490 | timeout?: number 491 | ): void, 492 | /** 493 | * Only run this test 494 | * 495 | * @param {string} Name of Test 496 | * @param {Function} Test 497 | * @param {number} Timeout for the test, in milliseconds. 498 | */ 499 | only( 500 | name: string, 501 | fn?: (done: () => void) => ?Promise, 502 | timeout?: number 503 | ): void, 504 | /** 505 | * Skip running this test 506 | * 507 | * @param {string} Name of Test 508 | * @param {Function} Test 509 | * @param {number} Timeout for the test, in milliseconds. 510 | */ 511 | skip( 512 | name: string, 513 | fn?: (done: () => void) => ?Promise, 514 | timeout?: number 515 | ): void, 516 | /** 517 | * Run the test concurrently 518 | * 519 | * @param {string} Name of Test 520 | * @param {Function} Test 521 | * @param {number} Timeout for the test, in milliseconds. 522 | */ 523 | concurrent( 524 | name: string, 525 | fn?: (done: () => void) => ?Promise, 526 | timeout?: number 527 | ): void 528 | }; 529 | declare function fit( 530 | name: string, 531 | fn: (done: () => void) => ?Promise, 532 | timeout?: number 533 | ): void; 534 | /** An individual test unit */ 535 | declare var test: typeof it; 536 | /** A disabled group of tests */ 537 | declare var xdescribe: typeof describe; 538 | /** A focused group of tests */ 539 | declare var fdescribe: typeof describe; 540 | /** A disabled individual test */ 541 | declare var xit: typeof it; 542 | /** A disabled individual test */ 543 | declare var xtest: typeof it; 544 | 545 | /** The expect function is used every time you want to test a value */ 546 | declare var expect: { 547 | /** The object that you want to make assertions against */ 548 | (value: any): JestExpectType & JestPromiseType & EnzymeMatchersType, 549 | /** Add additional Jasmine matchers to Jest's roster */ 550 | extend(matchers: { [name: string]: JestMatcher }): void, 551 | /** Add a module that formats application-specific data structures. */ 552 | addSnapshotSerializer(serializer: (input: Object) => string): void, 553 | assertions(expectedAssertions: number): void, 554 | hasAssertions(): void, 555 | any(value: mixed): JestAsymmetricEqualityType, 556 | anything(): void, 557 | arrayContaining(value: Array): void, 558 | objectContaining(value: Object): void, 559 | /** Matches any received string that contains the exact expected string. */ 560 | stringContaining(value: string): void, 561 | stringMatching(value: string | RegExp): void 562 | }; 563 | 564 | // TODO handle return type 565 | // http://jasmine.github.io/2.4/introduction.html#section-Spies 566 | declare function spyOn(value: mixed, method: string): Object; 567 | 568 | /** Holds all functions related to manipulating test runner */ 569 | declare var jest: JestObjectType; 570 | 571 | /** 572 | * The global Jasmine object, this is generally not exposed as the public API, 573 | * using features inside here could break in later versions of Jest. 574 | */ 575 | declare var jasmine: { 576 | DEFAULT_TIMEOUT_INTERVAL: number, 577 | any(value: mixed): JestAsymmetricEqualityType, 578 | anything(): void, 579 | arrayContaining(value: Array): void, 580 | clock(): JestClockType, 581 | createSpy(name: string): JestSpyType, 582 | createSpyObj( 583 | baseName: string, 584 | methodNames: Array 585 | ): { [methodName: string]: JestSpyType }, 586 | objectContaining(value: Object): void, 587 | stringMatching(value: string): void 588 | }; 589 | --------------------------------------------------------------------------------