From 55cc921c5d3485eb60fe94628b227d4069c97b6c Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Tue, 19 Mar 2019 15:12:45 +0000 Subject: [PATCH] Adds react-events package for internal testing (#15150) * Adds react-events package for internal testing --- packages/react-events/README.md | 3 ++ packages/react-events/index.js | 16 +++++++++++ packages/react-events/npm/index.js | 7 +++++ packages/react-events/package.json | 35 ++++++++++++++++++++++++ packages/react-events/src/ReactEvents.js | 25 +++++++++++++++++ packages/shared/ReactSymbols.js | 5 ++++ packages/shared/ReactTypes.js | 2 +- scripts/rollup/bundles.js | 9 ++++++ scripts/rollup/results.json | 28 +++++++++++++++++++ 9 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 packages/react-events/README.md create mode 100644 packages/react-events/index.js create mode 100644 packages/react-events/npm/index.js create mode 100644 packages/react-events/package.json create mode 100644 packages/react-events/src/ReactEvents.js diff --git a/packages/react-events/README.md b/packages/react-events/README.md new file mode 100644 index 0000000000000..14d0eeafa7886 --- /dev/null +++ b/packages/react-events/README.md @@ -0,0 +1,3 @@ +# `react-events` + +This is package is intended for use with the experimental React events API. \ No newline at end of file diff --git a/packages/react-events/index.js b/packages/react-events/index.js new file mode 100644 index 0000000000000..e22e25dabd125 --- /dev/null +++ b/packages/react-events/index.js @@ -0,0 +1,16 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ + +'use strict'; + +const ReactEvents = require('./src/ReactEvents'); + +// TODO: decide on the top-level export form. +// This is hacky but makes it work with both Rollup and Jest. +module.exports = ReactEvents.default || ReactEvents; diff --git a/packages/react-events/npm/index.js b/packages/react-events/npm/index.js new file mode 100644 index 0000000000000..00bc7ad72acc6 --- /dev/null +++ b/packages/react-events/npm/index.js @@ -0,0 +1,7 @@ +'use strict'; + +if (process.env.NODE_ENV === 'production') { + module.exports = require('./cjs/react-events.production.min.js'); +} else { + module.exports = require('./cjs/react-events.development.js'); +} diff --git a/packages/react-events/package.json b/packages/react-events/package.json new file mode 100644 index 0000000000000..b680069e1153d --- /dev/null +++ b/packages/react-events/package.json @@ -0,0 +1,35 @@ +{ + "name": "react-events", + "description": "React is a JavaScript library for building user interfaces.", + "keywords": [ + "react" + ], + "version": "0.1.0", + "homepage": "https://reactjs.org/", + "bugs": "https://github.com/facebook/react/issues", + "license": "MIT", + "files": [ + "LICENSE", + "README.md", + "build-info.json", + "cjs/", + "umd/" + ], + "main": "index.js", + "repository": { + "type": "git", + "url": "https://github.com/facebook/react.git", + "directory": "packages/react" + }, + "engines": { + "node": ">=0.10.0" + }, + "dependencies": { + "loose-envify": "^1.1.0" + }, + "browserify": { + "transform": [ + "loose-envify" + ] + } +} \ No newline at end of file diff --git a/packages/react-events/src/ReactEvents.js b/packages/react-events/src/ReactEvents.js new file mode 100644 index 0000000000000..09ae7abf9f709 --- /dev/null +++ b/packages/react-events/src/ReactEvents.js @@ -0,0 +1,25 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ + +import { + REACT_EVENT_TARGET_TYPE, + REACT_EVENT_TARGET_TOUCH_HIT, +} from 'shared/ReactSymbols'; +import type {ReactEventTarget} from 'shared/ReactTypes'; + +const TouchHitTarget: ReactEventTarget = { + $$typeof: REACT_EVENT_TARGET_TYPE, + type: REACT_EVENT_TARGET_TOUCH_HIT, +}; + +const ReactEvents = { + TouchHitTarget, +}; + +export default ReactEvents; diff --git a/packages/shared/ReactSymbols.js b/packages/shared/ReactSymbols.js index 4bd0518efa3c6..45e8a57e04e43 100644 --- a/packages/shared/ReactSymbols.js +++ b/packages/shared/ReactSymbols.js @@ -53,6 +53,11 @@ export const REACT_EVENT_TARGET_TYPE = hasSymbol ? Symbol.for('react.event_target') : 0xead6; +// React event targets +export const REACT_EVENT_TARGET_TOUCH_HIT = hasSymbol + ? Symbol.for('react.event_target.touch_hit') + : 0xead7; + const MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; const FAUX_ITERATOR_SYMBOL = '@@iterator'; diff --git a/packages/shared/ReactTypes.js b/packages/shared/ReactTypes.js index 57a3a8bf4728c..41d9503ec7545 100644 --- a/packages/shared/ReactTypes.js +++ b/packages/shared/ReactTypes.js @@ -95,5 +95,5 @@ export type ReactEvent = {| export type ReactEventTarget = {| $$typeof: Symbol | number, - type: string, + type: Symbol | number, |}; diff --git a/scripts/rollup/bundles.js b/scripts/rollup/bundles.js index 16bd645e7684b..898c39728f98d 100644 --- a/scripts/rollup/bundles.js +++ b/scripts/rollup/bundles.js @@ -461,6 +461,15 @@ const bundles = [ global: 'SchedulerTracing', externals: [], }, + + /******* React Events (experimental) *******/ + { + bundleTypes: [NODE_DEV, NODE_PROD, FB_WWW_DEV, FB_WWW_PROD], + moduleType: ISOMORPHIC, + entry: 'react-events', + global: 'ReactEvents', + externals: [], + }, ]; // Based on deep-freeze by substack (public domain) diff --git a/scripts/rollup/results.json b/scripts/rollup/results.json index a75771086ee82..1e19f2a2581fa 100644 --- a/scripts/rollup/results.json +++ b/scripts/rollup/results.json @@ -1147,6 +1147,34 @@ "packageName": "scheduler", "size": 12088, "gzip": 2473 + }, + { + "filename": "react-events.development.js", + "bundleType": "NODE_DEV", + "packageName": "react-events", + "size": 1135, + "gzip": 623 + }, + { + "filename": "react-events.production.min.js", + "bundleType": "NODE_PROD", + "packageName": "react-events", + "size": 448, + "gzip": 328 + }, + { + "filename": "ReactEvents-dev.js", + "bundleType": "FB_WWW_DEV", + "packageName": "react-events", + "size": 1106, + "gzip": 613 + }, + { + "filename": "ReactEvents-prod.js", + "bundleType": "FB_WWW_PROD", + "packageName": "react-events", + "size": 643, + "gzip": 377 } ] } \ No newline at end of file