diff --git a/.flowconfig b/.flowconfig index c05e58f597..4c85601032 100644 --- a/.flowconfig +++ b/.flowconfig @@ -36,4 +36,4 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError [version] -^0.37.0 +^0.41.0 diff --git a/.travis.yml b/.travis.yml index 2a56780f56..a1989ffb47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -63,8 +63,6 @@ script: curl \ -F "react=@build/react.js" \ -F "react.min=@build/react.min.js" \ - -F "react-with-addons=@build/react-with-addons.js" \ - -F "react-with-addons.min=@build/react-with-addons.min.js" \ -F "react-dom=@build/react-dom.js" \ -F "react-dom.min=@build/react-dom.min.js" \ -F "react-dom-server=@build/react-dom-server.js" \ diff --git a/Gruntfile.js b/Gruntfile.js index 1782deee77..58c832e29c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -84,10 +84,6 @@ module.exports = function(grunt) { grunt.registerTask('npm-react-native:release', npmReactNativeTasks.buildRelease); grunt.registerTask('npm-react-native:pack', npmReactNativeTasks.packRelease); - var npmReactAddonsTasks = require('./grunt/tasks/npm-react-addons'); - grunt.registerTask('npm-react-addons:release', npmReactAddonsTasks.buildReleases); - grunt.registerTask('npm-react-addons:pack', npmReactAddonsTasks.packReleases); - var npmReactTestRendererTasks = require('./grunt/tasks/npm-react-test'); grunt.registerTask('npm-react-test:release', npmReactTestRendererTasks.buildRelease); grunt.registerTask('npm-react-test:pack', npmReactTestRendererTasks.packRelease); @@ -106,19 +102,11 @@ module.exports = function(grunt) { 'version-check', 'browserify:basic', ]); - grunt.registerTask('build:addons', [ - 'build-modules', - 'browserify:addons', - ]); grunt.registerTask('build:min', [ 'build-modules', 'version-check', 'browserify:min', ]); - grunt.registerTask('build:addons-min', [ - 'build-modules', - 'browserify:addonsMin', - ]); grunt.registerTask('build:dom', [ 'build-modules', 'version-check', @@ -169,9 +157,7 @@ module.exports = function(grunt) { 'build-modules', 'version-check', 'browserify:basic', - 'browserify:addons', 'browserify:min', - 'browserify:addonsMin', 'browserify:dom', 'browserify:domMin', 'browserify:domServer', @@ -184,8 +170,6 @@ module.exports = function(grunt) { 'npm-react-dom:pack', 'npm-react-native:release', 'npm-react-native:pack', - 'npm-react-addons:release', - 'npm-react-addons:pack', 'npm-react-test:release', 'npm-react-test:pack', 'npm-react-noop:release', diff --git a/docs/Rakefile b/docs/Rakefile index 7a9872b7c0..5f5e1e4c7b 100644 --- a/docs/Rakefile +++ b/docs/Rakefile @@ -37,8 +37,6 @@ task :update_hashes do map = { 'react.js' => 'dev', 'react.min.js' => 'prod', - 'react-with-addons.js' => 'addons_dev', - 'react-with-addons.min.js' => 'addons_prod', 'react-dom.js' => 'dom_dev', 'react-dom.min.js' => 'dom_prod', 'react-dom-server.js' => 'dom_server_dev', diff --git a/docs/docs/optimizing-performance.md b/docs/docs/optimizing-performance.md index cbb1b9849b..185fb57873 100644 --- a/docs/docs/optimizing-performance.md +++ b/docs/docs/optimizing-performance.md @@ -248,9 +248,9 @@ If you're using Create React App, both `Object.assign` and the object spread syn Immutability makes tracking changes cheap. A change will always result in a new object so we only need to check if the reference to the object has changed. For example, in this regular JavaScript code: ```javascript -const x = { foo: "bar" }; +const x = { foo: 'bar' }; const y = x; -y.foo = "baz"; +y.foo = 'baz'; x === y; // true ``` @@ -258,7 +258,7 @@ Although `y` was edited, since it's a reference to the same object as `x`, this ```javascript const SomeRecord = Immutable.Record({ foo: null }); -const x = new SomeRecord({ foo: 'bar' }); +const x = new SomeRecord({ foo: 'bar' }); const y = x.set('foo', 'baz'); x === y; // false ``` diff --git a/fixtures/packaging/README.md b/fixtures/packaging/README.md index 4cfaa439ba..af59bcaa16 100644 --- a/fixtures/packaging/README.md +++ b/fixtures/packaging/README.md @@ -6,7 +6,7 @@ If you use React you don't need to worry about it. These fixtures verify that the built React distributions are usable in different environments. **They are not running automatically.** (At least not yet, feel free to contribute to automate them.) -Run them when you make changes to how we package React, ReactDOM, and addons. +Run them when you make changes to how we package React and ReactDOM. ## How to Run @@ -46,5 +46,5 @@ open http://localhost:9000/fixtures/webpack-alias/index.html You should see two things: -* "Hello World" fading in with an animation. +* "Hello World" is rendered. * No errors in the console. diff --git a/fixtures/packaging/browserify/index.html b/fixtures/packaging/browserify/index.html index d2b798e524..e010d6b31d 100644 --- a/fixtures/packaging/browserify/index.html +++ b/fixtures/packaging/browserify/index.html @@ -1,15 +1,5 @@ -
diff --git a/fixtures/packaging/browserify/input.js b/fixtures/packaging/browserify/input.js index da6cc5d0ff..93a0e76d43 100644 --- a/fixtures/packaging/browserify/input.js +++ b/fixtures/packaging/browserify/input.js @@ -1,16 +1,7 @@ var React = require('react'); -var CSSTransitionGroup = require('react-addons-css-transition-group'); var ReactDOM = require('react-dom'); ReactDOM.render( - React.createElement(CSSTransitionGroup, { - transitionName: 'example', - transitionAppear: true, - transitionAppearTimeout: 500, - transitionEnterTimeout: 0, - transitionLeaveTimeout: 0, - }, React.createElement('h1', null, - 'Hello World!' - )), + React.createElement('h1', null, 'Hello World!'), document.getElementById('container') ); diff --git a/fixtures/packaging/brunch/app/initialize.js b/fixtures/packaging/brunch/app/initialize.js index da6cc5d0ff..93a0e76d43 100644 --- a/fixtures/packaging/brunch/app/initialize.js +++ b/fixtures/packaging/brunch/app/initialize.js @@ -1,16 +1,7 @@ var React = require('react'); -var CSSTransitionGroup = require('react-addons-css-transition-group'); var ReactDOM = require('react-dom'); ReactDOM.render( - React.createElement(CSSTransitionGroup, { - transitionName: 'example', - transitionAppear: true, - transitionAppearTimeout: 500, - transitionEnterTimeout: 0, - transitionLeaveTimeout: 0, - }, React.createElement('h1', null, - 'Hello World!' - )), + React.createElement('h1', null, 'Hello World!'), document.getElementById('container') ); diff --git a/fixtures/packaging/brunch/index.html b/fixtures/packaging/brunch/index.html index 859d98d0f2..5902a1a690 100644 --- a/fixtures/packaging/brunch/index.html +++ b/fixtures/packaging/brunch/index.html @@ -1,15 +1,5 @@ -
diff --git a/fixtures/packaging/brunch/input.js b/fixtures/packaging/brunch/input.js index da6cc5d0ff..93a0e76d43 100644 --- a/fixtures/packaging/brunch/input.js +++ b/fixtures/packaging/brunch/input.js @@ -1,16 +1,7 @@ var React = require('react'); -var CSSTransitionGroup = require('react-addons-css-transition-group'); var ReactDOM = require('react-dom'); ReactDOM.render( - React.createElement(CSSTransitionGroup, { - transitionName: 'example', - transitionAppear: true, - transitionAppearTimeout: 500, - transitionEnterTimeout: 0, - transitionLeaveTimeout: 0, - }, React.createElement('h1', null, - 'Hello World!' - )), + React.createElement('h1', null, 'Hello World!'), document.getElementById('container') ); diff --git a/fixtures/packaging/brunch/package.json b/fixtures/packaging/brunch/package.json index 8799e2956e..4713d27c21 100644 --- a/fixtures/packaging/brunch/package.json +++ b/fixtures/packaging/brunch/package.json @@ -5,6 +5,6 @@ "javascript-brunch": "^2.0.0" }, "scripts": { - "build": "rm -rf public && ln -fs ../../../../build/packages/react node_modules/react && ln -fs ../../../../build/packages/react-dom node_modules/react-dom && ln -fs ../../../../build/packages/react-addons-css-transition-group node_modules/react-addons-css-transition-group && brunch build" + "build": "rm -rf public && ln -fs ../../../../build/packages/react node_modules/react && ln -fs ../../../../build/packages/react-dom node_modules/react-dom && brunch build" } } \ No newline at end of file diff --git a/fixtures/packaging/globals.html b/fixtures/packaging/globals.html index 1bc3ef5e4f..3c80fbfe8d 100644 --- a/fixtures/packaging/globals.html +++ b/fixtures/packaging/globals.html @@ -1,30 +1,11 @@ - + -
diff --git a/fixtures/packaging/requirejs.html b/fixtures/packaging/requirejs.html index d181b28f4f..325a2f031a 100644 --- a/fixtures/packaging/requirejs.html +++ b/fixtures/packaging/requirejs.html @@ -1,37 +1,18 @@ -
diff --git a/fixtures/packaging/rjs/input.js b/fixtures/packaging/rjs/input.js index 2b0deee96c..510e71da20 100644 --- a/fixtures/packaging/rjs/input.js +++ b/fixtures/packaging/rjs/input.js @@ -1,15 +1,6 @@ require(['react', 'react-dom'], function(React, ReactDOM) { - var CSSTransitionGroup = React.addons.CSSTransitionGroup; ReactDOM.render( - React.createElement(CSSTransitionGroup, { - transitionName: 'example', - transitionAppear: true, - transitionAppearTimeout: 500, - transitionEnterTimeout: 0, - transitionLeaveTimeout: 0, - }, React.createElement('h1', null, - 'Hello World!' - )), + React.createElement('h1', null, 'Hello World!'), document.getElementById('container') ); }); diff --git a/fixtures/packaging/systemjs-builder/config.js b/fixtures/packaging/systemjs-builder/config.js index 931a037bd9..4a4a2c0c3e 100644 --- a/fixtures/packaging/systemjs-builder/config.js +++ b/fixtures/packaging/systemjs-builder/config.js @@ -1,6 +1,6 @@ System.config({ paths: { - react: '../../../build/react-with-addons.js', + react: '../../../build/react.js', 'react-dom': '../../../build/react-dom.js', }, }); diff --git a/fixtures/packaging/systemjs-builder/index.html b/fixtures/packaging/systemjs-builder/index.html index d2b798e524..e010d6b31d 100644 --- a/fixtures/packaging/systemjs-builder/index.html +++ b/fixtures/packaging/systemjs-builder/index.html @@ -1,15 +1,5 @@ -
diff --git a/fixtures/packaging/systemjs-builder/input.js b/fixtures/packaging/systemjs-builder/input.js index 27d5c10086..e919c6f098 100644 --- a/fixtures/packaging/systemjs-builder/input.js +++ b/fixtures/packaging/systemjs-builder/input.js @@ -1,16 +1,7 @@ import React from 'react'; import ReactDOM from 'react-dom'; -var CSSTransitionGroup = React.addons.CSSTransitionGroup; ReactDOM.render( - React.createElement(CSSTransitionGroup, { - transitionName: 'example', - transitionAppear: true, - transitionAppearTimeout: 500, - transitionEnterTimeout: 0, - transitionLeaveTimeout: 0, - }, React.createElement('h1', null, - 'Hello World!' - )), + React.createElement('h1', null, 'Hello World!'), document.getElementById('container') ); diff --git a/fixtures/packaging/systemjs.html b/fixtures/packaging/systemjs.html index 7cd000c939..2f4125c702 100644 --- a/fixtures/packaging/systemjs.html +++ b/fixtures/packaging/systemjs.html @@ -1,21 +1,11 @@ -
diff --git a/fixtures/packaging/webpack-alias/input.js b/fixtures/packaging/webpack-alias/input.js index f1e2d79e23..93a0e76d43 100644 --- a/fixtures/packaging/webpack-alias/input.js +++ b/fixtures/packaging/webpack-alias/input.js @@ -1,16 +1,7 @@ var React = require('react'); var ReactDOM = require('react-dom'); -var CSSTransitionGroup = React.addons.CSSTransitionGroup; ReactDOM.render( - React.createElement(CSSTransitionGroup, { - transitionName: 'example', - transitionAppear: true, - transitionAppearTimeout: 500, - transitionEnterTimeout: 0, - transitionLeaveTimeout: 0, - }, React.createElement('h1', null, - 'Hello World!' - )), + React.createElement('h1', null, 'Hello World!'), document.getElementById('container') ); diff --git a/fixtures/packaging/webpack/index.html b/fixtures/packaging/webpack/index.html index d2b798e524..e010d6b31d 100644 --- a/fixtures/packaging/webpack/index.html +++ b/fixtures/packaging/webpack/index.html @@ -1,15 +1,5 @@ -
diff --git a/fixtures/packaging/webpack/input.js b/fixtures/packaging/webpack/input.js index da6cc5d0ff..93a0e76d43 100644 --- a/fixtures/packaging/webpack/input.js +++ b/fixtures/packaging/webpack/input.js @@ -1,16 +1,7 @@ var React = require('react'); -var CSSTransitionGroup = require('react-addons-css-transition-group'); var ReactDOM = require('react-dom'); ReactDOM.render( - React.createElement(CSSTransitionGroup, { - transitionName: 'example', - transitionAppear: true, - transitionAppearTimeout: 500, - transitionEnterTimeout: 0, - transitionLeaveTimeout: 0, - }, React.createElement('h1', null, - 'Hello World!' - )), + React.createElement('h1', null, 'Hello World!'), document.getElementById('container') ); diff --git a/grunt/config/browserify.js b/grunt/config/browserify.js index 5cc3f1f840..4cbdef2b25 100644 --- a/grunt/config/browserify.js +++ b/grunt/config/browserify.js @@ -21,12 +21,6 @@ var shimSharedModules = aliasify.configure({ }, }); -var shimDOMModules = aliasify.configure({ - 'aliases': { - './ReactAddonsDOMDependencies': {relative: './ReactAddonsDOMDependenciesUMDShim'}, - }, -}); - var SIMPLE_TEMPLATE = grunt.file.read('./grunt/data/header-template-short.txt'); @@ -172,37 +166,6 @@ var min = { after: [minify, bannerify], }; -var addons = { - entries: [ - './build/node_modules/react/lib/ReactWithAddonsUMDEntry.js', - ], - outfile: './build/react-with-addons.js', - debug: false, - standalone: 'React', - packageName: 'React (with addons)', - transforms: [shimDOMModules], - globalTransforms: [envifyDev], - plugins: [collapser], - after: [derequire, simpleBannerify], -}; - -var addonsMin = { - entries: [ - './build/node_modules/react/lib/ReactWithAddonsUMDEntry.js', - ], - outfile: './build/react-with-addons.min.js', - debug: false, - standalone: 'React', - packageName: 'React (with addons)', - transforms: [shimDOMModules, envifyProd, uglifyify], - globalTransforms: [envifyProd], - plugins: [collapser], - // No need to derequire because the minifier will mangle - // the "require" calls. - - after: [minify, bannerify], -}; - // The DOM Builds var dom = { entries: [ @@ -303,8 +266,6 @@ var domFiberMin = { module.exports = { basic: basic, min: min, - addons: addons, - addonsMin: addonsMin, dom: dom, domMin: domMin, domServer: domServer, diff --git a/grunt/tasks/npm-react-addons.js b/grunt/tasks/npm-react-addons.js deleted file mode 100644 index c0818ff75f..0000000000 --- a/grunt/tasks/npm-react-addons.js +++ /dev/null @@ -1,151 +0,0 @@ -'use strict'; - -var fs = require('fs'); -var grunt = require('grunt'); -var path = require('path'); - -var addons = { - CSSTransitionGroup: { - peerDependency: 'react', - module: 'ReactCSSTransitionGroup', - name: 'css-transition-group', - docs: 'animation', - }, - LinkedStateMixin: { - peerDependency: 'react', - module: 'LinkedStateMixin', - name: 'linked-state-mixin', - docs: 'two-way-binding-helpers', - }, - Perf: { - peerDependency: 'react-dom', - module: 'ReactPerf', - name: 'perf', - docs: 'perf', - }, - PureRenderMixin: { - peerDependency: 'react', - module: 'ReactComponentWithPureRenderMixin', - name: 'pure-render-mixin', - docs: 'pure-render-mixin', - }, - TestUtils: { - peerDependency: 'react-dom', - module: 'ReactTestUtils', - name: 'test-utils', - docs: 'test-utils', - }, - TransitionGroup: { - peerDependency: 'react', - module: 'ReactTransitionGroup', - name: 'transition-group', - docs: 'animation', - }, - createFragment: { - peerDependency: 'react', - module: 'ReactFragment', - method: 'create', - name: 'create-fragment', - docs: 'create-fragment', - }, - shallowCompare: { - peerDependency: 'react', - module: 'shallowCompare', - name: 'shallow-compare', - docs: 'shallow-compare', - }, - updates: { - peerDependency: 'react', - module: 'update', - name: 'update', - docs: 'update', - }, -}; - -function generateSource(info) { - var pieces = [ - 'module.exports = require(\'', - info.peerDependency, - '/lib/', - info.module, - '\')', - ]; - if (info.method) { - pieces.push('.', info.method); - } - pieces.push(';'); - return pieces.join(''); -} - -function buildReleases() { - var pkgTemplate = grunt.file.readJSON('./packages/react-addons/package.json'); - - Object.keys(addons).map(function(k) { - var info = addons[k]; - var pkgName = 'react-addons-' + info.name; - var destDir = 'build/packages/' + pkgName; - var destLicense = path.join(destDir, 'LICENSE'); - var destPatents = path.join(destDir, 'PATENTS'); - - var pkgData = Object.assign({}, pkgTemplate); - pkgData.name = pkgName; - - var version = pkgTemplate.peerDependencies.react; - if (info.peerDependency !== 'react') { - pkgData.peerDependencies = {}; - pkgData.peerDependencies[info.peerDependency] = version; - } - - grunt.file.mkdir(destDir); - var link = info.docs ? info.docs : 'addons'; - link = `https://facebook.github.io/react/docs/${link}.html`; - fs.writeFileSync(path.join(destDir, 'index.js'), generateSource(info)); - fs.writeFileSync(path.join(destDir, 'package.json'), JSON.stringify(pkgData, null, 2)); - grunt.file.copy('LICENSE', destLicense); - grunt.file.copy('PATENTS', destPatents); - fs.writeFileSync( - path.join(destDir, 'README.md'), - ` -# ${pkgName} - -This package provides the React ${k} add-on. - -See <${link}> for more information.`.slice(1) - ); - }); - -} - -function packReleases() { - var done = this.async(); - var count = 0; - - var addonKeys = Object.keys(addons); - - addonKeys.forEach(function(k) { - var info = addons[k]; - var pkgName = 'react-addons-' + info.name; - var pkgDir = 'build/packages/' + pkgName; - - var spawnCmd = { - cmd: 'npm', - args: ['pack', pkgDir], - }; - grunt.util.spawn(spawnCmd, function() { - var buildSrc = pkgName + '-' + grunt.config.data.pkg.version + '.tgz'; - var buildDest = 'build/packages/' + pkgName + '.tgz'; - fs.rename(buildSrc, buildDest, maybeDone); - }); - }); - - function maybeDone() { - if (++count === addonKeys.length) { - done(); - } - } -} - -module.exports = { - buildReleases: buildReleases, - packReleases: packReleases, -}; diff --git a/grunt/tasks/npm-react.js b/grunt/tasks/npm-react.js index 038d2fec51..35c8a520ea 100644 --- a/grunt/tasks/npm-react.js +++ b/grunt/tasks/npm-react.js @@ -11,8 +11,6 @@ var dist = dest + 'dist/'; var distFiles = [ 'react.js', 'react.min.js', - 'react-with-addons.js', - 'react-with-addons.min.js', ]; function buildRelease() { diff --git a/grunt/tasks/release.js b/grunt/tasks/release.js index 0ddab043d8..87186227bb 100644 --- a/grunt/tasks/release.js +++ b/grunt/tasks/release.js @@ -7,8 +7,6 @@ var BOWER_GLOB = [BOWER_PATH + '*.{js}']; var BOWER_FILES = [ 'react.js', 'react.min.js', - 'react-with-addons.js', - 'react-with-addons.min.js', 'react-dom.js', 'react-dom.min.js', 'react-dom-server.js', diff --git a/gulp/tasks/version-check.js b/gulp/tasks/version-check.js index 9e0cb23667..31118527d4 100644 --- a/gulp/tasks/version-check.js +++ b/gulp/tasks/version-check.js @@ -15,7 +15,6 @@ module.exports = function(gulp, plugins) { return function(done) { var reactVersion = require('../../package.json').version; - var addonsData = require('../../packages/react-addons/package.json'); var versions = { 'packages/react/package.json': require('../../packages/react/package.json').version, @@ -23,10 +22,6 @@ module.exports = function(gulp, plugins) { require('../../packages/react-dom/package.json').version, 'packages/react-native-renderer/package.json': require('../../packages/react-native-renderer/package.json').version, - 'packages/react-addons/package.json (version)': addonsData.version, - 'packages/react-addons/package.json (react dependency)': - // Get the "version" without the range bit - addonsData.peerDependencies.react.slice(1), 'packages/react-test-renderer/package.json': require('../../packages/react-test-renderer/package.json').version, 'src/ReactVersion.js': require('../../src/ReactVersion'), diff --git a/gulpfile.js b/gulpfile.js index cea6003e62..f25bc585b5 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -31,11 +31,9 @@ var paths = { react: { src: [ 'src/umd/ReactUMDEntry.js', - 'src/umd/ReactWithAddonsUMDEntry.js', 'src/umd/shims/**/*.js', 'src/isomorphic/**/*.js', - 'src/addons/**/*.js', 'src/ReactVersion.js', 'src/shared/**/*.js', diff --git a/package.json b/package.json index c8f830dfe1..498c5f9412 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "eslint-plugin-react-internal": "file:./eslint-rules", "fbjs": "^0.8.9", "fbjs-scripts": "^0.6.0", - "flow-bin": "^0.37.0", + "flow-bin": "^0.41.0", "glob": "^6.0.4", "glob-stream": "^6.1.0", "grunt": "^0.4.5", diff --git a/packages/jsx_orphaned_brackets_transformer/.gitignore b/packages/jsx_orphaned_brackets_transformer/.gitignore deleted file mode 100644 index 3c3629e647..0000000000 --- a/packages/jsx_orphaned_brackets_transformer/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules diff --git a/packages/jsx_orphaned_brackets_transformer/README.md b/packages/jsx_orphaned_brackets_transformer/README.md deleted file mode 100644 index e0fa3908ed..0000000000 --- a/packages/jsx_orphaned_brackets_transformer/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# JSX Orphaned Brackets Transformer - -React 0.13 no longer parses orphaned > and } as text. - -Take this example block: - -```js -
- > } -
-``` - -In 0.12 and below, this would be transformed to the following: - -```js -React.DOM.div(null, - "> }", -) -``` - -In 0.13, this will instead throw a parser error. - - -## Usage - -The `jsx_orphaned_brackets_transformer` module ships an executable which transforms a file or directory of files. Files will be modified in place, so be sure you are prepared for that. - -```sh -$ npm -g install jsx_orphaned_brackets_transformer -$ jsx_orphaned_brackets_transformer -``` diff --git a/packages/jsx_orphaned_brackets_transformer/package.json b/packages/jsx_orphaned_brackets_transformer/package.json deleted file mode 100644 index 4433172182..0000000000 --- a/packages/jsx_orphaned_brackets_transformer/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "jsx_orphaned_brackets_transformer", - "description": "A utility to update your JSX to work with React 0.13.", - "version": "1.0.1", - "main": "run.js", - "dependencies": { - "graceful-fs": "~2.0.0", - "jstransform": "~8.2.0", - "node-find-files": "0.0.2", - "optimist": "~0.6.0" - }, - "bin": { - "jsx_orphaned_brackets_transformer": "./run.js" - }, - "license": "BSD-3-Clause", - "preferGlobal": true -} diff --git a/packages/jsx_orphaned_brackets_transformer/run.js b/packages/jsx_orphaned_brackets_transformer/run.js deleted file mode 100644 index 7ce8a4a94b..0000000000 --- a/packages/jsx_orphaned_brackets_transformer/run.js +++ /dev/null @@ -1,166 +0,0 @@ -#!/usr/bin/env node - -'use strict'; - -var FileFinder = require('node-find-files'); -var fs = require('graceful-fs'); -var jstransform = require('jstransform'); -var path = require('path'); -var visitReactTag = require('./transforms/react').visitReactTag; -/*eslint-disable no-shadow*/ -var S = jstransform.Syntax; - -var USAGE = - 'Read a file (or directory of files) from disk, transform any orphaned ' + - '} and > characters to avoid parser errors with React 0.13.'; - -function _visitFbt(node, path, state) { - return false; -} -_visitFbt.test = function(node, path, state) { - return node.type === S.XJSElement - && node.openingElement.name.name === 'fbt'; -}; - -var VISITORS_LIST = [ - _visitFbt, - visitReactTag, -]; - -function _transformSource(source) { - return jstransform.transform(VISITORS_LIST, source).code; -} - -function transformDir(dirPath, exclude) { - var finder = new FileFinder({ - rootFolder: dirPath, - filterFunction: function(path, stat) { - return /\.jsx?$/.test(path) && (!exclude || !exclude.test(path)); - }, - }); - - var numTransforms = 0; - var completeTransforms = 0; - var findingComplete = false; - function _printProgress() { - process.stdout.clearLine(); - process.stdout.cursorTo(0); - process.stdout.write( - completeTransforms + '/' + numTransforms + ' transforms complete' - ); - - if (findingComplete && completeTransforms === numTransforms) { - console.log('\ndone!'); - } - } - - finder.on('match', function(pathStr, stat) { - fs.readFile(pathStr, 'utf8', function(err, data) { - if (err) { - err.message = err.message + ' (' + pathStr + ')'; - throw err; - } - - numTransforms++; - _printProgress(); - - var transformedData; - try { - transformedData = _transformSource(data); - } catch (e) { - e.message = e.message + ' (' + pathStr + ')'; - throw e; - } - - if (transformedData !== data) { - fs.writeFile(pathStr, transformedData, function(err) { - if (err) { - err.message = err.message + ' (' + pathStr + ')'; - throw err; - } - completeTransforms++; - _printProgress(); - }); - } else { - completeTransforms++; - _printProgress(); - } - }); - }); - - finder.on('error', function(err) { - console.log('\nError: ', err.stack); - throw err; - }); - - finder.on('complete', function() { - findingComplete = true; - }); - - finder.startSearch(); -} - -function transformFile(pathStr) { - fs.readFile(pathStr, 'utf8', function(err, data) { - if (err) { - err.message = err.message + ' (' + pathStr + ')'; - throw err; - } - - var transformedData; - try { - transformedData = _transformSource(data); - } catch (e) { - e.message = e.message + ' (' + pathStr + ')'; - throw e; - } - - if (transformedData !== data) { - fs.writeFile(pathStr, transformedData, function(err) { - if (err) { - err.message = err.message + ' (' + pathStr + ')'; - throw err; - } - console.log('done!'); - }); - } else { - console.log('done!'); - } - }); -} - -if (require.main === module) { - var argv = require('optimist') - .usage(USAGE) - .argv; - - if (argv._.length === 0) { - throw new Error( - 'Please specify a file or directory path as the first arg!' - ); - } - - argv._.forEach(function(arg) { - var absPath = path.resolve(arg); - - fs.stat(absPath, function(err, stat) { - if (err) { - throw err; - } - - if (stat.isFile()) { - transformFile(absPath); - } else if (stat.isDirectory()) { - var exclude = null; - if (argv.exclude) { - exclude = new RegExp(argv.exclude); - } - transformDir(absPath, exclude); - } else { - throw new Error('Unknown filesystem node type: ' + absPath); - } - }); - }); -} - -exports.transformDir = transformDir; diff --git a/packages/jsx_orphaned_brackets_transformer/transforms/react.js b/packages/jsx_orphaned_brackets_transformer/transforms/react.js deleted file mode 100644 index 1d9a28907a..0000000000 --- a/packages/jsx_orphaned_brackets_transformer/transforms/react.js +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ -/*global exports:true*/ -'use strict'; -var jstransform = require('jstransform'); -var Syntax = jstransform.Syntax; -var utils = require('jstransform/src/utils'); - -function visitReactTag(traverse, object, path, state) { - object.openingElement.attributes.forEach(function(attr, index) { - if (attr.value) { - traverse(attr.value, path, state); - } - }); - - object.children.forEach(function(child, index) { - if (child.type === Syntax.Literal) { - codemodXJSLiteral(child, state); - } else { - traverse(child, path, state); - } - }); - - return false; -} - -visitReactTag.test = function(object, path, state) { - return object.type === Syntax.XJSElement; -}; - -function codemodXJSLiteral(object, state) { - var value = object.raw; - - utils.catchup(object.range[0], state); - - var rightCurlyBracket = '}'; // or {'}'} - var rightAngledBracket = '>'; // or {'>'} - - value = value.replace(/\}/g, rightCurlyBracket); - value = value.replace(/\>/g, rightAngledBracket); - - utils.append(value, state); - utils.move(object.range[1], state); -} - -exports.visitReactTag = visitReactTag; diff --git a/packages/react-addons/package.json b/packages/react-addons/package.json deleted file mode 100644 index 9c32da9881..0000000000 --- a/packages/react-addons/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "react-addons-template", - "version": "16.0.0-alpha.4", - "main": "index.js", - "repository": "facebook/react", - "keywords": [ - "react", - "react-addon" - ], - "license": "BSD-3-Clause", - "dependencies": { - "fbjs": "^0.8.9", - "object-assign": "^4.1.0" - }, - "peerDependencies": { - "react": "^16.0.0-alpha.4" - }, - "files": [ - "LICENSE", - "PATENTS", - "README.md", - "index.js" - ] -} diff --git a/packages/react-linked-input/LinkedInput.js b/packages/react-linked-input/LinkedInput.js deleted file mode 100644 index 394056e039..0000000000 --- a/packages/react-linked-input/LinkedInput.js +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -'use strict'; - -var React = require('react'); -var LinkedValueUtils = require('react-dom/lib/LinkedValueUtils'); - -class LinkedInput extends React.Component { - render() { - var newProps = Object.assign({}, this.props); - newProps.value = LinkedValueUtils.getValue(this.props); - newProps.checked = LinkedValueUtils.getChecked(this.props); - delete newProps.valueLink; - delete newProps.checkedLink; - return React.createElement('input', newProps); - } -} - -module.exports = LinkedInput; - diff --git a/packages/react-linked-input/README.md b/packages/react-linked-input/README.md deleted file mode 100644 index 3109ea7df1..0000000000 --- a/packages/react-linked-input/README.md +++ /dev/null @@ -1,11 +0,0 @@ -This component supports the ReactLink API (valueLink, etc) for input components. Support for ReactLink on DOM elements will be removed from React. This component may be used as a migration plan (so your code doesn't break in the next version of React) or may be used if you just like the ReactLink data binding semantics. However, this component is not maintained, so use at your own risk. - - -``` -var React = require('react'); -var ReactDOM = require('react-dom'); -var LinkedInput = require('react-linked-input'); - -var link = {value: 'boo', requestChange: function() {}}; -React.render(, container); -``` diff --git a/packages/react-linked-input/__test__/LinkedInput-test.js b/packages/react-linked-input/__test__/LinkedInput-test.js deleted file mode 100644 index fab7c3d528..0000000000 --- a/packages/react-linked-input/__test__/LinkedInput-test.js +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @emails react-core - */ - -'use strict'; - - -describe('LinkedStateMixin', function() { - var LinkedInput; - var React; - var ReactDOM; - - beforeEach(function() { - LinkedInput = require('LinkedInput'); - React = require('React'); - ReactDOM = require('ReactDOM'); - }); - - it('should basically work', function() { - var container = document.createElement('div'); - var component = ReactDOM.render(, container); - var input = ReactDOM.findDOMNode(component); - expect(input.value).toBe('foo'); - ReactDOM.render(, container); - expect(input.value).toBe('boo'); - }); - - it('should throw', function() { - var container = document.createElement('div'); - var element = ; - expect(function() { - ReactDOM.render(element, container); - }).toThrow(); - }); -}); diff --git a/packages/react-linked-input/package.json b/packages/react-linked-input/package.json deleted file mode 100644 index 07f65db07c..0000000000 --- a/packages/react-linked-input/package.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "react-linked-input", - "version": "1.0.1", - "description": "LinkedInput supports the ReactLink semantics", - "main": "LinkedInput.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/facebook/react.git" - }, - "keywords": [ - "react", - "linkedinput", - "input", - "linked", - "reactlink" - ], - "author": "", - "license": "BSD-3-Clause", - "peerDependencies": { - "react": "^15.0.1" - } -} diff --git a/scripts/circleci/upload_build.sh b/scripts/circleci/upload_build.sh index 0558ba8dd0..6b57fceac2 100755 --- a/scripts/circleci/upload_build.sh +++ b/scripts/circleci/upload_build.sh @@ -6,8 +6,6 @@ if [ -z $CI_PULL_REQUEST ] && [ -n "$BUILD_SERVER_ENDPOINT" ]; then curl \ -F "react=@build/react.js" \ -F "react.min=@build/react.min.js" \ - -F "react-with-addons=@build/react-with-addons.js" \ - -F "react-with-addons.min=@build/react-with-addons.min.js" \ -F "react-dom=@build/react-dom.js" \ -F "react-dom.min=@build/react-dom.min.js" \ -F "react-dom-server=@build/react-dom-server.js" \ diff --git a/scripts/fiber/tests-failing.txt b/scripts/fiber/tests-failing.txt index 325811e749..4a4444a784 100644 --- a/scripts/fiber/tests-failing.txt +++ b/scripts/fiber/tests-failing.txt @@ -6,6 +6,47 @@ src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js * gives source code refs for unknown prop warning for exact elements (ssr) * gives source code refs for unknown prop warning for exact elements in composition (ssr) +src/renderers/dom/shared/__tests__/ReactDOMServerIntegration-test.js +* renders a blank div with client render on top of good server markup +* renders a div with inline styles with client render on top of good server markup +* renders a self-closing tag with client render on top of good server markup +* renders a self-closing tag as a child with client render on top of good server markup +* renders simple numbers with client render on top of good server markup +* renders simple strings with client render on top of good server markup +* renders string prop with true value with client render on top of good server markup +* renders string prop with false value with client render on top of good server markup +* renders boolean prop with true value with client render on top of good server markup +* renders boolean prop with false value with client render on top of good server markup +* renders boolean prop with self value with client render on top of good server markup +* renders boolean prop with "" value with client render on top of good server markup +* renders boolean prop with string value with client render on top of good server markup +* renders boolean prop with array value with client render on top of good server markup +* renders boolean prop with object value with client render on top of good server markup +* renders boolean prop with non-zero number value with client render on top of good server markup +* renders boolean prop with zero value with client render on top of good server markup +* renders download prop with true value with client render on top of good server markup +* renders download prop with false value with client render on top of good server markup +* renders download prop with string value with client render on top of good server markup +* renders download prop with string "true" value with client render on top of good server markup +* renders className prop with string value with client render on top of good server markup +* renders className prop with empty string value with client render on top of good server markup +* renders className prop with true value with client render on top of good server markup +* renders className prop with false value with client render on top of good server markup +* renders htmlFor with string value with client render on top of good server markup +* renders htmlFor with an empty string with client render on top of good server markup +* renders className prop with true value with client render on top of good server markup +* renders className prop with false value with client render on top of good server markup +* renders no ref attribute with client render on top of good server markup +* renders no children attribute with client render on top of good server markup +* renders no key attribute with client render on top of good server markup +* renders no dangerouslySetInnerHTML attribute with client render on top of good server markup +* renders no unknown attributes with client render on top of good server markup +* renders unknown data- attributes with client render on top of good server markup +* renders no unknown attributes for non-standard elements with client render on top of good server markup +* renders unknown attributes for custom elements with client render on top of good server markup +* renders unknown attributes for custom elements using is with client render on top of good server markup +* renders no HTML events with client render on top of good server markup + src/renderers/dom/shared/__tests__/ReactDOMTextComponent-test.js * can reconcile text merged by Node.normalize() alongside other elements * can reconcile text merged by Node.normalize() diff --git a/scripts/fiber/tests-passing-except-dev.txt b/scripts/fiber/tests-passing-except-dev.txt index ea25216a39..98dda4bba0 100644 --- a/scripts/fiber/tests-passing-except-dev.txt +++ b/scripts/fiber/tests-passing-except-dev.txt @@ -10,6 +10,43 @@ src/renderers/dom/shared/__tests__/ReactDOMServerIntegration-test.js * renders a div with inline styles with client render on top of bad server markup * renders a self-closing tag with client render on top of bad server markup * renders a self-closing tag as a child with client render on top of bad server markup +* renders simple numbers with client render on top of bad server markup +* renders simple strings with client render on top of bad server markup +* renders string prop with true value with client render on top of bad server markup +* renders string prop with false value with client render on top of bad server markup +* renders boolean prop with true value with client render on top of bad server markup +* renders boolean prop with false value with client render on top of bad server markup +* renders boolean prop with self value with client render on top of bad server markup +* renders boolean prop with "" value with client render on top of bad server markup +* renders boolean prop with string value with client render on top of bad server markup +* renders boolean prop with array value with client render on top of bad server markup +* renders boolean prop with object value with client render on top of bad server markup +* renders boolean prop with non-zero number value with client render on top of bad server markup +* renders boolean prop with zero value with client render on top of bad server markup +* renders download prop with true value with client render on top of bad server markup +* renders download prop with false value with client render on top of bad server markup +* renders download prop with string value with client render on top of bad server markup +* renders download prop with string "true" value with client render on top of bad server markup +* renders className prop with string value with client render on top of bad server markup +* renders className prop with empty string value with client render on top of bad server markup +* renders className prop with true value with client render on top of bad server markup +* renders className prop with false value with client render on top of bad server markup +* renders htmlFor with string value with client render on top of bad server markup +* renders htmlFor with an empty string with client render on top of bad server markup +* renders className prop with true value with client render on top of bad server markup +* renders className prop with false value with client render on top of bad server markup +* renders no ref attribute with client render on top of bad server markup +* renders no children attribute with client render on top of bad server markup +* renders no key attribute with client render on top of bad server markup +* renders no dangerouslySetInnerHTML attribute with client render on top of bad server markup +* renders no unknown attributes with server string render +* renders no unknown attributes with client render on top of bad server markup +* renders unknown data- attributes with client render on top of bad server markup +* renders no unknown attributes for non-standard elements with server string render +* renders no unknown attributes for non-standard elements with client render on top of bad server markup +* renders unknown attributes for custom elements with client render on top of bad server markup +* renders unknown attributes for custom elements using is with client render on top of bad server markup +* renders no HTML events with client render on top of bad server markup src/renderers/dom/shared/__tests__/ReactMount-test.js * should warn if mounting into dirty rendered markup diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index e6ffdc28ab..6a88c7cf95 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -42,82 +42,6 @@ scripts/error-codes/__tests__/invertObject-test.js * should take the last value when there're duplications in vals * should preserve the original order -src/addons/__tests__/ReactComponentWithPureRenderMixin-test.js -* provides a default shouldComponentUpdate implementation -* does not do a deep comparison - -src/addons/__tests__/ReactFragment-test.js -* should throw if a plain object is used as a child -* should throw if a plain object even if it is in an owner -* warns for numeric keys on objects as children -* should warn if passing null to createFragment -* should warn if passing an array to createFragment -* should warn if passing a ReactElement to createFragment - -src/addons/__tests__/renderSubtreeIntoContainer-test.js -* should pass context when rendering subtree elsewhere -* should throw if parentComponent is invalid -* should update context if it changes due to setState -* should update context if it changes due to re-render -* should render portal with non-context-provider parent -* should get context through non-context-provider parent -* should get context through middle non-context-provider layer - -src/addons/__tests__/update-test.js -* pushes -* does not mutate the original object -* only pushes an array -* only pushes unto an array -* unshifts -* does not mutate the original object -* only unshifts an array -* only unshifts unto an array -* splices -* does not mutate the original object -* only splices an array of arrays -* only splices unto an array -* merges -* does not mutate the original object -* only merges with an object -* only merges with an object -* sets -* does not mutate the original object -* applies -* does not mutate the original object -* only applies a function -* should support deep updates -* should require a command -* should perform safe hasOwnProperty check - -src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js -* should warn if timeouts aren't specified -* should not warn if timeouts is zero -* should clean-up silently after the timeout elapses -* should keep both sets of DOM nodes around -* should switch transitionLeave from false to true -* should work with no children -* should work with a null child -* should transition from one to null -* should transition from false to one -* should use transition-type specific names when they're provided -* should clear transition timeouts when unmounted -* should handle unmounted elements properly - -src/addons/transitions/__tests__/ReactTransitionChildMapping-test.js -* should support getChildMapping -* should support mergeChildMappings for adding keys -* should support mergeChildMappings for removing keys -* should support mergeChildMappings for adding and removing -* should reconcile overlapping insertions and deletions -* should support mergeChildMappings with undefined input - -src/addons/transitions/__tests__/ReactTransitionGroup-test.js -* should handle willEnter correctly -* should handle enter/leave/enter/leave correctly -* should handle enter/leave/enter correctly -* should handle entering/leaving several elements at once -* should warn for duplicated keys - src/isomorphic/__tests__/React-test.js * should log a deprecation warning once when using React.createMixin @@ -542,6 +466,8 @@ src/renderers/__tests__/ReactComponent-test.js * fires the callback after a component is rendered * throws usefully when rendering badly-typed elements * includes owner name in the error about badly-typed elements +* throws if a plain object is used as a child +* throws if a plain object even if it is in an owner src/renderers/__tests__/ReactComponentLifeCycle-test.js * should not reuse an instance when it has been unmounted @@ -602,6 +528,8 @@ src/renderers/__tests__/ReactCompositeComponent-test.js * should warn when mutated props are passed * should only call componentWillUnmount once * prepares new child before unmounting old +* respects a shallow shouldComponentUpdate implementation +* does not do a deep comparison for a shallow shouldComponentUpdate implementation src/renderers/__tests__/ReactCompositeComponentDOMMinimalism-test.js * should not render extra nodes for non-interpolated text @@ -1064,16 +992,80 @@ src/renderers/dom/shared/__tests__/ReactDOMSVG-test.js src/renderers/dom/shared/__tests__/ReactDOMServerIntegration-test.js * renders a blank div with server string render * renders a blank div with clean client render -* renders a blank div with client render on top of good server markup * renders a div with inline styles with server string render * renders a div with inline styles with clean client render -* renders a div with inline styles with client render on top of good server markup * renders a self-closing tag with server string render * renders a self-closing tag with clean client render -* renders a self-closing tag with client render on top of good server markup * renders a self-closing tag as a child with server string render * renders a self-closing tag as a child with clean client render -* renders a self-closing tag as a child with client render on top of good server markup +* renders simple numbers with server string render +* renders simple numbers with clean client render +* renders simple strings with server string render +* renders simple strings with clean client render +* renders string prop with true value with server string render +* renders string prop with true value with clean client render +* renders string prop with false value with server string render +* renders string prop with false value with clean client render +* renders boolean prop with true value with server string render +* renders boolean prop with true value with clean client render +* renders boolean prop with false value with server string render +* renders boolean prop with false value with clean client render +* renders boolean prop with self value with server string render +* renders boolean prop with self value with clean client render +* renders boolean prop with "" value with server string render +* renders boolean prop with "" value with clean client render +* renders boolean prop with string value with server string render +* renders boolean prop with string value with clean client render +* renders boolean prop with array value with server string render +* renders boolean prop with array value with clean client render +* renders boolean prop with object value with server string render +* renders boolean prop with object value with clean client render +* renders boolean prop with non-zero number value with server string render +* renders boolean prop with non-zero number value with clean client render +* renders boolean prop with zero value with server string render +* renders boolean prop with zero value with clean client render +* renders download prop with true value with server string render +* renders download prop with true value with clean client render +* renders download prop with false value with server string render +* renders download prop with false value with clean client render +* renders download prop with string value with server string render +* renders download prop with string value with clean client render +* renders download prop with string "true" value with server string render +* renders download prop with string "true" value with clean client render +* renders className prop with string value with server string render +* renders className prop with string value with clean client render +* renders className prop with empty string value with server string render +* renders className prop with empty string value with clean client render +* renders className prop with true value with server string render +* renders className prop with true value with clean client render +* renders className prop with false value with server string render +* renders className prop with false value with clean client render +* renders htmlFor with string value with server string render +* renders htmlFor with string value with clean client render +* renders htmlFor with an empty string with server string render +* renders htmlFor with an empty string with clean client render +* renders className prop with true value with server string render +* renders className prop with true value with clean client render +* renders className prop with false value with server string render +* renders className prop with false value with clean client render +* renders no ref attribute with server string render +* renders no ref attribute with clean client render +* renders no children attribute with server string render +* renders no children attribute with clean client render +* renders no key attribute with server string render +* renders no key attribute with clean client render +* renders no dangerouslySetInnerHTML attribute with server string render +* renders no dangerouslySetInnerHTML attribute with clean client render +* renders no unknown attributes with clean client render +* renders unknown data- attributes with server string render +* renders unknown data- attributes with clean client render +* renders no unknown attributes for non-standard elements with clean client render +* renders unknown attributes for custom elements with server string render +* renders unknown attributes for custom elements with clean client render +* renders unknown attributes for custom elements using is with server string render +* renders unknown attributes for custom elements using is with clean client render +* renders no HTML events with server string render +* renders no HTML events with clean client render src/renderers/dom/shared/__tests__/ReactDOMTextComponent-test.js * updates a mounted text component in place @@ -1163,6 +1155,15 @@ src/renderers/dom/shared/__tests__/quoteAttributeValueForBrowser-test.js * should escape number to string * should escape string +src/renderers/dom/shared/__tests__/renderSubtreeIntoContainer-test.js +* should pass context when rendering subtree elsewhere +* should throw if parentComponent is invalid +* should update context if it changes due to setState +* should update context if it changes due to re-render +* should render portal with non-context-provider parent +* should get context through non-context-provider parent +* should get context through middle non-context-provider layer + src/renderers/dom/shared/__tests__/validateDOMNesting-test.js * allows any tag with no context * allows valid nestings @@ -1436,7 +1437,9 @@ src/renderers/native/__tests__/ReactNativeAttributePayload-test.js src/renderers/native/__tests__/ReactNativeEvents-test.js * handles events +* handles events on text nodes * handles when a responder is unmounted while a touch sequence is in progress +* handles events without target src/renderers/native/__tests__/ReactNativeMount-test.js * should be able to create and render a native component diff --git a/scripts/release-manager/commands/utils/npm.js b/scripts/release-manager/commands/utils/npm.js index 5a9bf235fc..65c87d33cc 100644 --- a/scripts/release-manager/commands/utils/npm.js +++ b/scripts/release-manager/commands/utils/npm.js @@ -3,15 +3,6 @@ const querystring = require('querystring'); const PACKAGES = [ - 'react-addons-create-fragment', - 'react-addons-css-transition-group', - 'react-addons-linked-state-mixin', - 'react-addons-perf', - 'react-addons-pure-render-mixin', - 'react-addons-shallow-compare', - 'react-addons-test-utils', - 'react-addons-transition-group', - 'react-addons-update', 'react-dom', 'react-native-renderer', 'react-test-renderer', diff --git a/src/addons/ReactAddonsDOMDependencies.js b/src/addons/ReactAddonsDOMDependencies.js deleted file mode 100644 index db86d1f495..0000000000 --- a/src/addons/ReactAddonsDOMDependencies.js +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @providesModule ReactAddonsDOMDependencies - */ - -'use strict'; - -var ReactDOM = require('react-dom'); - -exports.getReactDOM = function() { - return ReactDOM; -}; - -if (__DEV__) { - var ReactPerf; - var ReactTestUtils; - - exports.getReactPerf = function() { - if (!ReactPerf) { - ReactPerf = require('react-dom/lib/ReactPerf'); - } - return ReactPerf; - }; - - exports.getReactTestUtils = function() { - if (!ReactTestUtils) { - ReactTestUtils = require('react-dom/lib/ReactTestUtils'); - } - return ReactTestUtils; - }; -} diff --git a/src/addons/ReactComponentWithPureRenderMixin.js b/src/addons/ReactComponentWithPureRenderMixin.js deleted file mode 100644 index cf00d7cb3d..0000000000 --- a/src/addons/ReactComponentWithPureRenderMixin.js +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @providesModule ReactComponentWithPureRenderMixin - */ - -'use strict'; - -var shallowCompare = require('shallowCompare'); - -/** - * If your React component's render function is "pure", e.g. it will render the - * same result given the same props and state, provide this mixin for a - * considerable performance boost. - * - * Most React components have pure render functions. - * - * Example: - * - * var ReactComponentWithPureRenderMixin = - * require('ReactComponentWithPureRenderMixin'); - * React.createClass({ - * mixins: [ReactComponentWithPureRenderMixin], - * - * render: function() { - * return
foo
; - * } - * }); - * - * Note: This only checks shallow equality for props and state. If these contain - * complex data structures this mixin may have false-negatives for deeper - * differences. Only mixin to components which have simple props and state, or - * use `forceUpdate()` when you know deep data structures have changed. - * - * See https://facebook.github.io/react/docs/pure-render-mixin.html - */ -var ReactComponentWithPureRenderMixin = { - shouldComponentUpdate: function(nextProps, nextState) { - return shallowCompare(this, nextProps, nextState); - }, -}; - -module.exports = ReactComponentWithPureRenderMixin; diff --git a/src/addons/ReactFragment.js b/src/addons/ReactFragment.js deleted file mode 100644 index 14efe88759..0000000000 --- a/src/addons/ReactFragment.js +++ /dev/null @@ -1,88 +0,0 @@ -/** - * Copyright 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @providesModule ReactFragment - */ - -'use strict'; - -var ReactChildren = require('ReactChildren'); -var ReactElement = require('ReactElement'); - -var emptyFunction = require('fbjs/lib/emptyFunction'); -var invariant = require('fbjs/lib/invariant'); -var warning = require('fbjs/lib/warning'); - -/** - * We used to allow keyed objects to serve as a collection of ReactElements, - * or nested sets. This allowed us a way to explicitly key a set or fragment of - * components. This is now being replaced with an opaque data structure. - * The upgrade path is to call React.addons.createFragment({ key: value }) to - * create a keyed fragment. The resulting data structure is an array. - */ - -var numericPropertyRegex = /^\d+$/; - -var warnedAboutNumeric = false; - -var ReactFragment = { - /** - * Wrap a keyed object in an opaque proxy that warns you if you access any - * of its properties. - * See https://facebook.github.io/react/docs/create-fragment.html - */ - create: function(object) { - if (typeof object !== 'object' || !object || Array.isArray(object)) { - warning( - false, - 'React.addons.createFragment only accepts a single object. Got: %s', - object, - ); - return object; - } - if (ReactElement.isValidElement(object)) { - warning( - false, - 'React.addons.createFragment does not accept a ReactElement ' + - 'without a wrapper object.', - ); - return object; - } - - invariant( - object.nodeType !== 1, - 'React.addons.createFragment(...): Encountered an invalid child; DOM ' + - 'elements are not valid children of React components.', - ); - - var result = []; - - for (var key in object) { - if (__DEV__) { - if (!warnedAboutNumeric && numericPropertyRegex.test(key)) { - warning( - false, - 'React.addons.createFragment(...): Child objects should have ' + - 'non-numeric keys so ordering is preserved.', - ); - warnedAboutNumeric = true; - } - } - ReactChildren.mapIntoWithKeyPrefixInternal( - object[key], - result, - key, - emptyFunction.thatReturnsArgument, - ); - } - - return result; - }, -}; - -module.exports = ReactFragment; diff --git a/src/addons/ReactWithAddons.js b/src/addons/ReactWithAddons.js deleted file mode 100644 index 6a20a3ae36..0000000000 --- a/src/addons/ReactWithAddons.js +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @providesModule ReactWithAddons - */ - -'use strict'; - -var React = require('react'); -var ReactAddonsDOMDependencies = require('ReactAddonsDOMDependencies'); -var ReactComponentWithPureRenderMixin = require('ReactComponentWithPureRenderMixin'); -var ReactCSSTransitionGroup = require('ReactCSSTransitionGroup'); -var ReactFragment = require('ReactFragment'); -var ReactTransitionGroup = require('ReactTransitionGroup'); - -var shallowCompare = require('shallowCompare'); -var update = require('update'); - -React.addons = { - CSSTransitionGroup: ReactCSSTransitionGroup, - PureRenderMixin: ReactComponentWithPureRenderMixin, - TransitionGroup: ReactTransitionGroup, - - createFragment: ReactFragment.create, - shallowCompare: shallowCompare, - update: update, -}; - -if (__DEV__) { - // For the UMD build we get these lazily from the global since they're tied - // to the DOM renderer and it hasn't loaded yet. - Object.defineProperty(React.addons, 'Perf', { - enumerable: true, - get: function() { - return ReactAddonsDOMDependencies.getReactPerf(); - }, - }); - Object.defineProperty(React.addons, 'TestUtils', { - enumerable: true, - get: function() { - return ReactAddonsDOMDependencies.getReactTestUtils(); - }, - }); -} - -module.exports = React; diff --git a/src/addons/__tests__/ReactComponentWithPureRenderMixin-test.js b/src/addons/__tests__/ReactComponentWithPureRenderMixin-test.js deleted file mode 100644 index d9d1683fcb..0000000000 --- a/src/addons/__tests__/ReactComponentWithPureRenderMixin-test.js +++ /dev/null @@ -1,137 +0,0 @@ -/** - * Copyright 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @emails react-core - */ - -'use strict'; - -var React; -var ReactComponentWithPureRenderMixin; -var ReactTestUtils; - -describe('ReactComponentWithPureRenderMixin', () => { - beforeEach(() => { - React = require('react'); - ReactComponentWithPureRenderMixin = require('ReactComponentWithPureRenderMixin'); - ReactTestUtils = require('ReactTestUtils'); - }); - - it('provides a default shouldComponentUpdate implementation', () => { - var renderCalls = 0; - class PlasticWrap extends React.Component { - constructor(props, context) { - super(props, context); - this.state = { - color: 'green', - }; - } - - render() { - return ; - } - } - - var Apple = React.createClass({ - mixins: [ReactComponentWithPureRenderMixin], - - getInitialState: function() { - return { - cut: false, - slices: 1, - }; - }, - - cut: function() { - this.setState({ - cut: true, - slices: 10, - }); - }, - - eatSlice: function() { - this.setState({ - slices: this.state.slices - 1, - }); - }, - - render: function() { - renderCalls++; - return
; - }, - }); - - var instance = ReactTestUtils.renderIntoDocument(); - expect(renderCalls).toBe(1); - - // Do not re-render based on props - instance.setState({color: 'green'}); - expect(renderCalls).toBe(1); - - // Re-render based on props - instance.setState({color: 'red'}); - expect(renderCalls).toBe(2); - - // Re-render base on state - instance.refs.apple.cut(); - expect(renderCalls).toBe(3); - - // No re-render based on state - instance.refs.apple.cut(); - expect(renderCalls).toBe(3); - - // Re-render based on state again - instance.refs.apple.eatSlice(); - expect(renderCalls).toBe(4); - }); - - it('does not do a deep comparison', () => { - function getInitialState() { - return { - foo: [1, 2, 3], - bar: {a: 4, b: 5, c: 6}, - }; - } - - var renderCalls = 0; - var initialSettings = getInitialState(); - - var Component = React.createClass({ - mixins: [ReactComponentWithPureRenderMixin], - - getInitialState: function() { - return initialSettings; - }, - - render: function() { - renderCalls++; - return
; - }, - }); - - var instance = ReactTestUtils.renderIntoDocument(); - expect(renderCalls).toBe(1); - - // Do not re-render if state is equal - var settings = { - foo: initialSettings.foo, - bar: initialSettings.bar, - }; - instance.setState(settings); - expect(renderCalls).toBe(1); - - // Re-render because one field changed - initialSettings.foo = [1, 2, 3]; - instance.setState(initialSettings); - expect(renderCalls).toBe(2); - - // Re-render because the object changed - instance.setState(getInitialState()); - expect(renderCalls).toBe(3); - }); -}); diff --git a/src/addons/__tests__/ReactFragment-test.js b/src/addons/__tests__/ReactFragment-test.js deleted file mode 100644 index a295aaef6a..0000000000 --- a/src/addons/__tests__/ReactFragment-test.js +++ /dev/null @@ -1,99 +0,0 @@ -/** - * Copyright 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @emails react-core - */ - -'use strict'; - -var React; -var ReactDOM; -var ReactFragment; - -describe('ReactFragment', () => { - beforeEach(() => { - React = require('react'); - ReactDOM = require('react-dom'); - ReactFragment = require('ReactFragment'); - }); - - it('should throw if a plain object is used as a child', () => { - var children = { - x: , - y: , - z: , - }; - var element =
{[children]}
; - var container = document.createElement('div'); - expect(() => ReactDOM.render(element, container)).toThrowError( - 'Objects are not valid as a React child (found: object with keys ' + - '{x, y, z}). If you meant to render a collection of children, use an ' + - 'array instead or wrap the object using createFragment(object) from ' + - 'the React add-ons.', - ); - }); - - it('should throw if a plain object even if it is in an owner', () => { - class Foo extends React.Component { - render() { - var children = { - a: , - b: , - c: , - }; - return
{[children]}
; - } - } - var container = document.createElement('div'); - expect(() => ReactDOM.render(, container)).toThrowError( - 'Objects are not valid as a React child (found: object with keys ' + - '{a, b, c}). If you meant to render a collection of children, use an ' + - 'array instead or wrap the object using createFragment(object) from ' + - 'the React add-ons.\n\nCheck the render method of `Foo`.', - ); - }); - - it('warns for numeric keys on objects as children', () => { - spyOn(console, 'error'); - - ReactFragment.create({1: , 2: }); - - expectDev(console.error.calls.count()).toBe(1); - expectDev(console.error.calls.argsFor(0)[0]).toContain( - 'Child objects should have non-numeric keys so ordering is preserved.', - ); - }); - - it('should warn if passing null to createFragment', () => { - spyOn(console, 'error'); - ReactFragment.create(null); - expectDev(console.error.calls.count()).toBe(1); - expectDev(console.error.calls.argsFor(0)[0]).toContain( - 'React.addons.createFragment only accepts a single object.', - ); - }); - - it('should warn if passing an array to createFragment', () => { - spyOn(console, 'error'); - ReactFragment.create([]); - expectDev(console.error.calls.count()).toBe(1); - expectDev(console.error.calls.argsFor(0)[0]).toContain( - 'React.addons.createFragment only accepts a single object.', - ); - }); - - it('should warn if passing a ReactElement to createFragment', () => { - spyOn(console, 'error'); - ReactFragment.create(
); - expectDev(console.error.calls.count()).toBe(1); - expectDev(console.error.calls.argsFor(0)[0]).toContain( - 'React.addons.createFragment does not accept a ReactElement without a ' + - 'wrapper object.', - ); - }); -}); diff --git a/src/addons/__tests__/update-test.js b/src/addons/__tests__/update-test.js deleted file mode 100644 index 15cf7ff75d..0000000000 --- a/src/addons/__tests__/update-test.js +++ /dev/null @@ -1,189 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @emails react-core - */ - -'use strict'; - -var update = require('update'); - -describe('update', () => { - describe('$push', () => { - it('pushes', () => { - expect(update([1], {$push: [7]})).toEqual([1, 7]); - }); - it('does not mutate the original object', () => { - var obj = [1]; - update(obj, {$push: [7]}); - expect(obj).toEqual([1]); - }); - it('only pushes an array', () => { - expect(update.bind(null, [], {$push: 7})).toThrowError( - 'update(): expected spec of $push to be an array; got 7. Did you ' + - 'forget to wrap your parameter in an array?', - ); - }); - it('only pushes unto an array', () => { - expect(update.bind(null, 1, {$push: 7})).toThrowError( - 'update(): expected target of $push to be an array; got 1.', - ); - }); - }); - - describe('$unshift', () => { - it('unshifts', () => { - expect(update([1], {$unshift: [7]})).toEqual([7, 1]); - }); - it('does not mutate the original object', () => { - var obj = [1]; - update(obj, {$unshift: [7]}); - expect(obj).toEqual([1]); - }); - it('only unshifts an array', () => { - expect(update.bind(null, [], {$unshift: 7})).toThrowError( - 'update(): expected spec of $unshift to be an array; got 7. Did you ' + - 'forget to wrap your parameter in an array?', - ); - }); - it('only unshifts unto an array', () => { - expect(update.bind(null, 1, {$unshift: 7})).toThrowError( - 'update(): expected target of $unshift to be an array; got 1.', - ); - }); - }); - - describe('$splice', () => { - it('splices', () => { - expect(update([1, 4, 3], {$splice: [[1, 1, 2]]})).toEqual([1, 2, 3]); - }); - it('does not mutate the original object', () => { - var obj = [1, 4, 3]; - update(obj, {$splice: [[1, 1, 2]]}); - expect(obj).toEqual([1, 4, 3]); - }); - it('only splices an array of arrays', () => { - expect(update.bind(null, [], {$splice: 1})).toThrowError( - 'update(): expected spec of $splice to be an array of arrays; got 1. ' + - 'Did you forget to wrap your parameters in an array?', - ); - expect(update.bind(null, [], {$splice: [1]})).toThrowError( - 'update(): expected spec of $splice to be an array of arrays; got 1. ' + - 'Did you forget to wrap your parameters in an array?', - ); - }); - it('only splices unto an array', () => { - expect(update.bind(null, 1, {$splice: 7})).toThrowError( - 'Expected $splice target to be an array; got 1', - ); - }); - }); - - describe('$merge', () => { - it('merges', () => { - expect(update({a: 'b'}, {$merge: {c: 'd'}})).toEqual({a: 'b', c: 'd'}); - }); - it('does not mutate the original object', () => { - var obj = {a: 'b'}; - update(obj, {$merge: {c: 'd'}}); - expect(obj).toEqual({a: 'b'}); - }); - it('only merges with an object', () => { - expect(update.bind(null, {}, {$merge: 7})).toThrowError( - "update(): $merge expects a spec of type 'object'; got 7", - ); - }); - it('only merges with an object', () => { - expect(update.bind(null, 7, {$merge: {a: 'b'}})).toThrowError( - "update(): $merge expects a target of type 'object'; got 7", - ); - }); - }); - - describe('$set', () => { - it('sets', () => { - expect(update({a: 'b'}, {$set: {c: 'd'}})).toEqual({c: 'd'}); - }); - it('does not mutate the original object', () => { - var obj = {a: 'b'}; - update(obj, {$set: {c: 'd'}}); - expect(obj).toEqual({a: 'b'}); - }); - }); - - describe('$apply', () => { - var applier = function(node) { - return {v: node.v * 2}; - }; - it('applies', () => { - expect(update({v: 2}, {$apply: applier})).toEqual({v: 4}); - }); - it('does not mutate the original object', () => { - var obj = {v: 2}; - update(obj, {$apply: applier}); - expect(obj).toEqual({v: 2}); - }); - it('only applies a function', () => { - expect(update.bind(null, 2, {$apply: 123})).toThrowError( - 'update(): expected spec of $apply to be a function; got 123.', - ); - }); - }); - - it('should support deep updates', () => { - expect( - update( - { - a: 'b', - c: { - d: 'e', - f: [1], - g: [2], - h: [3], - i: {j: 'k'}, - l: 4, - }, - }, - { - c: { - d: {$set: 'm'}, - f: {$push: [5]}, - g: {$unshift: [6]}, - h: {$splice: [[0, 1, 7]]}, - i: {$merge: {n: 'o'}}, - l: {$apply: x => x * 2}, - }, - }, - ), - ).toEqual({ - a: 'b', - c: { - d: 'm', - f: [1, 5], - g: [6, 2], - h: [7], - i: {j: 'k', n: 'o'}, - l: 8, - }, - }); - }); - - it('should require a command', () => { - expect(update.bind(null, {a: 'b'}, {a: 'c'})).toThrowError( - 'update(): You provided a key path to update() that did not contain ' + - 'one of $push, $unshift, $splice, $set, $merge, $apply. Did you ' + - 'forget to include {$set: ...}?', - ); - }); - - it('should perform safe hasOwnProperty check', () => { - expect(update({}, {hasOwnProperty: {$set: 'a'}})).toEqual({ - hasOwnProperty: 'a', - }); - }); -}); diff --git a/src/addons/shallowCompare.js b/src/addons/shallowCompare.js deleted file mode 100644 index 5bb1f500a8..0000000000 --- a/src/addons/shallowCompare.js +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @providesModule shallowCompare - */ - -'use strict'; - -var shallowEqual = require('fbjs/lib/shallowEqual'); - -/** - * Does a shallow comparison for props and state. - * See ReactComponentWithPureRenderMixin - * See also https://facebook.github.io/react/docs/shallow-compare.html - */ -function shallowCompare(instance, nextProps, nextState) { - return !shallowEqual(instance.props, nextProps) || - !shallowEqual(instance.state, nextState); -} - -module.exports = shallowCompare; diff --git a/src/addons/transitions/ReactCSSTransitionGroup.js b/src/addons/transitions/ReactCSSTransitionGroup.js deleted file mode 100644 index 97f1075a0f..0000000000 --- a/src/addons/transitions/ReactCSSTransitionGroup.js +++ /dev/null @@ -1,99 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @providesModule ReactCSSTransitionGroup - */ - -'use strict'; - -var React = require('react'); - -var ReactTransitionGroup = require('ReactTransitionGroup'); -var ReactCSSTransitionGroupChild = require('ReactCSSTransitionGroupChild'); - -function createTransitionTimeoutPropValidator(transitionType) { - var timeoutPropName = 'transition' + transitionType + 'Timeout'; - var enabledPropName = 'transition' + transitionType; - - return function(props) { - // If the transition is enabled - if (props[enabledPropName]) { - // If no timeout duration is provided - if (props[timeoutPropName] == null) { - return new Error( - timeoutPropName + - " wasn't supplied to ReactCSSTransitionGroup: " + - "this can cause unreliable animations and won't be supported in " + - 'a future version of React. See ' + - 'https://fb.me/react-animation-transition-group-timeout for more ' + - 'information.', - ); - - // If the duration isn't a number - } else if (typeof props[timeoutPropName] !== 'number') { - return new Error( - timeoutPropName + ' must be a number (in milliseconds)', - ); - } - } - }; -} - -/** - * An easy way to perform CSS transitions and animations when a React component - * enters or leaves the DOM. - * See https://facebook.github.io/react/docs/animation.html#high-level-api-reactcsstransitiongroup - */ -class ReactCSSTransitionGroup extends React.Component { - static displayName = 'ReactCSSTransitionGroup'; - - static propTypes = { - transitionName: ReactCSSTransitionGroupChild.propTypes.name, - - transitionAppear: React.PropTypes.bool, - transitionEnter: React.PropTypes.bool, - transitionLeave: React.PropTypes.bool, - transitionAppearTimeout: createTransitionTimeoutPropValidator('Appear'), - transitionEnterTimeout: createTransitionTimeoutPropValidator('Enter'), - transitionLeaveTimeout: createTransitionTimeoutPropValidator('Leave'), - }; - - static defaultProps = { - transitionAppear: false, - transitionEnter: true, - transitionLeave: true, - }; - - _wrapChild = child => { - // We need to provide this childFactory so that - // ReactCSSTransitionGroupChild can receive updates to name, enter, and - // leave while it is leaving. - return React.createElement( - ReactCSSTransitionGroupChild, - { - name: this.props.transitionName, - appear: this.props.transitionAppear, - enter: this.props.transitionEnter, - leave: this.props.transitionLeave, - appearTimeout: this.props.transitionAppearTimeout, - enterTimeout: this.props.transitionEnterTimeout, - leaveTimeout: this.props.transitionLeaveTimeout, - }, - child, - ); - }; - - render() { - return React.createElement( - ReactTransitionGroup, - Object.assign({}, this.props, {childFactory: this._wrapChild}), - ); - } -} - -module.exports = ReactCSSTransitionGroup; diff --git a/src/addons/transitions/ReactCSSTransitionGroupChild.js b/src/addons/transitions/ReactCSSTransitionGroupChild.js deleted file mode 100644 index e2a794d0fa..0000000000 --- a/src/addons/transitions/ReactCSSTransitionGroupChild.js +++ /dev/null @@ -1,173 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @providesModule ReactCSSTransitionGroupChild - */ - -'use strict'; - -var React = require('react'); -var ReactAddonsDOMDependencies = require('ReactAddonsDOMDependencies'); - -var CSSCore = require('fbjs/lib/CSSCore'); -var ReactTransitionEvents = require('ReactTransitionEvents'); - -var onlyChild = require('onlyChild'); - -var TICK = 17; - -var ReactCSSTransitionGroupChild = React.createClass({ - displayName: 'ReactCSSTransitionGroupChild', - - propTypes: { - name: React.PropTypes.oneOfType([ - React.PropTypes.string, - React.PropTypes.shape({ - enter: React.PropTypes.string, - leave: React.PropTypes.string, - active: React.PropTypes.string, - }), - React.PropTypes.shape({ - enter: React.PropTypes.string, - enterActive: React.PropTypes.string, - leave: React.PropTypes.string, - leaveActive: React.PropTypes.string, - appear: React.PropTypes.string, - appearActive: React.PropTypes.string, - }), - ]).isRequired, - - // Once we require timeouts to be specified, we can remove the - // boolean flags (appear etc.) and just accept a number - // or a bool for the timeout flags (appearTimeout etc.) - appear: React.PropTypes.bool, - enter: React.PropTypes.bool, - leave: React.PropTypes.bool, - appearTimeout: React.PropTypes.number, - enterTimeout: React.PropTypes.number, - leaveTimeout: React.PropTypes.number, - }, - - transition: function(animationType, finishCallback, userSpecifiedDelay) { - var node = ReactAddonsDOMDependencies.getReactDOM().findDOMNode(this); - - if (!node) { - if (finishCallback) { - finishCallback(); - } - return; - } - - var className = this.props.name[animationType] || - this.props.name + '-' + animationType; - var activeClassName = this.props.name[animationType + 'Active'] || - className + '-active'; - var timeout = null; - - var endListener = function(e) { - if (e && e.target !== node) { - return; - } - - clearTimeout(timeout); - - CSSCore.removeClass(node, className); - CSSCore.removeClass(node, activeClassName); - - ReactTransitionEvents.removeEndEventListener(node, endListener); - - // Usually this optional callback is used for informing an owner of - // a leave animation and telling it to remove the child. - if (finishCallback) { - finishCallback(); - } - }; - - CSSCore.addClass(node, className); - - // Need to do this to actually trigger a transition. - this.queueClassAndNode(activeClassName, node); - - // If the user specified a timeout delay. - if (userSpecifiedDelay) { - // Clean-up the animation after the specified delay - timeout = setTimeout(endListener, userSpecifiedDelay); - this.transitionTimeouts.push(timeout); - } else { - // DEPRECATED: this listener will be removed in a future version of react - ReactTransitionEvents.addEndEventListener(node, endListener); - } - }, - - queueClassAndNode: function(className, node) { - this.classNameAndNodeQueue.push({ - className: className, - node: node, - }); - - if (!this.timeout) { - this.timeout = setTimeout(this.flushClassNameAndNodeQueue, TICK); - } - }, - - flushClassNameAndNodeQueue: function() { - if (this.isMounted()) { - this.classNameAndNodeQueue.forEach(function(obj) { - CSSCore.addClass(obj.node, obj.className); - }); - } - this.classNameAndNodeQueue.length = 0; - this.timeout = null; - }, - - componentWillMount: function() { - this.classNameAndNodeQueue = []; - this.transitionTimeouts = []; - }, - - componentWillUnmount: function() { - if (this.timeout) { - clearTimeout(this.timeout); - } - this.transitionTimeouts.forEach(function(timeout) { - clearTimeout(timeout); - }); - - this.classNameAndNodeQueue.length = 0; - }, - - componentWillAppear: function(done) { - if (this.props.appear) { - this.transition('appear', done, this.props.appearTimeout); - } else { - done(); - } - }, - - componentWillEnter: function(done) { - if (this.props.enter) { - this.transition('enter', done, this.props.enterTimeout); - } else { - done(); - } - }, - - componentWillLeave: function(done) { - if (this.props.leave) { - this.transition('leave', done, this.props.leaveTimeout); - } else { - done(); - } - }, - - render: function() { - return onlyChild(this.props.children); - }, -}); - -module.exports = ReactCSSTransitionGroupChild; diff --git a/src/addons/transitions/ReactTransitionChildMapping.js b/src/addons/transitions/ReactTransitionChildMapping.js deleted file mode 100644 index 4ba6795dfc..0000000000 --- a/src/addons/transitions/ReactTransitionChildMapping.js +++ /dev/null @@ -1,105 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @providesModule ReactTransitionChildMapping - */ - -'use strict'; - -var flattenChildren = require('flattenChildren'); - -var ReactTransitionChildMapping = { - /** - * Given `this.props.children`, return an object mapping key to child. Just - * simple syntactic sugar around flattenChildren(). - * - * @param {*} children `this.props.children` - * @param {number=} selfDebugID Optional debugID of the current internal instance. - * @return {object} Mapping of key to child - */ - getChildMapping: function(children, selfDebugID) { - if (!children) { - return children; - } - - if (__DEV__) { - return flattenChildren(children, selfDebugID); - } - - return flattenChildren(children); - }, - - /** - * When you're adding or removing children some may be added or removed in the - * same render pass. We want to show *both* since we want to simultaneously - * animate elements in and out. This function takes a previous set of keys - * and a new set of keys and merges them with its best guess of the correct - * ordering. In the future we may expose some of the utilities in - * ReactMultiChild to make this easy, but for now React itself does not - * directly have this concept of the union of prevChildren and nextChildren - * so we implement it here. - * - * @param {object} prev prev children as returned from - * `ReactTransitionChildMapping.getChildMapping()`. - * @param {object} next next children as returned from - * `ReactTransitionChildMapping.getChildMapping()`. - * @return {object} a key set that contains all keys in `prev` and all keys - * in `next` in a reasonable order. - */ - mergeChildMappings: function(prev, next) { - prev = prev || {}; - next = next || {}; - - function getValueForKey(key) { - if (next.hasOwnProperty(key)) { - return next[key]; - } else { - return prev[key]; - } - } - - // For each key of `next`, the list of keys to insert before that key in - // the combined list - var nextKeysPending = {}; - - var pendingKeys = []; - for (var prevKey in prev) { - if (next.hasOwnProperty(prevKey)) { - if (pendingKeys.length) { - nextKeysPending[prevKey] = pendingKeys; - pendingKeys = []; - } - } else { - pendingKeys.push(prevKey); - } - } - - var i; - var childMapping = {}; - for (var nextKey in next) { - if (nextKeysPending.hasOwnProperty(nextKey)) { - for (i = 0; i < nextKeysPending[nextKey].length; i++) { - var pendingNextKey = nextKeysPending[nextKey][i]; - childMapping[nextKeysPending[nextKey][i]] = getValueForKey( - pendingNextKey, - ); - } - } - childMapping[nextKey] = getValueForKey(nextKey); - } - - // Finally, add the keys which didn't appear before any key in `next` - for (i = 0; i < pendingKeys.length; i++) { - childMapping[pendingKeys[i]] = getValueForKey(pendingKeys[i]); - } - - return childMapping; - }, -}; - -module.exports = ReactTransitionChildMapping; diff --git a/src/addons/transitions/ReactTransitionEvents.js b/src/addons/transitions/ReactTransitionEvents.js deleted file mode 100644 index 82d8b46480..0000000000 --- a/src/addons/transitions/ReactTransitionEvents.js +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @providesModule ReactTransitionEvents - */ - -'use strict'; - -var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment'); - -var getVendorPrefixedEventName = require('react-dom/lib/getVendorPrefixedEventName'); - -var endEvents = []; - -function detectEvents() { - var animEnd = getVendorPrefixedEventName('animationend'); - var transEnd = getVendorPrefixedEventName('transitionend'); - - if (animEnd) { - endEvents.push(animEnd); - } - - if (transEnd) { - endEvents.push(transEnd); - } -} - -if (ExecutionEnvironment.canUseDOM) { - detectEvents(); -} - -// We use the raw {add|remove}EventListener() call because EventListener -// does not know how to remove event listeners and we really should -// clean up. Also, these events are not triggered in older browsers -// so we should be A-OK here. - -function addEventListener(node, eventName, eventListener) { - node.addEventListener(eventName, eventListener, false); -} - -function removeEventListener(node, eventName, eventListener) { - node.removeEventListener(eventName, eventListener, false); -} - -var ReactTransitionEvents = { - addEndEventListener: function(node, eventListener) { - if (endEvents.length === 0) { - // If CSS transitions are not supported, trigger an "end animation" - // event immediately. - window.setTimeout(eventListener, 0); - return; - } - endEvents.forEach(function(endEvent) { - addEventListener(node, endEvent, eventListener); - }); - }, - - removeEndEventListener: function(node, eventListener) { - if (endEvents.length === 0) { - return; - } - endEvents.forEach(function(endEvent) { - removeEventListener(node, endEvent, eventListener); - }); - }, -}; - -module.exports = ReactTransitionEvents; diff --git a/src/addons/transitions/ReactTransitionGroup.js b/src/addons/transitions/ReactTransitionGroup.js deleted file mode 100644 index 0b25c5feb0..0000000000 --- a/src/addons/transitions/ReactTransitionGroup.js +++ /dev/null @@ -1,243 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @providesModule ReactTransitionGroup - */ - -'use strict'; - -var React = require('react'); -var ReactTransitionChildMapping = require('ReactTransitionChildMapping'); - -var emptyFunction = require('fbjs/lib/emptyFunction'); - -/** - * A basis for animations. When children are declaratively added or removed, - * special lifecycle hooks are called. - * See https://facebook.github.io/react/docs/animation.html#low-level-api-reacttransitiongroup - */ -class ReactTransitionGroup extends React.Component { - static displayName = 'ReactTransitionGroup'; - - static propTypes = { - component: React.PropTypes.any, - childFactory: React.PropTypes.func, - }; - - static defaultProps = { - component: 'span', - childFactory: emptyFunction.thatReturnsArgument, - }; - - state = { - // TODO: can we get useful debug information to show at this point? - children: ReactTransitionChildMapping.getChildMapping(this.props.children), - }; - - componentWillMount() { - this.currentlyTransitioningKeys = {}; - this.keysToEnter = []; - this.keysToLeave = []; - } - - componentDidMount() { - var initialChildMapping = this.state.children; - for (var key in initialChildMapping) { - if (initialChildMapping[key]) { - this.performAppear(key); - } - } - } - - componentWillReceiveProps(nextProps) { - var nextChildMapping = ReactTransitionChildMapping.getChildMapping( - nextProps.children, - ); - var prevChildMapping = this.state.children; - - this.setState({ - children: ReactTransitionChildMapping.mergeChildMappings( - prevChildMapping, - nextChildMapping, - ), - }); - - var key; - - for (key in nextChildMapping) { - var hasPrev = prevChildMapping && prevChildMapping.hasOwnProperty(key); - if ( - nextChildMapping[key] && - !hasPrev && - !this.currentlyTransitioningKeys[key] - ) { - this.keysToEnter.push(key); - } - } - - for (key in prevChildMapping) { - var hasNext = nextChildMapping && nextChildMapping.hasOwnProperty(key); - if ( - prevChildMapping[key] && - !hasNext && - !this.currentlyTransitioningKeys[key] - ) { - this.keysToLeave.push(key); - } - } - - // If we want to someday check for reordering, we could do it here. - } - - componentDidUpdate() { - var keysToEnter = this.keysToEnter; - this.keysToEnter = []; - keysToEnter.forEach(this.performEnter); - - var keysToLeave = this.keysToLeave; - this.keysToLeave = []; - keysToLeave.forEach(this.performLeave); - } - - performAppear = key => { - this.currentlyTransitioningKeys[key] = true; - - var component = this.refs[key]; - - if (component.componentWillAppear) { - component.componentWillAppear(this._handleDoneAppearing.bind(this, key)); - } else { - this._handleDoneAppearing(key); - } - }; - - _handleDoneAppearing = key => { - var component = this.refs[key]; - if (component.componentDidAppear) { - component.componentDidAppear(); - } - - delete this.currentlyTransitioningKeys[key]; - - var currentChildMapping = ReactTransitionChildMapping.getChildMapping( - this.props.children, - ); - - if (!currentChildMapping || !currentChildMapping.hasOwnProperty(key)) { - // This was removed before it had fully appeared. Remove it. - this.performLeave(key); - } - }; - - performEnter = key => { - this.currentlyTransitioningKeys[key] = true; - - var component = this.refs[key]; - - if (component.componentWillEnter) { - component.componentWillEnter(this._handleDoneEntering.bind(this, key)); - } else { - this._handleDoneEntering(key); - } - }; - - _handleDoneEntering = key => { - var component = this.refs[key]; - if (component.componentDidEnter) { - component.componentDidEnter(); - } - - delete this.currentlyTransitioningKeys[key]; - - var currentChildMapping = ReactTransitionChildMapping.getChildMapping( - this.props.children, - ); - - if (!currentChildMapping || !currentChildMapping.hasOwnProperty(key)) { - // This was removed before it had fully entered. Remove it. - this.performLeave(key); - } - }; - - performLeave = key => { - this.currentlyTransitioningKeys[key] = true; - - var component = this.refs[key]; - if (component.componentWillLeave) { - component.componentWillLeave(this._handleDoneLeaving.bind(this, key)); - } else { - // Note that this is somewhat dangerous b/c it calls setState() - // again, effectively mutating the component before all the work - // is done. - this._handleDoneLeaving(key); - } - }; - - _handleDoneLeaving = key => { - var component = this.refs[key]; - - if (component.componentDidLeave) { - component.componentDidLeave(); - } - - delete this.currentlyTransitioningKeys[key]; - - var currentChildMapping = ReactTransitionChildMapping.getChildMapping( - this.props.children, - ); - - if (currentChildMapping && currentChildMapping.hasOwnProperty(key)) { - // This entered again before it fully left. Add it again. - this.performEnter(key); - } else { - this.setState(function(state) { - var newChildren = Object.assign({}, state.children); - delete newChildren[key]; - return {children: newChildren}; - }); - } - }; - - render() { - // TODO: we could get rid of the need for the wrapper node - // by cloning a single child - var childrenToRender = []; - for (var key in this.state.children) { - var child = this.state.children[key]; - if (child) { - // You may need to apply reactive updates to a child as it is leaving. - // The normal React way to do it won't work since the child will have - // already been removed. In case you need this behavior you can provide - // a childFactory function to wrap every child, even the ones that are - // leaving. - childrenToRender.push( - React.cloneElement(this.props.childFactory(child), { - ref: key, - key: key, - }), - ); - } - } - - // Do not forward ReactTransitionGroup props to primitive DOM nodes - var props = Object.assign({}, this.props); - delete props.transitionLeave; - delete props.transitionName; - delete props.transitionAppear; - delete props.transitionEnter; - delete props.childFactory; - delete props.transitionLeaveTimeout; - delete props.transitionEnterTimeout; - delete props.transitionAppearTimeout; - delete props.component; - - return React.createElement(this.props.component, props, childrenToRender); - } -} - -module.exports = ReactTransitionGroup; diff --git a/src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js b/src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js deleted file mode 100644 index aaecb6e485..0000000000 --- a/src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js +++ /dev/null @@ -1,325 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @emails react-core - */ - -'use strict'; - -var CSSCore = require('fbjs/lib/CSSCore'); - -var React; -var ReactDOM; -var ReactCSSTransitionGroup; - -// Most of the real functionality is covered in other unit tests, this just -// makes sure we're wired up correctly. -describe('ReactCSSTransitionGroup', () => { - var container; - - beforeEach(() => { - jest.resetModules(); - React = require('react'); - ReactDOM = require('react-dom'); - ReactCSSTransitionGroup = require('ReactCSSTransitionGroup'); - - container = document.createElement('div'); - spyOn(console, 'error'); - }); - - it("should warn if timeouts aren't specified", () => { - ReactDOM.render( - - - , - container, - ); - - // Warning about the missing transitionLeaveTimeout prop - expectDev(console.error.calls.count()).toBe(1); - }); - - it('should not warn if timeouts is zero', () => { - ReactDOM.render( - - - , - container, - ); - - expectDev(console.error.calls.count()).toBe(0); - }); - - it('should clean-up silently after the timeout elapses', () => { - var a = ReactDOM.render( - - - , - container, - ); - expect(ReactDOM.findDOMNode(a).childNodes.length).toBe(1); - - setTimeout.mock.calls.length = 0; - - ReactDOM.render( - - - , - container, - ); - expect(ReactDOM.findDOMNode(a).childNodes.length).toBe(2); - expect(ReactDOM.findDOMNode(a).childNodes[0].id).toBe('two'); - expect(ReactDOM.findDOMNode(a).childNodes[1].id).toBe('one'); - - // For some reason jst is adding extra setTimeout()s and grunt test isn't, - // so we need to do this disgusting hack. - for (var i = 0; i < setTimeout.mock.calls.length; i++) { - if (setTimeout.mock.calls[i][1] === 200) { - setTimeout.mock.calls[i][0](); - break; - } - } - - // No warnings - expectDev(console.error.calls.count()).toBe(0); - - // The leaving child has been removed - expect(ReactDOM.findDOMNode(a).childNodes.length).toBe(1); - expect(ReactDOM.findDOMNode(a).childNodes[0].id).toBe('two'); - }); - - it('should keep both sets of DOM nodes around', () => { - var a = ReactDOM.render( - - - , - container, - ); - expect(ReactDOM.findDOMNode(a).childNodes.length).toBe(1); - ReactDOM.render( - - - , - container, - ); - expect(ReactDOM.findDOMNode(a).childNodes.length).toBe(2); - expect(ReactDOM.findDOMNode(a).childNodes[0].id).toBe('two'); - expect(ReactDOM.findDOMNode(a).childNodes[1].id).toBe('one'); - }); - - it('should switch transitionLeave from false to true', () => { - var a = ReactDOM.render( - - - , - container, - ); - expect(ReactDOM.findDOMNode(a).childNodes.length).toBe(1); - ReactDOM.render( - - - , - container, - ); - expect(ReactDOM.findDOMNode(a).childNodes.length).toBe(1); - ReactDOM.render( - - - , - container, - ); - expect(ReactDOM.findDOMNode(a).childNodes.length).toBe(2); - expect(ReactDOM.findDOMNode(a).childNodes[0].id).toBe('three'); - expect(ReactDOM.findDOMNode(a).childNodes[1].id).toBe('two'); - }); - - it('should work with no children', () => { - ReactDOM.render( - , - container, - ); - }); - - it('should work with a null child', () => { - ReactDOM.render( - - {[null]} - , - container, - ); - }); - - it('should transition from one to null', () => { - var a = ReactDOM.render( - - - , - container, - ); - expect(ReactDOM.findDOMNode(a).childNodes.length).toBe(1); - ReactDOM.render( - - {null} - , - container, - ); - // (Here, we expect the original child to stick around but test that no - // exception is thrown) - expect(ReactDOM.findDOMNode(a).childNodes.length).toBe(1); - expect(ReactDOM.findDOMNode(a).childNodes[0].id).toBe('one'); - }); - - it('should transition from false to one', () => { - var a = ReactDOM.render( - - {false} - , - container, - ); - expect(ReactDOM.findDOMNode(a).childNodes.length).toBe(0); - ReactDOM.render( - - - , - container, - ); - expect(ReactDOM.findDOMNode(a).childNodes.length).toBe(1); - expect(ReactDOM.findDOMNode(a).childNodes[0].id).toBe('one'); - }); - - it("should use transition-type specific names when they're provided", () => { - var customTransitionNames = { - enter: 'custom-entering', - leave: 'custom-leaving', - }; - - var a = ReactDOM.render( - - - , - container, - ); - expect(ReactDOM.findDOMNode(a).childNodes.length).toBe(1); - - // Add an element - ReactDOM.render( - - - - , - container, - ); - expect(ReactDOM.findDOMNode(a).childNodes.length).toBe(2); - - var enteringNode = ReactDOM.findDOMNode(a).childNodes[1]; - expect(CSSCore.hasClass(enteringNode, 'custom-entering')).toBe(true); - - // Remove an element - ReactDOM.render( - - - , - container, - ); - expect(ReactDOM.findDOMNode(a).childNodes.length).toBe(2); - - var leavingNode = ReactDOM.findDOMNode(a).childNodes[0]; - expect(CSSCore.hasClass(leavingNode, 'custom-leaving')).toBe(true); - }); - - it('should clear transition timeouts when unmounted', () => { - class Component extends React.Component { - render() { - return ( - - {this.props.children} - - ); - } - } - - ReactDOM.render(, container); - ReactDOM.render( - , - container, - ); - - ReactDOM.unmountComponentAtNode(container); - - // Testing that no exception is thrown here, as the timeout has been cleared. - jest.runAllTimers(); - }); - - it('should handle unmounted elements properly', () => { - class Child extends React.Component { - render() { - if (!this.props.show) { - return null; - } - return
; - } - } - - class Component extends React.Component { - state = {showChild: true}; - - componentDidMount() { - this.setState({showChild: false}); - } - - render() { - return ( - - - - ); - } - } - - ReactDOM.render(, container); - - // Testing that no exception is thrown here, as the timeout has been cleared. - jest.runAllTimers(); - }); -}); diff --git a/src/addons/transitions/__tests__/ReactTransitionChildMapping-test.js b/src/addons/transitions/__tests__/ReactTransitionChildMapping-test.js deleted file mode 100644 index a383d11f51..0000000000 --- a/src/addons/transitions/__tests__/ReactTransitionChildMapping-test.js +++ /dev/null @@ -1,137 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @emails react-core - */ - -'use strict'; - -var React; -var ReactTransitionChildMapping; - -describe('ReactTransitionChildMapping', () => { - beforeEach(() => { - React = require('react'); - ReactTransitionChildMapping = require('ReactTransitionChildMapping'); - }); - - it('should support getChildMapping', () => { - var oneone =
; - var onetwo =
; - var one =
{oneone}{onetwo}
; - var two =
; - var component =
{one}{two}
; - expect( - ReactTransitionChildMapping.getChildMapping(component.props.children), - ).toEqual({ - '.$one': one, - '.$two': two, - }); - }); - - it('should support mergeChildMappings for adding keys', () => { - var prev = { - one: true, - two: true, - }; - var next = { - one: true, - two: true, - three: true, - }; - expect(ReactTransitionChildMapping.mergeChildMappings(prev, next)).toEqual({ - one: true, - two: true, - three: true, - }); - }); - - it('should support mergeChildMappings for removing keys', () => { - var prev = { - one: true, - two: true, - three: true, - }; - var next = { - one: true, - two: true, - }; - expect(ReactTransitionChildMapping.mergeChildMappings(prev, next)).toEqual({ - one: true, - two: true, - three: true, - }); - }); - - it('should support mergeChildMappings for adding and removing', () => { - var prev = { - one: true, - two: true, - three: true, - }; - var next = { - one: true, - two: true, - four: true, - }; - expect(ReactTransitionChildMapping.mergeChildMappings(prev, next)).toEqual({ - one: true, - two: true, - three: true, - four: true, - }); - }); - - it('should reconcile overlapping insertions and deletions', () => { - var prev = { - one: true, - two: true, - four: true, - five: true, - }; - var next = { - one: true, - two: true, - three: true, - five: true, - }; - expect(ReactTransitionChildMapping.mergeChildMappings(prev, next)).toEqual({ - one: true, - two: true, - three: true, - four: true, - five: true, - }); - }); - - it('should support mergeChildMappings with undefined input', () => { - var prev = { - one: true, - two: true, - }; - - var next = undefined; - - expect(ReactTransitionChildMapping.mergeChildMappings(prev, next)).toEqual({ - one: true, - two: true, - }); - - prev = undefined; - - next = { - three: true, - four: true, - }; - - expect(ReactTransitionChildMapping.mergeChildMappings(prev, next)).toEqual({ - three: true, - four: true, - }); - }); -}); diff --git a/src/addons/transitions/__tests__/ReactTransitionGroup-test.js b/src/addons/transitions/__tests__/ReactTransitionGroup-test.js deleted file mode 100644 index b9cce0db97..0000000000 --- a/src/addons/transitions/__tests__/ReactTransitionGroup-test.js +++ /dev/null @@ -1,334 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @emails react-core - */ - -'use strict'; - -var React; -var ReactDOM; -var ReactTransitionGroup; - -// Most of the real functionality is covered in other unit tests, this just -// makes sure we're wired up correctly. -describe('ReactTransitionGroup', () => { - var container; - - beforeEach(() => { - React = require('react'); - ReactDOM = require('react-dom'); - ReactTransitionGroup = require('ReactTransitionGroup'); - - container = document.createElement('div'); - }); - - it('should handle willEnter correctly', () => { - var log = []; - - class Child extends React.Component { - componentDidMount() { - log.push('didMount'); - } - - componentWillAppear = cb => { - log.push('willAppear'); - cb(); - }; - - componentDidAppear = () => { - log.push('didAppear'); - }; - - componentWillEnter = cb => { - log.push('willEnter'); - cb(); - }; - - componentDidEnter = () => { - log.push('didEnter'); - }; - - componentWillLeave = cb => { - log.push('willLeave'); - cb(); - }; - - componentDidLeave = () => { - log.push('didLeave'); - }; - - componentWillUnmount() { - log.push('willUnmount'); - } - - render() { - return ; - } - } - - class Component extends React.Component { - state = {count: 1}; - - render() { - var children = []; - for (var i = 0; i < this.state.count; i++) { - children.push(); - } - return {children}; - } - } - - var instance = ReactDOM.render(, container); - expect(log).toEqual(['didMount', 'willAppear', 'didAppear']); - - log = []; - instance.setState({count: 2}, function() { - expect(log).toEqual(['didMount', 'willEnter', 'didEnter']); - - log = []; - instance.setState({count: 1}); - }); - - expect(log).toEqual(['willLeave', 'didLeave', 'willUnmount']); - }); - - it('should handle enter/leave/enter/leave correctly', () => { - var log = []; - var willEnterCb; - - class Child extends React.Component { - componentDidMount() { - log.push('didMount'); - } - - componentWillEnter = cb => { - log.push('willEnter'); - willEnterCb = cb; - }; - - componentDidEnter = () => { - log.push('didEnter'); - }; - - componentWillLeave = cb => { - log.push('willLeave'); - cb(); - }; - - componentDidLeave = () => { - log.push('didLeave'); - }; - - componentWillUnmount() { - log.push('willUnmount'); - } - - render() { - return ; - } - } - - class Component extends React.Component { - state = {count: 1}; - - render() { - var children = []; - for (var i = 0; i < this.state.count; i++) { - children.push(); - } - return {children}; - } - } - - var instance = ReactDOM.render(, container); - expect(log).toEqual(['didMount']); - instance.setState({count: 2}); - expect(log).toEqual(['didMount', 'didMount', 'willEnter']); - for (var k = 0; k < 5; k++) { - instance.setState({count: 2}); - expect(log).toEqual(['didMount', 'didMount', 'willEnter']); - instance.setState({count: 1}); - } - // other animations are blocked until willEnterCb is called - willEnterCb(); - expect(log).toEqual([ - 'didMount', - 'didMount', - 'willEnter', - 'didEnter', - 'willLeave', - 'didLeave', - 'willUnmount', - ]); - }); - - it('should handle enter/leave/enter correctly', () => { - var log = []; - var willEnterCb; - - class Child extends React.Component { - componentDidMount() { - log.push('didMount'); - } - - componentWillEnter = cb => { - log.push('willEnter'); - willEnterCb = cb; - }; - - componentDidEnter = () => { - log.push('didEnter'); - }; - - componentWillLeave = cb => { - log.push('willLeave'); - cb(); - }; - - componentDidLeave = () => { - log.push('didLeave'); - }; - - componentWillUnmount() { - log.push('willUnmount'); - } - - render() { - return ; - } - } - - class Component extends React.Component { - state = {count: 1}; - - render() { - var children = []; - for (var i = 0; i < this.state.count; i++) { - children.push(); - } - return {children}; - } - } - - var instance = ReactDOM.render(, container); - expect(log).toEqual(['didMount']); - instance.setState({count: 2}); - expect(log).toEqual(['didMount', 'didMount', 'willEnter']); - for (var k = 0; k < 5; k++) { - instance.setState({count: 1}); - expect(log).toEqual(['didMount', 'didMount', 'willEnter']); - instance.setState({count: 2}); - } - willEnterCb(); - expect(log).toEqual(['didMount', 'didMount', 'willEnter', 'didEnter']); - }); - - it('should handle entering/leaving several elements at once', () => { - var log = []; - - class Child extends React.Component { - componentDidMount() { - log.push('didMount' + this.props.id); - } - - componentWillEnter = cb => { - log.push('willEnter' + this.props.id); - cb(); - }; - - componentDidEnter = () => { - log.push('didEnter' + this.props.id); - }; - - componentWillLeave = cb => { - log.push('willLeave' + this.props.id); - cb(); - }; - - componentDidLeave = () => { - log.push('didLeave' + this.props.id); - }; - - componentWillUnmount() { - log.push('willUnmount' + this.props.id); - } - - render() { - return ; - } - } - - class Component extends React.Component { - state = {count: 1}; - - render() { - var children = []; - for (var i = 0; i < this.state.count; i++) { - children.push(); - } - return {children}; - } - } - - var instance = ReactDOM.render(, container); - expect(log).toEqual(['didMount0']); - log = []; - - instance.setState({count: 3}); - expect(log).toEqual([ - 'didMount1', - 'didMount2', - 'willEnter1', - 'didEnter1', - 'willEnter2', - 'didEnter2', - ]); - log = []; - - instance.setState({count: 0}); - expect(log).toEqual([ - 'willLeave0', - 'didLeave0', - 'willLeave1', - 'didLeave1', - 'willLeave2', - 'didLeave2', - 'willUnmount0', - 'willUnmount1', - 'willUnmount2', - ]); - }); - - it('should warn for duplicated keys', () => { - spyOn(console, 'error'); - - class Component extends React.Component { - render() { - var children = [
,
]; - return {children}; - } - } - - ReactDOM.render(, container); - - expectDev(console.error.calls.count()).toBe(2); - expectDev(console.error.calls.argsFor(0)[0]).toBe( - 'Warning: flattenChildren(...): ' + - 'Encountered two children with the same key, `1`. ' + - 'Child keys must be unique; when two children share a key, ' + - 'only the first child will be used.', - ); - expectDev(console.error.calls.argsFor(1)[0]).toBe( - 'Warning: flattenChildren(...): ' + - 'Encountered two children with the same key, `1`. ' + - 'Child keys must be unique; when two children share a key, ' + - 'only the first child will be used.', - ); - }); -}); diff --git a/src/addons/update.js b/src/addons/update.js deleted file mode 100644 index d690c6723a..0000000000 --- a/src/addons/update.js +++ /dev/null @@ -1,169 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @providesModule update - */ - -/* global hasOwnProperty:true */ - -'use strict'; - -var invariant = require('fbjs/lib/invariant'); -var hasOwnProperty = {}.hasOwnProperty; - -function shallowCopy(x) { - if (Array.isArray(x)) { - return x.concat(); - } else if (x && typeof x === 'object') { - return Object.assign(new x.constructor(), x); - } else { - return x; - } -} - -var COMMAND_PUSH = '$push'; -var COMMAND_UNSHIFT = '$unshift'; -var COMMAND_SPLICE = '$splice'; -var COMMAND_SET = '$set'; -var COMMAND_MERGE = '$merge'; -var COMMAND_APPLY = '$apply'; - -var ALL_COMMANDS_LIST = [ - COMMAND_PUSH, - COMMAND_UNSHIFT, - COMMAND_SPLICE, - COMMAND_SET, - COMMAND_MERGE, - COMMAND_APPLY, -]; - -var ALL_COMMANDS_SET = {}; - -ALL_COMMANDS_LIST.forEach(function(command) { - ALL_COMMANDS_SET[command] = true; -}); - -function invariantArrayCase(value, spec, command) { - invariant( - Array.isArray(value), - 'update(): expected target of %s to be an array; got %s.', - command, - value, - ); - var specValue = spec[command]; - invariant( - Array.isArray(specValue), - 'update(): expected spec of %s to be an array; got %s. ' + - 'Did you forget to wrap your parameter in an array?', - command, - specValue, - ); -} - -/** - * Returns a updated shallow copy of an object without mutating the original. - * See https://facebook.github.io/react/docs/update.html for details. - */ -function update(value, spec) { - invariant( - typeof spec === 'object', - 'update(): You provided a key path to update() that did not contain one ' + - 'of %s. Did you forget to include {%s: ...}?', - ALL_COMMANDS_LIST.join(', '), - COMMAND_SET, - ); - - if (hasOwnProperty.call(spec, COMMAND_SET)) { - invariant( - Object.keys(spec).length === 1, - 'Cannot have more than one key in an object with %s', - COMMAND_SET, - ); - - return spec[COMMAND_SET]; - } - - var nextValue = shallowCopy(value); - - if (hasOwnProperty.call(spec, COMMAND_MERGE)) { - var mergeObj = spec[COMMAND_MERGE]; - invariant( - mergeObj && typeof mergeObj === 'object', - "update(): %s expects a spec of type 'object'; got %s", - COMMAND_MERGE, - mergeObj, - ); - invariant( - nextValue && typeof nextValue === 'object', - "update(): %s expects a target of type 'object'; got %s", - COMMAND_MERGE, - nextValue, - ); - Object.assign(nextValue, spec[COMMAND_MERGE]); - } - - if (hasOwnProperty.call(spec, COMMAND_PUSH)) { - invariantArrayCase(value, spec, COMMAND_PUSH); - spec[COMMAND_PUSH].forEach(function(item) { - nextValue.push(item); - }); - } - - if (hasOwnProperty.call(spec, COMMAND_UNSHIFT)) { - invariantArrayCase(value, spec, COMMAND_UNSHIFT); - spec[COMMAND_UNSHIFT].forEach(function(item) { - nextValue.unshift(item); - }); - } - - if (hasOwnProperty.call(spec, COMMAND_SPLICE)) { - invariant( - Array.isArray(value), - 'Expected %s target to be an array; got %s', - COMMAND_SPLICE, - value, - ); - invariant( - Array.isArray(spec[COMMAND_SPLICE]), - 'update(): expected spec of %s to be an array of arrays; got %s. ' + - 'Did you forget to wrap your parameters in an array?', - COMMAND_SPLICE, - spec[COMMAND_SPLICE], - ); - spec[COMMAND_SPLICE].forEach(function(args) { - invariant( - Array.isArray(args), - 'update(): expected spec of %s to be an array of arrays; got %s. ' + - 'Did you forget to wrap your parameters in an array?', - COMMAND_SPLICE, - spec[COMMAND_SPLICE], - ); - nextValue.splice.apply(nextValue, args); - }); - } - - if (hasOwnProperty.call(spec, COMMAND_APPLY)) { - invariant( - typeof spec[COMMAND_APPLY] === 'function', - 'update(): expected spec of %s to be a function; got %s.', - COMMAND_APPLY, - spec[COMMAND_APPLY], - ); - nextValue = spec[COMMAND_APPLY](nextValue); - } - - for (var k in spec) { - if (!(ALL_COMMANDS_SET.hasOwnProperty(k) && ALL_COMMANDS_SET[k])) { - nextValue[k] = update(value[k], spec[k]); - } - } - - return nextValue; -} - -module.exports = update; diff --git a/src/isomorphic/children/__tests__/ReactChildren-test.js b/src/isomorphic/children/__tests__/ReactChildren-test.js index 6c3421c96d..a71ea8f7a7 100644 --- a/src/isomorphic/children/__tests__/ReactChildren-test.js +++ b/src/isomorphic/children/__tests__/ReactChildren-test.js @@ -13,12 +13,10 @@ describe('ReactChildren', () => { var React; - var ReactFragment; beforeEach(() => { jest.resetModules(); React = require('react'); - ReactFragment = require('ReactFragment'); }); it('should support identity for simple', () => { @@ -150,8 +148,8 @@ describe('ReactChildren', () => { var instance = (
{div} - {[ReactFragment.create({span})]} - {ReactFragment.create({a: a})} + {[[span]]} + {[a]} {'string'} {1234} {true} @@ -164,8 +162,8 @@ describe('ReactChildren', () => { function assertCalls() { expect(callback.calls.count()).toBe(9); expect(callback).toHaveBeenCalledWith(div, 0); - expect(callback).toHaveBeenCalledWith(, 1); - expect(callback).toHaveBeenCalledWith(, 2); + expect(callback).toHaveBeenCalledWith(span, 1); + expect(callback).toHaveBeenCalledWith(a, 2); expect(callback).toHaveBeenCalledWith('string', 3); expect(callback).toHaveBeenCalledWith(1234, 4); expect(callback).toHaveBeenCalledWith(null, 5); @@ -186,8 +184,8 @@ describe('ReactChildren', () => { assertCalls(); expect(mappedChildren).toEqual([
, - , - , + , + , 'string', 1234, ]); @@ -199,12 +197,7 @@ describe('ReactChildren', () => { var two =
; var three = null; var four =
; - var five =
; - // five is placed into a JS object with a key that is joined to the - // component key attribute. - // Precedence is as follows: - // 1. If grouped in an Object, the object key combined with `key` prop - // 2. If grouped in an Array, the `key` prop, falling back to array index + var five =
; var context = {}; var callback = jasmine.createSpy().and.callFake(function(kid) { @@ -213,34 +206,18 @@ describe('ReactChildren', () => { var instance = (
- {[ - ReactFragment.create({ - firstHalfKey: [zero, one, two], - secondHalfKey: [three, four], - keyFive: five, - }), - ]} + {[[zero, one, two], [three, four], five]}
); function assertCalls() { - expect(callback.calls.count()).toBe(4); - expect(callback).toHaveBeenCalledWith( -
, - 0, - ); - expect(callback).toHaveBeenCalledWith( -
, - 1, - ); - expect(callback).toHaveBeenCalledWith( -
, - 2, - ); - expect(callback).toHaveBeenCalledWith( -
, - 3, - ); + expect(callback.calls.count()).toBe(6); + expect(callback).toHaveBeenCalledWith(zero, 0); + expect(callback).toHaveBeenCalledWith(one, 1); + expect(callback).toHaveBeenCalledWith(two, 2); + expect(callback).toHaveBeenCalledWith(three, 3); + expect(callback).toHaveBeenCalledWith(four, 4); + expect(callback).toHaveBeenCalledWith(five, 5); callback.calls.reset(); } @@ -254,10 +231,10 @@ describe('ReactChildren', () => { ); assertCalls(); expect(mappedChildren).toEqual([ -
, -
, -
, -
, +
, +
, +
, +
, ]); }); @@ -601,52 +578,49 @@ describe('ReactChildren', () => { var two =
; var three = null; var four =
; - var five =
; - // five is placed into a JS object with a key that is joined to the - // component key attribute. - // Precedence is as follows: - // 1. If grouped in an Object, the object key combined with `key` prop - // 2. If grouped in an Array, the `key` prop, falling back to array index + var five =
; var zeroMapped =
; // Key should be overridden var twoMapped =
; // Key should be added even if not supplied! var fourMapped =
; var fiveMapped =
; - var callback = jasmine.createSpy().and.callFake(function(kid, index) { - return index === 0 - ? zeroMapped - : index === 1 ? twoMapped : index === 2 ? fourMapped : fiveMapped; + var callback = jasmine.createSpy().and.callFake(function(kid) { + switch (kid) { + case zero: + return zeroMapped; + case two: + return twoMapped; + case four: + return fourMapped; + case five: + return fiveMapped; + default: + return kid; + } }); - var frag = ReactFragment.create({ - firstHalfKey: [zero, one, two], - secondHalfKey: [three, four], - keyFive: five, - }); + var frag = [[zero, one, two], [three, four], five]; var instance =
{[frag]}
; - expect([frag[0].key, frag[1].key, frag[2].key, frag[3].key]).toEqual([ - 'firstHalfKey/.$keyZero', - 'firstHalfKey/.$keyTwo', - 'secondHalfKey/.$keyFour', - 'keyFive/.$keyFiveInner', - ]); - React.Children.forEach(instance.props.children, callback); - expect(callback.calls.count()).toBe(4); - expect(callback).toHaveBeenCalledWith(frag[0], 0); - expect(callback).toHaveBeenCalledWith(frag[1], 1); - expect(callback).toHaveBeenCalledWith(frag[2], 2); - expect(callback).toHaveBeenCalledWith(frag[3], 3); + expect(callback.calls.count()).toBe(6); + expect(callback).toHaveBeenCalledWith(zero, 0); + expect(callback).toHaveBeenCalledWith(one, 1); + expect(callback).toHaveBeenCalledWith(two, 2); + expect(callback).toHaveBeenCalledWith(three, 3); + expect(callback).toHaveBeenCalledWith(four, 4); + expect(callback).toHaveBeenCalledWith(five, 5); callback.calls.reset(); var mappedChildren = React.Children.map(instance.props.children, callback); - expect(callback.calls.count()).toBe(4); - expect(callback).toHaveBeenCalledWith(frag[0], 0); - expect(callback).toHaveBeenCalledWith(frag[1], 1); - expect(callback).toHaveBeenCalledWith(frag[2], 2); - expect(callback).toHaveBeenCalledWith(frag[3], 3); + expect(callback.calls.count()).toBe(6); + expect(callback).toHaveBeenCalledWith(zero, 0); + expect(callback).toHaveBeenCalledWith(one, 1); + expect(callback).toHaveBeenCalledWith(two, 2); + expect(callback).toHaveBeenCalledWith(three, 3); + expect(callback).toHaveBeenCalledWith(four, 4); + expect(callback).toHaveBeenCalledWith(five, 5); expect(React.Children.count(mappedChildren)).toBe(4); // Keys default to indices. @@ -656,20 +630,16 @@ describe('ReactChildren', () => { mappedChildren[2].key, mappedChildren[3].key, ]).toEqual([ - 'giraffe/.0:$firstHalfKey/.$keyZero', - '.0:$firstHalfKey/.$keyTwo', - 'keyFour/.0:$secondHalfKey/.$keyFour', - '.0:$keyFive/.$keyFiveInner', + 'giraffe/.0:0:$keyZero', + '.0:0:$keyTwo', + '.0:1:$keyFour', + '.0:$keyFive', ]); - expect(mappedChildren[0]).toEqual( -
, - ); - expect(mappedChildren[1]).toEqual(
); - expect(mappedChildren[2]).toEqual( -
, - ); - expect(mappedChildren[3]).toEqual(
); + expect(mappedChildren[0]).toEqual(
); + expect(mappedChildren[1]).toEqual(
); + expect(mappedChildren[2]).toEqual(
); + expect(mappedChildren[3]).toEqual(
); }); it('should retain key across two mappings', () => { @@ -812,27 +782,15 @@ describe('ReactChildren', () => { var two =
; var three = null; var four =
; - var five =
; - // five is placed into a JS object with a key that is joined to the - // component key attribute. - // Precedence is as follows: - // 1. If grouped in an Object, the object key combined with `key` prop - // 2. If grouped in an Array, the `key` prop, falling back to array index + var five =
; var instance = (
- {[ - ReactFragment.create({ - firstHalfKey: [zero, one, two], - secondHalfKey: [three, four], - keyFive: five, - }), - null, - ]} + {[[[zero, one, two], [three, four], five], null]}
); var numberOfChildren = React.Children.count(instance.props.children); - expect(numberOfChildren).toBe(5); + expect(numberOfChildren).toBe(7); }); it('should flatten children to an array', () => { @@ -878,8 +836,7 @@ describe('ReactChildren', () => { }).toThrowError( 'Objects are not valid as a React child (found: object with keys ' + '{a, b}). If you meant to render a collection of children, use an ' + - 'array instead or wrap the object using createFragment(object) from ' + - 'the React add-ons.', + 'array instead.', ); }); @@ -890,8 +847,7 @@ describe('ReactChildren', () => { React.Children.forEach(/abc/, function() {}, null); }).toThrowError( 'Objects are not valid as a React child (found: /abc/). If you meant ' + - 'to render a collection of children, use an array instead or wrap the ' + - 'object using createFragment(object) from the React add-ons.', + 'to render a collection of children, use an array instead.', ); }); }); diff --git a/src/isomorphic/children/__tests__/onlyChild-test.js b/src/isomorphic/children/__tests__/onlyChild-test.js index 45ee0f74b3..082c389e6b 100644 --- a/src/isomorphic/children/__tests__/onlyChild-test.js +++ b/src/isomorphic/children/__tests__/onlyChild-test.js @@ -13,13 +13,11 @@ describe('onlyChild', () => { var React; - var ReactFragment; var onlyChild; var WrapComponent; beforeEach(() => { React = require('react'); - ReactFragment = require('ReactFragment'); onlyChild = require('onlyChild'); WrapComponent = class extends React.Component { render() { @@ -68,7 +66,7 @@ describe('onlyChild', () => { expect(function() { var instance = ( - {ReactFragment.create({oneThing: })} + {[]} ); onlyChild(instance.props.children); diff --git a/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js b/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js index c5ba572fb2..7405993530 100644 --- a/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js +++ b/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js @@ -16,7 +16,6 @@ var checkPropTypes; var checkReactTypeSpec; var React; var ReactDOM; -var ReactFragment; var Component; var MyComponent; @@ -115,7 +114,6 @@ describe('ReactPropTypes', () => { PropTypes = require('ReactPropTypes'); React = require('react'); ReactDOM = require('react-dom'); - ReactFragment = require('ReactFragment'); resetWarningCache(); }); @@ -615,39 +613,20 @@ describe('ReactPropTypes', () => { }); it('should not warn for valid values', () => { - spyOn(console, 'error'); typeCheckPass(PropTypes.node,
); typeCheckPass(PropTypes.node, false); typeCheckPass(PropTypes.node, ); typeCheckPass(PropTypes.node, 'Some string'); typeCheckPass(PropTypes.node, []); - typeCheckPass(PropTypes.node, [ 123, 'Some string',
, ['Another string', [456], , ], , + null, + undefined, ]); - - // Object of renderable things - var frag = ReactFragment.create; - typeCheckPass( - PropTypes.node, - frag({ - k0: 123, - k1: 'Some string', - k2:
, - k3: frag({ - k30: , - k31: frag({k310: }), - k32: 'Another string', - }), - k4: null, - k5: undefined, - }), - ); - expectDev(console.error.calls.count()).toBe(0); }); it('should not warn for iterables', () => { diff --git a/src/renderers/__tests__/ReactComponent-test.js b/src/renderers/__tests__/ReactComponent-test.js index b909c8ab10..50dcec84ef 100644 --- a/src/renderers/__tests__/ReactComponent-test.js +++ b/src/renderers/__tests__/ReactComponent-test.js @@ -380,4 +380,38 @@ describe('ReactComponent', () => { // One warning for each element creation expectDev(console.error.calls.count()).toBe(1); }); + + it('throws if a plain object is used as a child', () => { + var children = { + x: , + y: , + z: , + }; + var element =
{[children]}
; + var container = document.createElement('div'); + expect(() => ReactDOM.render(element, container)).toThrowError( + 'Objects are not valid as a React child (found: object with keys ' + + '{x, y, z}). If you meant to render a collection of children, use an ' + + 'array instead.', + ); + }); + + it('throws if a plain object even if it is in an owner', () => { + class Foo extends React.Component { + render() { + var children = { + a: , + b: , + c: , + }; + return
{[children]}
; + } + } + var container = document.createElement('div'); + expect(() => ReactDOM.render(, container)).toThrowError( + 'Objects are not valid as a React child (found: object with keys ' + + '{a, b, c}). If you meant to render a collection of children, use an ' + + 'array instead.\n\nCheck the render method of `Foo`.', + ); + }); }); diff --git a/src/renderers/__tests__/ReactCompositeComponent-test.js b/src/renderers/__tests__/ReactCompositeComponent-test.js index 6f82e6f01a..7259ec57b2 100644 --- a/src/renderers/__tests__/ReactCompositeComponent-test.js +++ b/src/renderers/__tests__/ReactCompositeComponent-test.js @@ -20,6 +20,8 @@ var ReactDOMServer; var ReactCurrentOwner; var ReactPropTypes; var ReactTestUtils; +var shallowEqual; +var shallowCompare; describe('ReactCompositeComponent', () => { beforeEach(() => { @@ -31,6 +33,12 @@ describe('ReactCompositeComponent', () => { ReactCurrentOwner = require('react/lib/ReactCurrentOwner'); ReactPropTypes = require('ReactPropTypes'); ReactTestUtils = require('ReactTestUtils'); + shallowEqual = require('fbjs/lib/shallowEqual'); + + shallowCompare = function(instance, nextProps, nextState) { + return !shallowEqual(instance.props, nextProps) || + !shallowEqual(instance.state, nextState); + }; MorphingComponent = class extends React.Component { state = {activated: false}; @@ -1396,4 +1404,119 @@ describe('ReactCompositeComponent', () => { 'B componentDidMount', ]); }); + + it('respects a shallow shouldComponentUpdate implementation', () => { + var renderCalls = 0; + class PlasticWrap extends React.Component { + constructor(props, context) { + super(props, context); + this.state = { + color: 'green', + }; + } + + render() { + return ; + } + } + + class Apple extends React.Component { + state = { + cut: false, + slices: 1, + }; + + shouldComponentUpdate(nextProps, nextState) { + return shallowCompare(this, nextProps, nextState); + } + + cut() { + this.setState({ + cut: true, + slices: 10, + }); + } + + eatSlice() { + this.setState({ + slices: this.state.slices - 1, + }); + } + + render() { + renderCalls++; + return
; + } + } + + var container = document.createElement('div'); + var instance = ReactDOM.render(, container); + expect(renderCalls).toBe(1); + + // Do not re-render based on props + instance.setState({color: 'green'}); + expect(renderCalls).toBe(1); + + // Re-render based on props + instance.setState({color: 'red'}); + expect(renderCalls).toBe(2); + + // Re-render base on state + instance.refs.apple.cut(); + expect(renderCalls).toBe(3); + + // No re-render based on state + instance.refs.apple.cut(); + expect(renderCalls).toBe(3); + + // Re-render based on state again + instance.refs.apple.eatSlice(); + expect(renderCalls).toBe(4); + }); + + it('does not do a deep comparison for a shallow shouldComponentUpdate implementation', () => { + function getInitialState() { + return { + foo: [1, 2, 3], + bar: {a: 4, b: 5, c: 6}, + }; + } + + var renderCalls = 0; + var initialSettings = getInitialState(); + + class Component extends React.Component { + state = initialSettings; + + shouldComponentUpdate(nextProps, nextState) { + return shallowCompare(this, nextProps, nextState); + } + + render() { + renderCalls++; + return
; + } + } + + var container = document.createElement('div'); + var instance = ReactDOM.render(, container); + expect(renderCalls).toBe(1); + + // Do not re-render if state is equal + var settings = { + foo: initialSettings.foo, + bar: initialSettings.bar, + }; + instance.setState(settings); + expect(renderCalls).toBe(1); + + // Re-render because one field changed + initialSettings.foo = [1, 2, 3]; + instance.setState(initialSettings); + expect(renderCalls).toBe(2); + + // Re-render because the object changed + instance.setState(getInitialState()); + expect(renderCalls).toBe(3); + }); }); diff --git a/src/renderers/__tests__/ReactIdentity-test.js b/src/renderers/__tests__/ReactIdentity-test.js index e25f1ff049..369c625706 100644 --- a/src/renderers/__tests__/ReactIdentity-test.js +++ b/src/renderers/__tests__/ReactIdentity-test.js @@ -13,7 +13,6 @@ var React; var ReactDOM; -var ReactFragment; var ReactTestUtils; describe('ReactIdentity', () => { @@ -21,14 +20,9 @@ describe('ReactIdentity', () => { jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); - ReactFragment = require('ReactFragment'); ReactTestUtils = require('ReactTestUtils'); }); - function frag(obj) { - return ReactFragment.create(obj); - } - it('should allow key property to express identity', () => { var node; var Component = props => ( @@ -72,21 +66,13 @@ describe('ReactIdentity', () => { function renderAComponentWithKeyIntoContainer(key, container) { class Wrapper extends React.Component { render() { - var s1 = ; - var s2 = ; - - var map = {}; - map[key] = s2; - return
{[s1, frag(map)]}
; + return
; } } var instance = ReactDOM.render(, container); - var span1 = instance.refs.span1; - var span2 = instance.refs.span2; - - expect(ReactDOM.findDOMNode(span1)).not.toBe(null); - expect(ReactDOM.findDOMNode(span2)).not.toBe(null); + var span = instance.refs.span; + expect(ReactDOM.findDOMNode(span)).not.toBe(null); } it('should allow any character as a key, in a detached parent', () => { diff --git a/src/renderers/dom/shared/__tests__/ReactDOMServerIntegration-test.js b/src/renderers/dom/shared/__tests__/ReactDOMServerIntegration-test.js index 3b7b4e4d25..f3aa90ce90 100644 --- a/src/renderers/dom/shared/__tests__/ReactDOMServerIntegration-test.js +++ b/src/renderers/dom/shared/__tests__/ReactDOMServerIntegration-test.js @@ -65,14 +65,20 @@ function renderIntoDom(reactElement, domElement, errorCount = 0) { ); } +async function renderIntoString(reactElement, errorCount = 0) { + return await expectErrors( + () => + new Promise(resolve => + resolve(ReactDOMServer.renderToString(reactElement))), + errorCount, + ); +} + // Renders text using SSR and then stuffs it into a DOM node; returns the DOM // element that corresponds with the reactElement. // Does not render on client or perform client-side revival. async function serverRender(reactElement, errorCount = 0) { - const markup = await expectErrors( - () => Promise.resolve(ReactDOMServer.renderToString(reactElement)), - errorCount, - ); + const markup = await renderIntoString(reactElement, errorCount); var domElement = document.createElement('div'); domElement.innerHTML = markup; return domElement.firstChild; @@ -84,10 +90,17 @@ const clientCleanRender = (element, errorCount = 0) => { }; const clientRenderOnServerString = async (element, errorCount = 0) => { - const markup = await serverRender(element, errorCount); + const markup = await renderIntoString(element, errorCount); + resetModules(); var domElement = document.createElement('div'); domElement.innerHTML = markup; - return renderIntoDom(element, domElement, errorCount); + const serverElement = domElement.firstChild; + const clientElement = await renderIntoDom(element, domElement, errorCount); + // assert that the DOM element hasn't been replaced. + // Note that we cannot use expect(serverElement).toBe(clientElement) because + // of jest bug #1772 + expect(serverElement === clientElement).toBe(true); + return clientElement; }; const clientRenderOnBadMarkup = (element, errorCount = 0) => { @@ -135,14 +148,22 @@ function itClientRenders(desc, testFn) { testFn(clientRenderOnBadMarkup)); } +// When there is a test that renders on server and then on client and expects a logged +// error, you want to see the error show up both on server and client. Unfortunately, +// React refuses to issue the same error twice to avoid clogging up the console. +// To get around this, we must reload React modules in between server and client render. +function resetModules() { + jest.resetModuleRegistry(); + React = require('React'); + ReactDOM = require('ReactDOM'); + ReactDOMServer = require('ReactDOMServer'); + ExecutionEnvironment = require('ExecutionEnvironment'); +} + describe('ReactDOMServerIntegration', () => { beforeEach(() => { - jest.resetModuleRegistry(); - React = require('React'); - ReactDOM = require('ReactDOM'); - ReactDOMServer = require('ReactDOMServer'); + resetModules(); - ExecutionEnvironment = require('ExecutionEnvironment'); ExecutionEnvironment.canUseDOM = false; }); @@ -169,4 +190,224 @@ describe('ReactDOMServerIntegration', () => { expect(e.firstChild.tagName).toBe('BR'); }); }); + + describe('property to attribute mapping', function() { + describe('string properties', function() { + itRenders('simple numbers', async render => { + const e = await render(
); + expect(e.getAttribute('width')).toBe('30'); + }); + + itRenders('simple strings', async render => { + const e = await render(
); + expect(e.getAttribute('width')).toBe('30'); + }); + + // this seems like it might mask programmer error, but it's existing behavior. + itRenders('string prop with true value', async render => { + const e = await render(); + expect(e.getAttribute('href')).toBe('true'); + }); + + // this seems like it might mask programmer error, but it's existing behavior. + itRenders('string prop with false value', async render => { + const e = await render(); + expect(e.getAttribute('href')).toBe('false'); + }); + }); + + describe('boolean properties', function() { + itRenders('boolean prop with true value', async render => { + const e = await render(