react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / core / ReactNativeComponent.js
81152 views/**1* Copyright 2014, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under the BSD-style license found in the5* LICENSE file in the root directory of this source tree. An additional grant6* of patent rights can be found in the PATENTS file in the same directory.7*8* @providesModule ReactNativeComponent9*/1011"use strict";1213var assign = require('Object.assign');14var invariant = require('invariant');1516var genericComponentClass = null;17// This registry keeps track of wrapper classes around native tags18var tagToComponentClass = {};1920var ReactNativeComponentInjection = {21// This accepts a class that receives the tag string. This is a catch all22// that can render any kind of tag.23injectGenericComponentClass: function(componentClass) {24genericComponentClass = componentClass;25},26// This accepts a keyed object with classes as values. Each key represents a27// tag. That particular tag will use this class instead of the generic one.28injectComponentClasses: function(componentClasses) {29assign(tagToComponentClass, componentClasses);30}31};3233/**34* Create an internal class for a specific tag.35*36* @param {string} tag The tag for which to create an internal instance.37* @param {any} props The props passed to the instance constructor.38* @return {ReactComponent} component The injected empty component.39*/40function createInstanceForTag(tag, props, parentType) {41var componentClass = tagToComponentClass[tag];42if (componentClass == null) {43invariant(44genericComponentClass,45'There is no registered component for the tag %s',46tag47);48return new genericComponentClass(tag, props);49}50if (parentType === tag) {51// Avoid recursion52invariant(53genericComponentClass,54'There is no registered component for the tag %s',55tag56);57return new genericComponentClass(tag, props);58}59// Unwrap legacy factories60return new componentClass.type(props);61}6263var ReactNativeComponent = {64createInstanceForTag: createInstanceForTag,65injection: ReactNativeComponentInjection66};6768module.exports = ReactNativeComponent;697071