mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
This copies the propType and contextType validation to a wrapper around the descriptor factory. By doing the validation early, we make it easier to track down bugs. It also prepares for static type checking which should be done at the usage site. This validation is not yet active and is just logged using monitorCodeUse. This will allow us to clean up callsites which would fail this new type of validation. I chose to copy the validation of abstracting it out since this is just an intermediate step to avoid spamming consoles. This makes more a much cleaner diff review/history. The original validation in the instance will be deleted as soon as we can turn on the warnings. Additionally, getDefaultProps are moved to become a static function which is only executed once. It should be moved to statics but we don't have a convenient way to merge mixins in statics right now. Deferring to ES6 classes. This is still a breaking change since you can return an object or array from getDefaultProps, which later gets mutated and now the shared instance is mutated. Mutating an object that is passed into you from props is highly discouraged and likely to lead to subtle bugs anyway. So I'm not too worried. The defaultProps will later be resolved in the descriptor factory. This will enable a perf optimizations where we don't create an unnecessary object allocation when you use default props. It also means that ReactChildren.map has access to resolved properties which gives them consistent behavior whether or not the default prop is specified.
210 lines
4.4 KiB
JavaScript
210 lines
4.4 KiB
JavaScript
/**
|
|
* Copyright 2013-2014 Facebook, Inc.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*
|
|
* @providesModule ReactDOM
|
|
* @typechecks static-only
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
var ReactDescriptor = require('ReactDescriptor');
|
|
var ReactDescriptorValidator = require('ReactDescriptorValidator');
|
|
var ReactDOMComponent = require('ReactDOMComponent');
|
|
|
|
var mergeInto = require('mergeInto');
|
|
var mapObject = require('mapObject');
|
|
|
|
/**
|
|
* Creates a new React class that is idempotent and capable of containing other
|
|
* React components. It accepts event listeners and DOM properties that are
|
|
* valid according to `DOMProperty`.
|
|
*
|
|
* - Event listeners: `onClick`, `onMouseDown`, etc.
|
|
* - DOM properties: `className`, `name`, `title`, etc.
|
|
*
|
|
* The `style` property functions differently from the DOM API. It accepts an
|
|
* object mapping of style properties to values.
|
|
*
|
|
* @param {boolean} omitClose True if the close tag should be omitted.
|
|
* @param {string} tag Tag name (e.g. `div`).
|
|
* @private
|
|
*/
|
|
function createDOMComponentClass(omitClose, tag) {
|
|
var Constructor = function(descriptor) {
|
|
this.construct(descriptor);
|
|
};
|
|
Constructor.prototype = new ReactDOMComponent(tag, omitClose);
|
|
Constructor.prototype.constructor = Constructor;
|
|
Constructor.displayName = tag;
|
|
|
|
var ConvenienceConstructor = ReactDescriptor.createFactory(Constructor);
|
|
|
|
if (__DEV__) {
|
|
return ReactDescriptorValidator.createFactory(
|
|
ConvenienceConstructor
|
|
);
|
|
}
|
|
|
|
return ConvenienceConstructor;
|
|
}
|
|
|
|
/**
|
|
* Creates a mapping from supported HTML tags to `ReactDOMComponent` classes.
|
|
* This is also accessible via `React.DOM`.
|
|
*
|
|
* @public
|
|
*/
|
|
var ReactDOM = mapObject({
|
|
a: false,
|
|
abbr: false,
|
|
address: false,
|
|
area: true,
|
|
article: false,
|
|
aside: false,
|
|
audio: false,
|
|
b: false,
|
|
base: true,
|
|
bdi: false,
|
|
bdo: false,
|
|
big: false,
|
|
blockquote: false,
|
|
body: false,
|
|
br: true,
|
|
button: false,
|
|
canvas: false,
|
|
caption: false,
|
|
cite: false,
|
|
code: false,
|
|
col: true,
|
|
colgroup: false,
|
|
data: false,
|
|
datalist: false,
|
|
dd: false,
|
|
del: false,
|
|
details: false,
|
|
dfn: false,
|
|
div: false,
|
|
dl: false,
|
|
dt: false,
|
|
em: false,
|
|
embed: true,
|
|
fieldset: false,
|
|
figcaption: false,
|
|
figure: false,
|
|
footer: false,
|
|
form: false, // NOTE: Injected, see `ReactDOMForm`.
|
|
h1: false,
|
|
h2: false,
|
|
h3: false,
|
|
h4: false,
|
|
h5: false,
|
|
h6: false,
|
|
head: false,
|
|
header: false,
|
|
hr: true,
|
|
html: false,
|
|
i: false,
|
|
iframe: false,
|
|
img: true,
|
|
input: true,
|
|
ins: false,
|
|
kbd: false,
|
|
keygen: true,
|
|
label: false,
|
|
legend: false,
|
|
li: false,
|
|
link: true,
|
|
main: false,
|
|
map: false,
|
|
mark: false,
|
|
menu: false,
|
|
menuitem: false, // NOTE: Close tag should be omitted, but causes problems.
|
|
meta: true,
|
|
meter: false,
|
|
nav: false,
|
|
noscript: false,
|
|
object: false,
|
|
ol: false,
|
|
optgroup: false,
|
|
option: false,
|
|
output: false,
|
|
p: false,
|
|
param: true,
|
|
pre: false,
|
|
progress: false,
|
|
q: false,
|
|
rp: false,
|
|
rt: false,
|
|
ruby: false,
|
|
s: false,
|
|
samp: false,
|
|
script: false,
|
|
section: false,
|
|
select: false,
|
|
small: false,
|
|
source: true,
|
|
span: false,
|
|
strong: false,
|
|
style: false,
|
|
sub: false,
|
|
summary: false,
|
|
sup: false,
|
|
table: false,
|
|
tbody: false,
|
|
td: false,
|
|
textarea: false, // NOTE: Injected, see `ReactDOMTextarea`.
|
|
tfoot: false,
|
|
th: false,
|
|
thead: false,
|
|
time: false,
|
|
title: false,
|
|
tr: false,
|
|
track: true,
|
|
u: false,
|
|
ul: false,
|
|
'var': false,
|
|
video: false,
|
|
wbr: true,
|
|
|
|
// SVG
|
|
circle: false,
|
|
defs: false,
|
|
ellipse: false,
|
|
g: false,
|
|
line: false,
|
|
linearGradient: false,
|
|
mask: false,
|
|
path: false,
|
|
pattern: false,
|
|
polygon: false,
|
|
polyline: false,
|
|
radialGradient: false,
|
|
rect: false,
|
|
stop: false,
|
|
svg: false,
|
|
text: false,
|
|
tspan: false
|
|
}, createDOMComponentClass);
|
|
|
|
var injection = {
|
|
injectComponentClasses: function(componentClasses) {
|
|
mergeInto(ReactDOM, componentClasses);
|
|
}
|
|
};
|
|
|
|
ReactDOM.injection = injection;
|
|
|
|
module.exports = ReactDOM;
|