UNPKG

1.85 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2014-present, Facebook, Inc.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 */
8
9'use strict';
10
11var _prodInvariant = require('./reactProdInvariant');
12
13var invariant = require('fbjs/lib/invariant');
14
15var genericComponentClass = null;
16var textComponentClass = null;
17
18var ReactHostComponentInjection = {
19 // This accepts a class that receives the tag string. This is a catch all
20 // that can render any kind of tag.
21 injectGenericComponentClass: function (componentClass) {
22 genericComponentClass = componentClass;
23 },
24 // This accepts a text component class that takes the text string to be
25 // rendered as props.
26 injectTextComponentClass: function (componentClass) {
27 textComponentClass = componentClass;
28 }
29};
30
31/**
32 * Get a host internal component class for a specific tag.
33 *
34 * @param {ReactElement} element The element to create.
35 * @return {function} The internal class constructor function.
36 */
37function createInternalComponent(element) {
38 !genericComponentClass ? process.env.NODE_ENV !== 'production' ? invariant(false, 'There is no registered component for the tag %s', element.type) : _prodInvariant('111', element.type) : void 0;
39 return new genericComponentClass(element);
40}
41
42/**
43 * @param {ReactText} text
44 * @return {ReactComponent}
45 */
46function createInstanceForText(text) {
47 return new textComponentClass(text);
48}
49
50/**
51 * @param {ReactComponent} component
52 * @return {boolean}
53 */
54function isTextComponent(component) {
55 return component instanceof textComponentClass;
56}
57
58var ReactHostComponent = {
59 createInternalComponent: createInternalComponent,
60 createInstanceForText: createInstanceForText,
61 isTextComponent: isTextComponent,
62 injection: ReactHostComponentInjection
63};
64
65module.exports = ReactHostComponent;
\No newline at end of file