code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
function validateMethodOverride(proto, name) { var specPolicy = ReactClassInterface.hasOwnProperty(name) ? ReactClassInterface[name] : null; // Disallow overriding of base class methods unless explicitly allowed. if (ReactClassMixin.hasOwnProperty(name)) { !(specPolicy === SpecPolicy.OVERRIDE_BASE) ? "development" !== 'production' ? invariant(false, 'ReactClassInterface: You are attempting to override ' + '`%s` from your class specification. Ensure that your method names ' + 'do not overlap with React methods.', name) : invariant(false) : undefined; } // Disallow defining methods more than once unless explicitly allowed. if (proto.hasOwnProperty(name)) { !(specPolicy === SpecPolicy.DEFINE_MANY || specPolicy === SpecPolicy.DEFINE_MANY_MERGED) ? "development" !== 'production' ? invariant(false, 'ReactClassInterface: You are attempting to define ' + '`%s` on your component more than once. This conflict may be due ' + 'to a mixin.', name) : invariant(false) : undefined; } }
Special case getDefaultProps which should move into statics but requires automatic merging.
validateMethodOverride
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function mixSpecIntoComponent(Constructor, spec) { if (!spec) { return; } !(typeof spec !== 'function') ? "development" !== 'production' ? invariant(false, 'ReactClass: You\'re attempting to ' + 'use a component class as a mixin. Instead, just use a regular object.') : invariant(false) : undefined; !!ReactElement.isValidElement(spec) ? "development" !== 'production' ? invariant(false, 'ReactClass: You\'re attempting to ' + 'use a component as a mixin. Instead, just use a regular object.') : invariant(false) : undefined; var proto = Constructor.prototype; // By handling mixins before any other properties, we ensure the same // chaining order is applied to methods with DEFINE_MANY policy, whether // mixins are listed before or after these methods in the spec. if (spec.hasOwnProperty(MIXINS_KEY)) { RESERVED_SPEC_KEYS.mixins(Constructor, spec.mixins); } for (var name in spec) { if (!spec.hasOwnProperty(name)) { continue; } if (name === MIXINS_KEY) { // We have already handled mixins in a special case above. continue; } var property = spec[name]; validateMethodOverride(proto, name); if (RESERVED_SPEC_KEYS.hasOwnProperty(name)) { RESERVED_SPEC_KEYS[name](Constructor, property); } else { // Setup methods on prototype: // The following member methods should not be automatically bound: // 1. Expected ReactClass methods (in the "interface"). // 2. Overridden methods (that were mixed in). var isReactClassMethod = ReactClassInterface.hasOwnProperty(name); var isAlreadyDefined = proto.hasOwnProperty(name); var isFunction = typeof property === 'function'; var shouldAutoBind = isFunction && !isReactClassMethod && !isAlreadyDefined && spec.autobind !== false; if (shouldAutoBind) { if (!proto.__reactAutoBindMap) { proto.__reactAutoBindMap = {}; } proto.__reactAutoBindMap[name] = property; proto[name] = property; } else { if (isAlreadyDefined) { var specPolicy = ReactClassInterface[name]; // These cases should already be caught by validateMethodOverride. !(isReactClassMethod && (specPolicy === SpecPolicy.DEFINE_MANY_MERGED || specPolicy === SpecPolicy.DEFINE_MANY)) ? "development" !== 'production' ? invariant(false, 'ReactClass: Unexpected spec policy %s for key %s ' + 'when mixing in component specs.', specPolicy, name) : invariant(false) : undefined; // For methods which are defined more than once, call the existing // methods before calling the new property, merging if appropriate. if (specPolicy === SpecPolicy.DEFINE_MANY_MERGED) { proto[name] = createMergedResultFunction(proto[name], property); } else if (specPolicy === SpecPolicy.DEFINE_MANY) { proto[name] = createChainedFunction(proto[name], property); } } else { proto[name] = property; if ("development" !== 'production') { // Add verbose displayName to the function, which helps when looking // at profiling tools. if (typeof property === 'function' && spec.displayName) { proto[name].displayName = spec.displayName + '_' + name; } } } } } } }
Mixin helper which handles policy validation and reserved specification keys when building React classses.
mixSpecIntoComponent
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function mixStaticSpecIntoComponent(Constructor, statics) { if (!statics) { return; } for (var name in statics) { var property = statics[name]; if (!statics.hasOwnProperty(name)) { continue; } var isReserved = (name in RESERVED_SPEC_KEYS); !!isReserved ? "development" !== 'production' ? invariant(false, 'ReactClass: You are attempting to define a reserved ' + 'property, `%s`, that shouldn\'t be on the "statics" key. Define it ' + 'as an instance property instead; it will still be accessible on the ' + 'constructor.', name) : invariant(false) : undefined; var isInherited = (name in Constructor); !!isInherited ? "development" !== 'production' ? invariant(false, 'ReactClass: You are attempting to define ' + '`%s` on your component more than once. This conflict may be ' + 'due to a mixin.', name) : invariant(false) : undefined; Constructor[name] = property; } }
Mixin helper which handles policy validation and reserved specification keys when building React classses.
mixStaticSpecIntoComponent
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function mergeIntoWithNoDuplicateKeys(one, two) { !(one && two && typeof one === 'object' && typeof two === 'object') ? "development" !== 'production' ? invariant(false, 'mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.') : invariant(false) : undefined; for (var key in two) { if (two.hasOwnProperty(key)) { !(one[key] === undefined) ? "development" !== 'production' ? invariant(false, 'mergeIntoWithNoDuplicateKeys(): ' + 'Tried to merge two objects with the same key: `%s`. This conflict ' + 'may be due to a mixin; in particular, this may be caused by two ' + 'getInitialState() or getDefaultProps() methods returning objects ' + 'with clashing keys.', key) : invariant(false) : undefined; one[key] = two[key]; } } return one; }
Merge two objects, but throw if both contain the same key. @param {object} one The first object, which is mutated. @param {object} two The second object @return {object} one after it has been mutated to contain everything in two.
mergeIntoWithNoDuplicateKeys
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function createMergedResultFunction(one, two) { return function mergedResult() { var a = one.apply(this, arguments); var b = two.apply(this, arguments); if (a == null) { return b; } else if (b == null) { return a; } var c = {}; mergeIntoWithNoDuplicateKeys(c, a); mergeIntoWithNoDuplicateKeys(c, b); return c; }; }
Creates a function that invokes two functions and merges their return values. @param {function} one Function to invoke first. @param {function} two Function to invoke second. @return {function} Function that invokes the two argument functions. @private
createMergedResultFunction
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function createChainedFunction(one, two) { return function chainedFunction() { one.apply(this, arguments); two.apply(this, arguments); }; }
Creates a function that invokes two functions and ignores their return vales. @param {function} one Function to invoke first. @param {function} two Function to invoke second. @return {function} Function that invokes the two argument functions. @private
createChainedFunction
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function bindAutoBindMethod(component, method) { var boundMethod = method.bind(component); if ("development" !== 'production') { boundMethod.__reactBoundContext = component; boundMethod.__reactBoundMethod = method; boundMethod.__reactBoundArguments = null; var componentName = component.constructor.displayName; var _bind = boundMethod.bind; /* eslint-disable block-scoped-var, no-undef */ boundMethod.bind = function (newThis) { for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } // User is trying to bind() an autobound method; we effectively will // ignore the value of "this" that the user is trying to use, so // let's warn. if (newThis !== component && newThis !== null) { "development" !== 'production' ? warning(false, 'bind(): React component methods may only be bound to the ' + 'component instance. See %s', componentName) : undefined; } else if (!args.length) { "development" !== 'production' ? warning(false, 'bind(): You are binding a component method to the component. ' + 'React does this for you automatically in a high-performance ' + 'way, so you can safely remove this call. See %s', componentName) : undefined; return boundMethod; } var reboundMethod = _bind.apply(boundMethod, arguments); reboundMethod.__reactBoundContext = component; reboundMethod.__reactBoundMethod = method; reboundMethod.__reactBoundArguments = args; return reboundMethod; /* eslint-enable */ }; } return boundMethod; }
Binds a method to the component. @param {object} component Component whose method is going to be bound. @param {function} method Method to be bound. @return {function} The bound method.
bindAutoBindMethod
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function bindAutoBindMethods(component) { for (var autoBindKey in component.__reactAutoBindMap) { if (component.__reactAutoBindMap.hasOwnProperty(autoBindKey)) { var method = component.__reactAutoBindMap[autoBindKey]; component[autoBindKey] = bindAutoBindMethod(component, method); } } }
Binds all auto-bound methods in a component. @param {object} component Component whose method is going to be bound.
bindAutoBindMethods
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
Constructor = function (props, context, updater) { // This constructor is overridden by mocks. The argument is used // by mocks to assert on what gets mounted. if ("development" !== 'production') { "development" !== 'production' ? warning(this instanceof Constructor, 'Something is calling a React component directly. Use a factory or ' + 'JSX instead. See: https://fb.me/react-legacyfactory') : undefined; } // Wire up auto-binding if (this.__reactAutoBindMap) { bindAutoBindMethods(this); } this.props = props; this.context = context; this.refs = emptyObject; this.updater = updater || ReactNoopUpdateQueue; this.state = null; // ReactClasses doesn't have constructors. Instead, they use the // getInitialState and componentWillMount methods for initialization. var initialState = this.getInitialState ? this.getInitialState() : null; if ("development" !== 'production') { // We allow auto-mocks to proceed as if they're returning null. if (typeof initialState === 'undefined' && this.getInitialState._isMockFunction) { // This is probably bad practice. Consider warning here and // deprecating this convenience. initialState = null; } } !(typeof initialState === 'object' && !Array.isArray(initialState)) ? "development" !== 'production' ? invariant(false, '%s.getInitialState(): must return an object or null', Constructor.displayName || 'ReactCompositeComponent') : invariant(false) : undefined; this.state = initialState; }
Creates a composite component class given a class specification. @param {object} spec Class specification (which must define `render`). @return {function} Component constructor function. @public
Constructor
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function ReactComponent(props, context, updater) { this.props = props; this.context = context; this.refs = emptyObject; // We initialize the default updater but the real one gets injected by the // renderer. this.updater = updater || ReactNoopUpdateQueue; }
Base class helpers for the updating state of a component.
ReactComponent
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
defineDeprecationWarning = function (methodName, info) { if (canDefineProperty) { Object.defineProperty(ReactComponent.prototype, methodName, { get: function () { "development" !== 'production' ? warning(false, '%s(...) is deprecated in plain JavaScript React classes. %s', info[0], info[1]) : undefined; return undefined; } }); } }
Deprecated APIs. These APIs used to exist on classic React classes but since we would like to deprecate them, we're not going to move them over to this modern base class. Instead, we define a getter that warns if it's accessed.
defineDeprecationWarning
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function assertValidProps(component, props) { if (!props) { return; } // Note the use of `==` which checks for null or undefined. if ("development" !== 'production') { if (voidElementTags[component._tag]) { "development" !== 'production' ? warning(props.children == null && props.dangerouslySetInnerHTML == null, '%s is a void element tag and must not have `children` or ' + 'use `props.dangerouslySetInnerHTML`.%s', component._tag, component._currentElement._owner ? ' Check the render method of ' + component._currentElement._owner.getName() + '.' : '') : undefined; } } if (props.dangerouslySetInnerHTML != null) { !(props.children == null) ? "development" !== 'production' ? invariant(false, 'Can only set one of `children` or `props.dangerouslySetInnerHTML`.') : invariant(false) : undefined; !(typeof props.dangerouslySetInnerHTML === 'object' && HTML in props.dangerouslySetInnerHTML) ? "development" !== 'production' ? invariant(false, '`props.dangerouslySetInnerHTML` must be in the form `{__html: ...}`. ' + 'Please visit https://fb.me/react-invariant-dangerously-set-inner-html ' + 'for more information.') : invariant(false) : undefined; } if ("development" !== 'production') { "development" !== 'production' ? warning(props.innerHTML == null, 'Directly setting property `innerHTML` is not permitted. ' + 'For more information, lookup documentation on `dangerouslySetInnerHTML`.') : undefined; "development" !== 'production' ? warning(!props.contentEditable || props.children == null, 'A component is `contentEditable` and contains `children` managed by ' + 'React. It is now your responsibility to guarantee that none of ' + 'those nodes are unexpectedly modified or duplicated. This is ' + 'probably not intentional.') : undefined; } !(props.style == null || typeof props.style === 'object') ? "development" !== 'production' ? invariant(false, 'The `style` prop expects a mapping from style properties to values, ' + 'not a string. For example, style={{marginRight: spacing + \'em\'}} when ' + 'using JSX.%s', getDeclarationErrorAddendum(component)) : invariant(false) : undefined; }
@param {object} component @param {?object} props
assertValidProps
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function enqueuePutListener(id, registrationName, listener, transaction) { if ("development" !== 'production') { // IE8 has no API for event capturing and the `onScroll` event doesn't // bubble. "development" !== 'production' ? warning(registrationName !== 'onScroll' || isEventSupported('scroll', true), 'This browser doesn\'t support the `onScroll` event') : undefined; } var container = ReactMount.findReactContainerForID(id); if (container) { var doc = container.nodeType === ELEMENT_NODE_TYPE ? container.ownerDocument : container; listenTo(registrationName, doc); } transaction.getReactMountReady().enqueue(putListener, { id: id, registrationName: registrationName, listener: listener }); }
@param {object} component @param {?object} props
enqueuePutListener
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function putListener() { var listenerToPut = this; ReactBrowserEventEmitter.putListener(listenerToPut.id, listenerToPut.registrationName, listenerToPut.listener); }
@param {object} component @param {?object} props
putListener
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function trapBubbledEventsLocal() { var inst = this; // If a component renders to null or if another component fatals and causes // the state of the tree to be corrupted, `node` here can be null. !inst._rootNodeID ? "development" !== 'production' ? invariant(false, 'Must be mounted to trap events') : invariant(false) : undefined; var node = ReactMount.getNode(inst._rootNodeID); !node ? "development" !== 'production' ? invariant(false, 'trapBubbledEvent(...): Requires node to be rendered.') : invariant(false) : undefined; switch (inst._tag) { case 'iframe': inst._wrapperState.listeners = [ReactBrowserEventEmitter.trapBubbledEvent(EventConstants.topLevelTypes.topLoad, 'load', node)]; break; case 'video': case 'audio': inst._wrapperState.listeners = []; // create listener for each media event for (var event in mediaEvents) { if (mediaEvents.hasOwnProperty(event)) { inst._wrapperState.listeners.push(ReactBrowserEventEmitter.trapBubbledEvent(EventConstants.topLevelTypes[event], mediaEvents[event], node)); } } break; case 'img': inst._wrapperState.listeners = [ReactBrowserEventEmitter.trapBubbledEvent(EventConstants.topLevelTypes.topError, 'error', node), ReactBrowserEventEmitter.trapBubbledEvent(EventConstants.topLevelTypes.topLoad, 'load', node)]; break; case 'form': inst._wrapperState.listeners = [ReactBrowserEventEmitter.trapBubbledEvent(EventConstants.topLevelTypes.topReset, 'reset', node), ReactBrowserEventEmitter.trapBubbledEvent(EventConstants.topLevelTypes.topSubmit, 'submit', node)]; break; } }
@param {object} component @param {?object} props
trapBubbledEventsLocal
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function validateDangerousTag(tag) { if (!hasOwnProperty.call(validatedTagCache, tag)) { !VALID_TAG_REGEX.test(tag) ? "development" !== 'production' ? invariant(false, 'Invalid tag: %s', tag) : invariant(false) : undefined; validatedTagCache[tag] = true; } }
@param {object} component @param {?object} props
validateDangerousTag
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function processChildContextDev(context, inst) { // Pass down our tag name to child components for validation purposes context = assign({}, context); var info = context[validateDOMNesting.ancestorInfoContextKey]; context[validateDOMNesting.ancestorInfoContextKey] = validateDOMNesting.updatedAncestorInfo(info, inst._tag, inst); return context; }
@param {object} component @param {?object} props
processChildContextDev
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function isCustomComponent(tagName, props) { return tagName.indexOf('-') >= 0 || props.is != null; }
@param {object} component @param {?object} props
isCustomComponent
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function ReactDOMComponent(tag) { validateDangerousTag(tag); this._tag = tag.toLowerCase(); this._renderedChildren = null; this._previousStyle = null; this._previousStyleCopy = null; this._rootNodeID = null; this._wrapperState = null; this._topLevelWrapper = null; this._nodeWithLegacyProperties = null; if ("development" !== 'production') { this._unprocessedContextDev = null; this._processedContextDev = null; } }
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. @constructor ReactDOMComponent @extends ReactMultiChild
ReactDOMComponent
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function createDOMFactory(tag) { if ("development" !== 'production') { return ReactElementValidator.createFactory(tag); } return ReactElement.createFactory(tag); }
Create a factory that creates HTML tag elements. @param {string} tag Tag name (e.g. `div`). @private
createDOMFactory
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function _handleChange(event) { var props = this._currentElement.props; var returnValue = LinkedValueUtils.executeOnChange(props, event); // Here we use asap to wait until all updates have propagated, which // is important when using controlled components within layers: // https://github.com/facebook/react/issues/1698 ReactUpdates.asap(forceUpdateIfMounted, this); var name = props.name; if (props.type === 'radio' && name != null) { var rootNode = ReactMount.getNode(this._rootNodeID); var queryRoot = rootNode; while (queryRoot.parentNode) { queryRoot = queryRoot.parentNode; } // If `rootNode.form` was non-null, then we could try `form.elements`, // but that sometimes behaves strangely in IE8. We could also try using // `form.getElementsByName`, but that will only return direct children // and won't include inputs that use the HTML5 `form=` attribute. Since // the input might not even be in a form, let's just use the global // `querySelectorAll` to ensure we don't miss anything. var group = queryRoot.querySelectorAll('input[name=' + JSON.stringify('' + name) + '][type="radio"]'); for (var i = 0; i < group.length; i++) { var otherNode = group[i]; if (otherNode === rootNode || otherNode.form !== rootNode.form) { continue; } // This will throw if radio buttons rendered by different copies of React // and the same name are rendered into the same form (same as #1939). // That's probably okay; we don't support it just as we don't support // mixing React with non-React. var otherID = ReactMount.getID(otherNode); !otherID ? "development" !== 'production' ? invariant(false, 'ReactDOMInput: Mixing React and non-React radio inputs with the ' + 'same `name` is not supported.') : invariant(false) : undefined; var otherInstance = instancesByReactID[otherID]; !otherInstance ? "development" !== 'production' ? invariant(false, 'ReactDOMInput: Unknown radio button ID %s.', otherID) : invariant(false) : undefined; // If this is a controlled radio button group, forcing the input that // was previously checked to update will cause it to be come re-checked // as appropriate. ReactUpdates.asap(forceUpdateIfMounted, otherInstance); } } return returnValue; }
Implements an <input> native component that allows setting these optional props: `checked`, `value`, `defaultChecked`, and `defaultValue`. If `checked` or `value` are not supplied (or null/undefined), user actions that affect the checked state or value will trigger updates to the element. If they are supplied (and not null/undefined), the rendered element will not trigger updates to the element. Instead, the props must change in order for the rendered element to be updated. The rendered element will be initialized as unchecked (or `defaultChecked`) with an empty value (or `defaultValue`). @see http://www.w3.org/TR/2012/WD-html5-20121025/the-input-element.html
_handleChange
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function checkSelectPropTypes(inst, props) { var owner = inst._currentElement._owner; LinkedValueUtils.checkPropTypes('select', props, owner); for (var i = 0; i < valuePropNames.length; i++) { var propName = valuePropNames[i]; if (props[propName] == null) { continue; } if (props.multiple) { "development" !== 'production' ? warning(Array.isArray(props[propName]), 'The `%s` prop supplied to <select> must be an array if ' + '`multiple` is true.%s', propName, getDeclarationErrorAddendum(owner)) : undefined; } else { "development" !== 'production' ? warning(!Array.isArray(props[propName]), 'The `%s` prop supplied to <select> must be a scalar ' + 'value if `multiple` is false.%s', propName, getDeclarationErrorAddendum(owner)) : undefined; } } }
Validation function for `value` and `defaultValue`. @private
checkSelectPropTypes
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function updateOptions(inst, multiple, propValue) { var selectedValue, i; var options = ReactMount.getNode(inst._rootNodeID).options; if (multiple) { selectedValue = {}; for (i = 0; i < propValue.length; i++) { selectedValue['' + propValue[i]] = true; } for (i = 0; i < options.length; i++) { var selected = selectedValue.hasOwnProperty(options[i].value); if (options[i].selected !== selected) { options[i].selected = selected; } } } else { // Do not set `select.value` as exact behavior isn't consistent across all // browsers for all cases. selectedValue = '' + propValue; for (i = 0; i < options.length; i++) { if (options[i].value === selectedValue) { options[i].selected = true; return; } } if (options.length) { options[0].selected = true; } } }
@param {ReactDOMComponent} inst @param {boolean} multiple @param {*} propValue A stringable (with `multiple`, a list of stringables). @private
updateOptions
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function _handleChange(event) { var props = this._currentElement.props; var returnValue = LinkedValueUtils.executeOnChange(props, event); this._wrapperState.pendingUpdate = true; ReactUpdates.asap(updateOptionsIfPendingUpdateAndMounted, this); return returnValue; }
Implements a <select> native component that allows optionally setting the props `value` and `defaultValue`. If `multiple` is false, the prop must be a stringable. If `multiple` is true, the prop must be an array of stringables. If `value` is not supplied (or null/undefined), user actions that change the selected option will trigger updates to the rendered options. If it is supplied (and not null/undefined), the rendered options will not update in response to user actions. Instead, the `value` prop must change in order for the rendered options to update. If `defaultValue` is provided, any options with the supplied values will be selected.
_handleChange
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function isCollapsed(anchorNode, anchorOffset, focusNode, focusOffset) { return anchorNode === focusNode && anchorOffset === focusOffset; }
While `isCollapsed` is available on the Selection object and `collapsed` is available on the Range object, IE11 sometimes gets them wrong. If the anchor/focus nodes and offsets are the same, the range is collapsed.
isCollapsed
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function getIEOffsets(node) { var selection = document.selection; var selectedRange = selection.createRange(); var selectedLength = selectedRange.text.length; // Duplicate selection so we can move range without breaking user selection. var fromStart = selectedRange.duplicate(); fromStart.moveToElementText(node); fromStart.setEndPoint('EndToStart', selectedRange); var startOffset = fromStart.text.length; var endOffset = startOffset + selectedLength; return { start: startOffset, end: endOffset }; }
Get the appropriate anchor and focus node/offset pairs for IE. The catch here is that IE's selection API doesn't provide information about whether the selection is forward or backward, so we have to behave as though it's always forward. IE text differs from modern selection in that it behaves as though block elements end with a new line. This means character offsets will differ between the two APIs. @param {DOMElement} node @return {object}
getIEOffsets
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function setIEOffsets(node, offsets) { var range = document.selection.createRange().duplicate(); var start, end; if (typeof offsets.end === 'undefined') { start = offsets.start; end = start; } else if (offsets.start > offsets.end) { start = offsets.end; end = offsets.start; } else { start = offsets.start; end = offsets.end; } range.moveToElementText(node); range.moveStart('character', start); range.setEndPoint('EndToStart', range); range.moveEnd('character', end - start); range.select(); }
@param {DOMElement|DOMTextNode} node @param {object} offsets
setIEOffsets
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function setModernOffsets(node, offsets) { if (!window.getSelection) { return; } var selection = window.getSelection(); var length = node[getTextContentAccessor()].length; var start = Math.min(offsets.start, length); var end = typeof offsets.end === 'undefined' ? start : Math.min(offsets.end, length); // IE 11 uses modern selection, but doesn't support the extend method. // Flip backward selections, so we can set with a single range. if (!selection.extend && start > end) { var temp = end; end = start; start = temp; } var startMarker = getNodeForCharacterOffset(node, start); var endMarker = getNodeForCharacterOffset(node, end); if (startMarker && endMarker) { var range = document.createRange(); range.setStart(startMarker.node, startMarker.offset); selection.removeAllRanges(); if (start > end) { selection.addRange(range); selection.extend(endMarker.node, endMarker.offset); } else { range.setEnd(endMarker.node, endMarker.offset); selection.addRange(range); } } }
In modern non-IE browsers, we can support both forward and backward selections. Note: IE10+ supports the Selection object, but it does not support the `extend` method, which means that even in modern IE, it's not possible to programatically create a backward selection. Thus, for all IE versions, we use the old IE API to create our selections. @param {DOMElement|DOMTextNode} node @param {object} offsets
setModernOffsets
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
ReactDOMTextComponent = function (props) { // This constructor and its argument is currently used by mocks. }
Text nodes violate a couple assumptions that React makes about components: - When mounting text into the DOM, adjacent text nodes are merged. - Text nodes cannot be assigned a React root ID. This component is used to wrap strings in elements so that they can undergo the same reconciliation that is applied to elements. TODO: Investigate representing React components in the DOM with text nodes. @class ReactDOMTextComponent @extends ReactComponent @internal
ReactDOMTextComponent
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function _handleChange(event) { var props = this._currentElement.props; var returnValue = LinkedValueUtils.executeOnChange(props, event); ReactUpdates.asap(forceUpdateIfMounted, this); return returnValue; }
Implements a <textarea> native component that allows setting `value`, and `defaultValue`. This differs from the traditional DOM API because value is usually set as PCDATA children. If `value` is not supplied (or null/undefined), user actions that affect the value will trigger updates to the element. If `value` is supplied (and not null/undefined), the rendered element will not trigger updates to the element. Instead, the `value` prop must change in order for the rendered element to be updated. The rendered element will be initialized with an empty value, the prop `defaultValue` if specified, or the children content (deprecated).
_handleChange
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
ReactElement = function (type, key, ref, self, source, owner, props) { var element = { // This tag allow us to uniquely identify this as a React Element $$typeof: REACT_ELEMENT_TYPE, // Built-in properties that belong on the element type: type, key: key, ref: ref, props: props, // Record the component responsible for creating this element. _owner: owner }; if ("development" !== 'production') { // The validation flag is currently mutative. We put it on // an external backing store so that we can freeze the whole object. // This can be replaced with a WeakMap once they are implemented in // commonly used development environments. element._store = {}; // To make comparing ReactElements easier for testing purposes, we make // the validation flag non-enumerable (where possible, which should // include every environment we run tests in), so the test framework // ignores it. if (canDefineProperty) { Object.defineProperty(element._store, 'validated', { configurable: false, enumerable: false, writable: true, value: false }); // self and source are DEV only properties. Object.defineProperty(element, '_self', { configurable: false, enumerable: false, writable: false, value: self }); // Two elements created in two different places should be considered // equal for testing purposes and therefore we hide it from enumeration. Object.defineProperty(element, '_source', { configurable: false, enumerable: false, writable: false, value: source }); } else { element._store.validated = false; element._self = self; element._source = source; } Object.freeze(element.props); Object.freeze(element); } return element; }
Base constructor for all React elements. This is only used to make this work with a dynamic instanceof check. Nothing should live on this prototype. @param {*} type @param {*} key @param {string|object} ref @param {*} self A *temporary* helper to detect places where `this` is different from the `owner` when React.createElement is called, so that we can warn. We want to get rid of owner and replace string `ref`s with arrow functions, and as long as `this` and owner are the same, there will be no change in behavior. @param {*} source An annotation object (added by a transpiler or otherwise) indicating filename, line number, and/or other information. @param {*} owner @param {*} props @internal
ReactElement
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function getDeclarationErrorAddendum() { if (ReactCurrentOwner.current) { var name = ReactCurrentOwner.current.getName(); if (name) { return ' Check the render method of `' + name + '`.'; } } return ''; }
ReactElementValidator provides a wrapper around a element factory which validates the props passed to the element. This is intended to be used only in DEV and could be replaced by a static type checker for languages that support it.
getDeclarationErrorAddendum
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function validateExplicitKey(element, parentType) { if (!element._store || element._store.validated || element.key != null) { return; } element._store.validated = true; var addenda = getAddendaForKeyUse('uniqueKey', element, parentType); if (addenda === null) { // we already showed the warning return; } "development" !== 'production' ? warning(false, 'Each child in an array or iterator should have a unique "key" prop.' + '%s%s%s', addenda.parentOrOwner || '', addenda.childOwner || '', addenda.url || '') : undefined; }
Warn if the element doesn't have an explicit key assigned to it. This element is in an array. The array could grow and shrink or be reordered. All children that haven't already been validated are required to have a "key" property assigned to it. @internal @param {ReactElement} element Element that requires a key. @param {*} parentType element's parent's type.
validateExplicitKey
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function getAddendaForKeyUse(messageType, element, parentType) { var addendum = getDeclarationErrorAddendum(); if (!addendum) { var parentName = typeof parentType === 'string' ? parentType : parentType.displayName || parentType.name; if (parentName) { addendum = ' Check the top-level render call using <' + parentName + '>.'; } } var memoizer = ownerHasKeyUseWarning[messageType] || (ownerHasKeyUseWarning[messageType] = {}); if (memoizer[addendum]) { return null; } memoizer[addendum] = true; var addenda = { parentOrOwner: addendum, url: ' See https://fb.me/react-warning-keys for more information.', childOwner: null }; // Usually the current owner is the offender, but if it accepts children as a // property, it may be the creator of the child that's responsible for // assigning it a key. if (element && element._owner && element._owner !== ReactCurrentOwner.current) { // Give the component that originally created this child. addenda.childOwner = ' It was passed a child from ' + element._owner.getName() + '.'; } return addenda; }
Shared warning and monitoring code for the key warnings. @internal @param {string} messageType A key used for de-duping warnings. @param {ReactElement} element Component that requires a key. @param {*} parentType element's parent's type. @returns {?object} A set of addenda to use in the warning message, or null if the warning has already been shown before (and shouldn't be shown again).
getAddendaForKeyUse
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function validateChildKeys(node, parentType) { if (typeof node !== 'object') { return; } if (Array.isArray(node)) { for (var i = 0; i < node.length; i++) { var child = node[i]; if (ReactElement.isValidElement(child)) { validateExplicitKey(child, parentType); } } } else if (ReactElement.isValidElement(node)) { // This element was passed in a valid location. if (node._store) { node._store.validated = true; } } else if (node) { var iteratorFn = getIteratorFn(node); // Entry iterators provide implicit keys. if (iteratorFn) { if (iteratorFn !== node.entries) { var iterator = iteratorFn.call(node); var step; while (!(step = iterator.next()).done) { if (ReactElement.isValidElement(step.value)) { validateExplicitKey(step.value, parentType); } } } } } }
Ensure that every element either is passed in a static location, in an array with an explicit keys property defined, or in an object literal with valid key property. @internal @param {ReactNode} node Statically passed child of any type. @param {*} parentType node's parent's type.
validateChildKeys
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function checkPropTypes(componentName, propTypes, props, location) { for (var propName in propTypes) { if (propTypes.hasOwnProperty(propName)) { var error; // Prop type validation may throw. In case they do, we don't want to // fail the render phase where it didn't fail before. So we log it. // After these have been cleaned up, we'll let them throw. try { // This is intentionally an invariant that gets caught. It's the same // behavior as without this statement except with a better message. !(typeof propTypes[propName] === 'function') ? "development" !== 'production' ? invariant(false, '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', componentName || 'React class', ReactPropTypeLocationNames[location], propName) : invariant(false) : undefined; error = propTypes[propName](props, propName, componentName, location); } catch (ex) { error = ex; } "development" !== 'production' ? warning(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', ReactPropTypeLocationNames[location], propName, typeof error) : undefined; if (error instanceof Error && !(error.message in loggedTypeFailures)) { // Only monitor this failure once because there tends to be a lot of the // same error. loggedTypeFailures[error.message] = true; var addendum = getDeclarationErrorAddendum(); "development" !== 'production' ? warning(false, 'Failed propType: %s%s', error.message, addendum) : undefined; } } } }
Assert that the props are valid @param {string} componentName Name of the component for error messages. @param {object} propTypes Map of prop name to a ReactPropType @param {object} props @param {string} location e.g. "prop", "context", "child context" @private
checkPropTypes
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function validatePropTypes(element) { var componentClass = element.type; if (typeof componentClass !== 'function') { return; } var name = componentClass.displayName || componentClass.name; if (componentClass.propTypes) { checkPropTypes(name, componentClass.propTypes, element.props, ReactPropTypeLocations.prop); } if (typeof componentClass.getDefaultProps === 'function') { "development" !== 'production' ? warning(componentClass.getDefaultProps.isReactClassApproved, 'getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.') : undefined; } }
Given an element, validate that its props follow the propTypes definition, provided by the type. @param {ReactElement} element
validatePropTypes
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function isNullComponentID(id) { return !!nullComponentIDsRegistry[id]; }
@param {string} id Component's `_rootNodeID`. @return {boolean} True if the component is rendered to null.
isNullComponentID
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function registerNullComponentID(id) { nullComponentIDsRegistry[id] = true; }
Mark the component as having rendered to null. @param {string} id Component's `_rootNodeID`.
registerNullComponentID
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function deregisterNullComponentID(id) { delete nullComponentIDsRegistry[id]; }
Unmark the component as having rendered to null: it renders to something now. @param {string} id Component's `_rootNodeID`.
deregisterNullComponentID
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function invokeGuardedCallback(name, func, a, b) { try { return func(a, b); } catch (x) { if (caughtError === null) { caughtError = x; } return undefined; } }
Call a function while guarding against errors that happens within it. @param {?String} name of the guard to use for logging or debugging @param {Function} func The function to invoke @param {*} a First argument @param {*} b Second argument
invokeGuardedCallback
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function findParent(node) { // TODO: It may be a good idea to cache this to prevent unnecessary DOM // traversal, but caching is difficult to do correctly without using a // mutation observer to listen for all DOM changes. var nodeID = ReactMount.getID(node); var rootID = ReactInstanceHandles.getReactRootIDFromNodeID(nodeID); var container = ReactMount.findReactContainerForID(rootID); var parent = ReactMount.getFirstReactDOM(container); return parent; }
Finds the parent React component of `node`. @param {*} node @return {?DOMEventTarget} Parent container, or `null` if the specified node is not nested.
findParent
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function TopLevelCallbackBookKeeping(topLevelType, nativeEvent) { this.topLevelType = topLevelType; this.nativeEvent = nativeEvent; this.ancestors = []; }
Finds the parent React component of `node`. @param {*} node @return {?DOMEventTarget} Parent container, or `null` if the specified node is not nested.
TopLevelCallbackBookKeeping
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function handleTopLevelImpl(bookKeeping) { // TODO: Re-enable event.path handling // // if (bookKeeping.nativeEvent.path && bookKeeping.nativeEvent.path.length > 1) { // // New browsers have a path attribute on native events // handleTopLevelWithPath(bookKeeping); // } else { // // Legacy browsers don't have a path attribute on native events // handleTopLevelWithoutPath(bookKeeping); // } void handleTopLevelWithPath; // temporarily unused handleTopLevelWithoutPath(bookKeeping); }
Finds the parent React component of `node`. @param {*} node @return {?DOMEventTarget} Parent container, or `null` if the specified node is not nested.
handleTopLevelImpl
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function handleTopLevelWithoutPath(bookKeeping) { var topLevelTarget = ReactMount.getFirstReactDOM(getEventTarget(bookKeeping.nativeEvent)) || window; // Loop through the hierarchy, in case there's any nested components. // It's important that we build the array of ancestors before calling any // event handlers, because event handlers can modify the DOM, leading to // inconsistencies with ReactMount's node cache. See #1105. var ancestor = topLevelTarget; while (ancestor) { bookKeeping.ancestors.push(ancestor); ancestor = findParent(ancestor); } for (var i = 0; i < bookKeeping.ancestors.length; i++) { topLevelTarget = bookKeeping.ancestors[i]; var topLevelTargetID = ReactMount.getID(topLevelTarget) || ''; ReactEventListener._handleTopLevel(bookKeeping.topLevelType, topLevelTarget, topLevelTargetID, bookKeeping.nativeEvent, getEventTarget(bookKeeping.nativeEvent)); } }
Finds the parent React component of `node`. @param {*} node @return {?DOMEventTarget} Parent container, or `null` if the specified node is not nested.
handleTopLevelWithoutPath
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function handleTopLevelWithPath(bookKeeping) { var path = bookKeeping.nativeEvent.path; var currentNativeTarget = path[0]; var eventsFired = 0; for (var i = 0; i < path.length; i++) { var currentPathElement = path[i]; if (currentPathElement.nodeType === DOCUMENT_FRAGMENT_NODE_TYPE) { currentNativeTarget = path[i + 1]; } // TODO: slow var reactParent = ReactMount.getFirstReactDOM(currentPathElement); if (reactParent === currentPathElement) { var currentPathElementID = ReactMount.getID(currentPathElement); var newRootID = ReactInstanceHandles.getReactRootIDFromNodeID(currentPathElementID); bookKeeping.ancestors.push(currentPathElement); var topLevelTargetID = ReactMount.getID(currentPathElement) || ''; eventsFired++; ReactEventListener._handleTopLevel(bookKeeping.topLevelType, currentPathElement, topLevelTargetID, bookKeeping.nativeEvent, currentNativeTarget); // Jump to the root of this React render tree while (currentPathElementID !== newRootID) { i++; currentPathElement = path[i]; currentPathElementID = ReactMount.getID(currentPathElement); } } } if (eventsFired === 0) { ReactEventListener._handleTopLevel(bookKeeping.topLevelType, window, '', bookKeeping.nativeEvent, getEventTarget(bookKeeping.nativeEvent)); } }
Finds the parent React component of `node`. @param {*} node @return {?DOMEventTarget} Parent container, or `null` if the specified node is not nested.
handleTopLevelWithPath
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function scrollValueMonitor(cb) { var scrollPosition = getUnboundedScrollPosition(window); cb(scrollPosition); }
Finds the parent React component of `node`. @param {*} node @return {?DOMEventTarget} Parent container, or `null` if the specified node is not nested.
scrollValueMonitor
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function getReactRootIDString(index) { return SEPARATOR + index.toString(36); }
Creates a DOM ID prefix to use when mounting React components. @param {number} index A unique integer @return {string} React root ID. @internal
getReactRootIDString
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function isBoundary(id, index) { return id.charAt(index) === SEPARATOR || index === id.length; }
Checks if a character in the supplied ID is a separator or the end. @param {string} id A React DOM ID. @param {number} index Index of the character to check. @return {boolean} True if the character is a separator or end of the ID. @private
isBoundary
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function isValidID(id) { return id === '' || id.charAt(0) === SEPARATOR && id.charAt(id.length - 1) !== SEPARATOR; }
Checks if the supplied string is a valid React DOM ID. @param {string} id A React DOM ID, maybe. @return {boolean} True if the string is a valid React DOM ID. @private
isValidID
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function isAncestorIDOf(ancestorID, descendantID) { return descendantID.indexOf(ancestorID) === 0 && isBoundary(descendantID, ancestorID.length); }
Checks if the first ID is an ancestor of or equal to the second ID. @param {string} ancestorID @param {string} descendantID @return {boolean} True if `ancestorID` is an ancestor of `descendantID`. @internal
isAncestorIDOf
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function getParentID(id) { return id ? id.substr(0, id.lastIndexOf(SEPARATOR)) : ''; }
Gets the parent ID of the supplied React DOM ID, `id`. @param {string} id ID of a component. @return {string} ID of the parent, or an empty string. @private
getParentID
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function getNextDescendantID(ancestorID, destinationID) { !(isValidID(ancestorID) && isValidID(destinationID)) ? "development" !== 'production' ? invariant(false, 'getNextDescendantID(%s, %s): Received an invalid React DOM ID.', ancestorID, destinationID) : invariant(false) : undefined; !isAncestorIDOf(ancestorID, destinationID) ? "development" !== 'production' ? invariant(false, 'getNextDescendantID(...): React has made an invalid assumption about ' + 'the DOM hierarchy. Expected `%s` to be an ancestor of `%s`.', ancestorID, destinationID) : invariant(false) : undefined; if (ancestorID === destinationID) { return ancestorID; } // Skip over the ancestor and the immediate separator. Traverse until we hit // another separator or we reach the end of `destinationID`. var start = ancestorID.length + SEPARATOR_LENGTH; var i; for (i = start; i < destinationID.length; i++) { if (isBoundary(destinationID, i)) { break; } } return destinationID.substr(0, i); }
Gets the next DOM ID on the tree path from the supplied `ancestorID` to the supplied `destinationID`. If they are equal, the ID is returned. @param {string} ancestorID ID of an ancestor node of `destinationID`. @param {string} destinationID ID of the destination node. @return {string} Next ID on the path from `ancestorID` to `destinationID`. @private
getNextDescendantID
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function getFirstCommonAncestorID(oneID, twoID) { var minLength = Math.min(oneID.length, twoID.length); if (minLength === 0) { return ''; } var lastCommonMarkerIndex = 0; // Use `<=` to traverse until the "EOL" of the shorter string. for (var i = 0; i <= minLength; i++) { if (isBoundary(oneID, i) && isBoundary(twoID, i)) { lastCommonMarkerIndex = i; } else if (oneID.charAt(i) !== twoID.charAt(i)) { break; } } var longestCommonID = oneID.substr(0, lastCommonMarkerIndex); !isValidID(longestCommonID) ? "development" !== 'production' ? invariant(false, 'getFirstCommonAncestorID(%s, %s): Expected a valid React DOM ID: %s', oneID, twoID, longestCommonID) : invariant(false) : undefined; return longestCommonID; }
Gets the nearest common ancestor ID of two IDs. Using this ID scheme, the nearest common ancestor ID is the longest common prefix of the two IDs that immediately preceded a "marker" in both strings. @param {string} oneID @param {string} twoID @return {string} Nearest common ancestor ID, or the empty string if none. @private
getFirstCommonAncestorID
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function traverseParentPath(start, stop, cb, arg, skipFirst, skipLast) { start = start || ''; stop = stop || ''; !(start !== stop) ? "development" !== 'production' ? invariant(false, 'traverseParentPath(...): Cannot traverse from and to the same ID, `%s`.', start) : invariant(false) : undefined; var traverseUp = isAncestorIDOf(stop, start); !(traverseUp || isAncestorIDOf(start, stop)) ? "development" !== 'production' ? invariant(false, 'traverseParentPath(%s, %s, ...): Cannot traverse from two IDs that do ' + 'not have a parent path.', start, stop) : invariant(false) : undefined; // Traverse from `start` to `stop` one depth at a time. var depth = 0; var traverse = traverseUp ? getParentID : getNextDescendantID; for (var id = start;; /* until break */id = traverse(id, stop)) { var ret; if ((!skipFirst || id !== start) && (!skipLast || id !== stop)) { ret = cb(id, traverseUp, arg); } if (ret === false || id === stop) { // Only break //after// visiting `stop`. break; } !(depth++ < MAX_TREE_DEPTH) ? "development" !== 'production' ? invariant(false, 'traverseParentPath(%s, %s, ...): Detected an infinite loop while ' + 'traversing the React DOM ID tree. This may be due to malformed IDs: %s', start, stop, id) : invariant(false) : undefined; } }
Traverses the parent path between two IDs (either up or down). The IDs must not be the same, and there must exist a parent path between them. If the callback returns `false`, traversal is stopped. @param {?string} start ID at which to start traversal. @param {?string} stop ID at which to end traversal. @param {function} cb Callback to invoke each ID with. @param {*} arg Argument to invoke the callback with. @param {?boolean} skipFirst Whether or not to skip the first node. @param {?boolean} skipLast Whether or not to skip the last node. @private
traverseParentPath
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function firstDifferenceIndex(string1, string2) { var minLen = Math.min(string1.length, string2.length); for (var i = 0; i < minLen; i++) { if (string1.charAt(i) !== string2.charAt(i)) { return i; } } return string1.length === string2.length ? -1 : minLen; }
Finds the index of the first character that's not common between the two given strings. @return {number} the index of the character where the strings diverge
firstDifferenceIndex
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function getReactRootElementInContainer(container) { if (!container) { return null; } if (container.nodeType === DOC_NODE_TYPE) { return container.documentElement; } else { return container.firstChild; } }
@param {DOMElement|DOMDocument} container DOM element that may contain a React component @return {?*} DOM element that may have the reactRoot ID, or null.
getReactRootElementInContainer
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function getReactRootID(container) { var rootElement = getReactRootElementInContainer(container); return rootElement && ReactMount.getID(rootElement); }
@param {DOMElement} container DOM element that may contain a React component. @return {?string} A "reactRoot" ID, if a React component is rendered.
getReactRootID
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function getID(node) { var id = internalGetID(node); if (id) { if (nodeCache.hasOwnProperty(id)) { var cached = nodeCache[id]; if (cached !== node) { !!isValid(cached, id) ? "development" !== 'production' ? invariant(false, 'ReactMount: Two valid but unequal nodes with the same `%s`: %s', ATTR_NAME, id) : invariant(false) : undefined; nodeCache[id] = node; } } else { nodeCache[id] = node; } } return id; }
Accessing node[ATTR_NAME] or calling getAttribute(ATTR_NAME) on a form element can return its control whose name or ID equals ATTR_NAME. All DOM nodes support `getAttributeNode` but this can also get called on other objects so just return '' if we're given something other than a DOM node (such as window). @param {?DOMElement|DOMWindow|DOMDocument|DOMTextNode} node DOM node. @return {string} ID of the supplied `domNode`.
getID
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function internalGetID(node) { // If node is something like a window, document, or text node, none of // which support attributes or a .getAttribute method, gracefully return // the empty string, as if the attribute were missing. return node && node.getAttribute && node.getAttribute(ATTR_NAME) || ''; }
Accessing node[ATTR_NAME] or calling getAttribute(ATTR_NAME) on a form element can return its control whose name or ID equals ATTR_NAME. All DOM nodes support `getAttributeNode` but this can also get called on other objects so just return '' if we're given something other than a DOM node (such as window). @param {?DOMElement|DOMWindow|DOMDocument|DOMTextNode} node DOM node. @return {string} ID of the supplied `domNode`.
internalGetID
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function setID(node, id) { var oldID = internalGetID(node); if (oldID !== id) { delete nodeCache[oldID]; } node.setAttribute(ATTR_NAME, id); nodeCache[id] = node; }
Sets the React-specific ID of the given node. @param {DOMElement} node The DOM node whose ID will be set. @param {string} id The value of the ID attribute.
setID
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function getNode(id) { if (!nodeCache.hasOwnProperty(id) || !isValid(nodeCache[id], id)) { nodeCache[id] = ReactMount.findReactNodeByID(id); } return nodeCache[id]; }
Finds the node with the supplied React-generated DOM ID. @param {string} id A React-generated DOM ID. @return {DOMElement} DOM node with the suppled `id`. @internal
getNode
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function getNodeFromInstance(instance) { var id = ReactInstanceMap.get(instance)._rootNodeID; if (ReactEmptyComponentRegistry.isNullComponentID(id)) { return null; } if (!nodeCache.hasOwnProperty(id) || !isValid(nodeCache[id], id)) { nodeCache[id] = ReactMount.findReactNodeByID(id); } return nodeCache[id]; }
Finds the node with the supplied public React instance. @param {*} instance A public React instance. @return {?DOMElement} DOM node with the suppled `id`. @internal
getNodeFromInstance
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function isValid(node, id) { if (node) { !(internalGetID(node) === id) ? "development" !== 'production' ? invariant(false, 'ReactMount: Unexpected modification of `%s`', ATTR_NAME) : invariant(false) : undefined; var container = ReactMount.findReactContainerForID(id); if (container && containsNode(container, node)) { return true; } } return false; }
A node is "valid" if it is contained by a currently mounted container. This means that the node does not have to be contained by a document in order to be considered valid. @param {?DOMElement} node The candidate DOM node. @param {string} id The expected ID of the node. @return {boolean} Whether the node is contained by a mounted container.
isValid
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function purgeID(id) { delete nodeCache[id]; }
Causes the cache to forget about one React-specific ID. @param {string} id The ID to forget.
purgeID
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function findDeepestCachedAncestorImpl(ancestorID) { var ancestor = nodeCache[ancestorID]; if (ancestor && isValid(ancestor, ancestorID)) { deepestNodeSoFar = ancestor; } else { // This node isn't populated in the cache, so presumably none of its // descendants are. Break out of the loop. return false; } }
Causes the cache to forget about one React-specific ID. @param {string} id The ID to forget.
findDeepestCachedAncestorImpl
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function findDeepestCachedAncestor(targetID) { deepestNodeSoFar = null; ReactInstanceHandles.traverseAncestors(targetID, findDeepestCachedAncestorImpl); var foundNode = deepestNodeSoFar; deepestNodeSoFar = null; return foundNode; }
Return the deepest cached node whose ID is a prefix of `targetID`.
findDeepestCachedAncestor
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function mountComponentIntoNode(componentInstance, rootID, container, transaction, shouldReuseMarkup, context) { if (ReactDOMFeatureFlags.useCreateElement) { context = assign({}, context); if (container.nodeType === DOC_NODE_TYPE) { context[ownerDocumentContextKey] = container; } else { context[ownerDocumentContextKey] = container.ownerDocument; } } if ("development" !== 'production') { if (context === emptyObject) { context = {}; } var tag = container.nodeName.toLowerCase(); context[validateDOMNesting.ancestorInfoContextKey] = validateDOMNesting.updatedAncestorInfo(null, tag, null); } var markup = ReactReconciler.mountComponent(componentInstance, rootID, transaction, context); componentInstance._renderedComponent._topLevelWrapper = componentInstance; ReactMount._mountImageIntoNode(markup, container, shouldReuseMarkup, transaction); }
Mounts this component and inserts it into the DOM. @param {ReactComponent} componentInstance The instance to mount. @param {string} rootID DOM ID of the root node. @param {DOMElement} container DOM element to mount into. @param {ReactReconcileTransaction} transaction @param {boolean} shouldReuseMarkup If true, do not insert markup
mountComponentIntoNode
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function batchedMountComponentIntoNode(componentInstance, rootID, container, shouldReuseMarkup, context) { var transaction = ReactUpdates.ReactReconcileTransaction.getPooled( /* forceHTML */shouldReuseMarkup); transaction.perform(mountComponentIntoNode, null, componentInstance, rootID, container, transaction, shouldReuseMarkup, context); ReactUpdates.ReactReconcileTransaction.release(transaction); }
Batched mount. @param {ReactComponent} componentInstance The instance to mount. @param {string} rootID DOM ID of the root node. @param {DOMElement} container DOM element to mount into. @param {boolean} shouldReuseMarkup If true, do not insert markup
batchedMountComponentIntoNode
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function unmountComponentFromNode(instance, container) { ReactReconciler.unmountComponent(instance); if (container.nodeType === DOC_NODE_TYPE) { container = container.documentElement; } // http://jsperf.com/emptying-a-node while (container.lastChild) { container.removeChild(container.lastChild); } }
Unmounts a component and removes it from the DOM. @param {ReactComponent} instance React component instance. @param {DOMElement} container DOM element to unmount from. @final @internal @see {ReactMount.unmountComponentAtNode}
unmountComponentFromNode
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function hasNonRootReactChild(node) { var reactRootID = getReactRootID(node); return reactRootID ? reactRootID !== ReactInstanceHandles.getReactRootIDFromNodeID(reactRootID) : false; }
True if the supplied DOM node has a direct React-rendered child that is not a React root element. Useful for warning in `render`, `unmountComponentAtNode`, etc. @param {?DOMElement} node The candidate DOM node. @return {boolean} True if the DOM element contains a direct child that was rendered by React but is not a root element. @internal
hasNonRootReactChild
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function findFirstReactDOMImpl(node) { // This node might be from another React instance, so we make sure not to // examine the node cache here for (; node && node.parentNode !== node; node = node.parentNode) { if (node.nodeType !== 1) { // Not a DOMElement, therefore not a React component continue; } var nodeID = internalGetID(node); if (!nodeID) { continue; } var reactRootID = ReactInstanceHandles.getReactRootIDFromNodeID(nodeID); // If containersByReactRootID contains the container we find by crawling up // the tree, we know that this instance of React rendered the node. // nb. isValid's strategy (with containsNode) does not work because render // trees may be nested and we don't want a false positive in that case. var current = node; var lastID; do { lastID = internalGetID(current); current = current.parentNode; if (current == null) { // The passed-in node has been detached from the container it was // originally rendered into. return null; } } while (lastID !== reactRootID); if (current === containersByReactRootID[reactRootID]) { return node; } } return null; }
Returns the first (deepest) ancestor of a node which is rendered by this copy of React.
findFirstReactDOMImpl
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function enqueueInsertMarkup(parentID, markup, toIndex) { // NOTE: Null values reduce hidden classes. updateQueue.push({ parentID: parentID, parentNode: null, type: ReactMultiChildUpdateTypes.INSERT_MARKUP, markupIndex: markupQueue.push(markup) - 1, content: null, fromIndex: null, toIndex: toIndex }); }
Enqueues markup to be rendered and inserted at a supplied index. @param {string} parentID ID of the parent component. @param {string} markup Markup that renders into an element. @param {number} toIndex Destination index. @private
enqueueInsertMarkup
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function enqueueMove(parentID, fromIndex, toIndex) { // NOTE: Null values reduce hidden classes. updateQueue.push({ parentID: parentID, parentNode: null, type: ReactMultiChildUpdateTypes.MOVE_EXISTING, markupIndex: null, content: null, fromIndex: fromIndex, toIndex: toIndex }); }
Enqueues moving an existing element to another index. @param {string} parentID ID of the parent component. @param {number} fromIndex Source index of the existing element. @param {number} toIndex Destination index of the element. @private
enqueueMove
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function enqueueRemove(parentID, fromIndex) { // NOTE: Null values reduce hidden classes. updateQueue.push({ parentID: parentID, parentNode: null, type: ReactMultiChildUpdateTypes.REMOVE_NODE, markupIndex: null, content: null, fromIndex: fromIndex, toIndex: null }); }
Enqueues removing an element at an index. @param {string} parentID ID of the parent component. @param {number} fromIndex Index of the element to remove. @private
enqueueRemove
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function enqueueSetMarkup(parentID, markup) { // NOTE: Null values reduce hidden classes. updateQueue.push({ parentID: parentID, parentNode: null, type: ReactMultiChildUpdateTypes.SET_MARKUP, markupIndex: null, content: markup, fromIndex: null, toIndex: null }); }
Enqueues setting the markup of a node. @param {string} parentID ID of the parent component. @param {string} markup Markup that renders into an element. @private
enqueueSetMarkup
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function enqueueTextContent(parentID, textContent) { // NOTE: Null values reduce hidden classes. updateQueue.push({ parentID: parentID, parentNode: null, type: ReactMultiChildUpdateTypes.TEXT_CONTENT, markupIndex: null, content: textContent, fromIndex: null, toIndex: null }); }
Enqueues setting the text content. @param {string} parentID ID of the parent component. @param {string} textContent Text content to set. @private
enqueueTextContent
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function getComponentClassForElement(element) { if (typeof element.type === 'function') { return element.type; } var tag = element.type; var componentClass = tagToComponentClass[tag]; if (componentClass == null) { tagToComponentClass[tag] = componentClass = autoGenerateWrapperClass(tag); } return componentClass; }
Get a composite component wrapper class for a specific tag. @param {ReactElement} element The tag for which to get the class. @return {function} The React class constructor function.
getComponentClassForElement
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function createInternalComponent(element) { !genericComponentClass ? "development" !== 'production' ? invariant(false, 'There is no registered component for the tag %s', element.type) : invariant(false) : undefined; return new genericComponentClass(element.type, element.props); }
Get a native internal component class for a specific tag. @param {ReactElement} element The element to create. @return {function} The internal class constructor function.
createInternalComponent
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
wrapper = function () { if (ReactPerf.enableMeasure) { if (!measuredFunc) { measuredFunc = ReactPerf.storedMeasure(objName, fnName, func); } return measuredFunc.apply(this, arguments); } return func.apply(this, arguments); }
Use this to wrap methods you want to measure. Zero overhead in production. @param {string} objName @param {string} fnName @param {function} func @return {function}
wrapper
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function _noMeasure(objName, fnName, func) { return func; }
Simply passes through the measured function, without measuring it. @param {string} objName @param {string} fnName @param {function} func @return {function}
_noMeasure
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function createChainableTypeChecker(validate) { function checkType(isRequired, props, propName, componentName, location, propFullName) { componentName = componentName || ANONYMOUS; propFullName = propFullName || propName; if (props[propName] == null) { var locationName = ReactPropTypeLocationNames[location]; if (isRequired) { return new Error('Required ' + locationName + ' `' + propFullName + '` was not specified in ' + ('`' + componentName + '`.')); } return null; } else { return validate(props, propName, componentName, location, propFullName); } } var chainedCheckType = checkType.bind(null, false); chainedCheckType.isRequired = checkType.bind(null, true); return chainedCheckType; }
Collection of methods that allow declaration and validation of props that are supplied to React components. Example usage: var Props = require('ReactPropTypes'); var MyArticle = React.createClass({ propTypes: { // An optional string prop named "description". description: Props.string, // A required enum prop named "category". category: Props.oneOf(['News','Photos']).isRequired, // A prop named "dialog" that requires an instance of Dialog. dialog: Props.instanceOf(Dialog).isRequired }, render: function() { ... } }); A more formal specification of how these methods are used: type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) decl := ReactPropTypes.{type}(.isRequired)? Each and every declaration produces a function with the same signature. This allows the creation of custom validation functions. For example: var MyLink = React.createClass({ propTypes: { // An optional string or URI prop named "href". href: function(props, propName, componentName) { var propValue = props[propName]; if (propValue != null && typeof propValue !== 'string' && !(propValue instanceof URI)) { return new Error( 'Expected a string or an URI for ' + propName + ' in ' + componentName ); } } }, render: function() {...} }); @internal
createChainableTypeChecker
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function checkType(isRequired, props, propName, componentName, location, propFullName) { componentName = componentName || ANONYMOUS; propFullName = propFullName || propName; if (props[propName] == null) { var locationName = ReactPropTypeLocationNames[location]; if (isRequired) { return new Error('Required ' + locationName + ' `' + propFullName + '` was not specified in ' + ('`' + componentName + '`.')); } return null; } else { return validate(props, propName, componentName, location, propFullName); } }
Collection of methods that allow declaration and validation of props that are supplied to React components. Example usage: var Props = require('ReactPropTypes'); var MyArticle = React.createClass({ propTypes: { // An optional string prop named "description". description: Props.string, // A required enum prop named "category". category: Props.oneOf(['News','Photos']).isRequired, // A prop named "dialog" that requires an instance of Dialog. dialog: Props.instanceOf(Dialog).isRequired }, render: function() { ... } }); A more formal specification of how these methods are used: type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) decl := ReactPropTypes.{type}(.isRequired)? Each and every declaration produces a function with the same signature. This allows the creation of custom validation functions. For example: var MyLink = React.createClass({ propTypes: { // An optional string or URI prop named "href". href: function(props, propName, componentName) { var propValue = props[propName]; if (propValue != null && typeof propValue !== 'string' && !(propValue instanceof URI)) { return new Error( 'Expected a string or an URI for ' + propName + ' in ' + componentName ); } } }, render: function() {...} }); @internal
checkType
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function createPrimitiveTypeChecker(expectedType) { function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; var propType = getPropType(propValue); if (propType !== expectedType) { var locationName = ReactPropTypeLocationNames[location]; // `propValue` being instance of, say, date/regexp, pass the 'object' // check, but we can offer a more precise error message here rather than // 'of type `object`'. var preciseType = getPreciseType(propValue); return new Error('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.')); } return null; } return createChainableTypeChecker(validate); }
Collection of methods that allow declaration and validation of props that are supplied to React components. Example usage: var Props = require('ReactPropTypes'); var MyArticle = React.createClass({ propTypes: { // An optional string prop named "description". description: Props.string, // A required enum prop named "category". category: Props.oneOf(['News','Photos']).isRequired, // A prop named "dialog" that requires an instance of Dialog. dialog: Props.instanceOf(Dialog).isRequired }, render: function() { ... } }); A more formal specification of how these methods are used: type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) decl := ReactPropTypes.{type}(.isRequired)? Each and every declaration produces a function with the same signature. This allows the creation of custom validation functions. For example: var MyLink = React.createClass({ propTypes: { // An optional string or URI prop named "href". href: function(props, propName, componentName) { var propValue = props[propName]; if (propValue != null && typeof propValue !== 'string' && !(propValue instanceof URI)) { return new Error( 'Expected a string or an URI for ' + propName + ' in ' + componentName ); } } }, render: function() {...} }); @internal
createPrimitiveTypeChecker
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; var propType = getPropType(propValue); if (propType !== expectedType) { var locationName = ReactPropTypeLocationNames[location]; // `propValue` being instance of, say, date/regexp, pass the 'object' // check, but we can offer a more precise error message here rather than // 'of type `object`'. var preciseType = getPreciseType(propValue); return new Error('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.')); } return null; }
Collection of methods that allow declaration and validation of props that are supplied to React components. Example usage: var Props = require('ReactPropTypes'); var MyArticle = React.createClass({ propTypes: { // An optional string prop named "description". description: Props.string, // A required enum prop named "category". category: Props.oneOf(['News','Photos']).isRequired, // A prop named "dialog" that requires an instance of Dialog. dialog: Props.instanceOf(Dialog).isRequired }, render: function() { ... } }); A more formal specification of how these methods are used: type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) decl := ReactPropTypes.{type}(.isRequired)? Each and every declaration produces a function with the same signature. This allows the creation of custom validation functions. For example: var MyLink = React.createClass({ propTypes: { // An optional string or URI prop named "href". href: function(props, propName, componentName) { var propValue = props[propName]; if (propValue != null && typeof propValue !== 'string' && !(propValue instanceof URI)) { return new Error( 'Expected a string or an URI for ' + propName + ' in ' + componentName ); } } }, render: function() {...} }); @internal
validate
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function createAnyTypeChecker() { return createChainableTypeChecker(emptyFunction.thatReturns(null)); }
Collection of methods that allow declaration and validation of props that are supplied to React components. Example usage: var Props = require('ReactPropTypes'); var MyArticle = React.createClass({ propTypes: { // An optional string prop named "description". description: Props.string, // A required enum prop named "category". category: Props.oneOf(['News','Photos']).isRequired, // A prop named "dialog" that requires an instance of Dialog. dialog: Props.instanceOf(Dialog).isRequired }, render: function() { ... } }); A more formal specification of how these methods are used: type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) decl := ReactPropTypes.{type}(.isRequired)? Each and every declaration produces a function with the same signature. This allows the creation of custom validation functions. For example: var MyLink = React.createClass({ propTypes: { // An optional string or URI prop named "href". href: function(props, propName, componentName) { var propValue = props[propName]; if (propValue != null && typeof propValue !== 'string' && !(propValue instanceof URI)) { return new Error( 'Expected a string or an URI for ' + propName + ' in ' + componentName ); } } }, render: function() {...} }); @internal
createAnyTypeChecker
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function createArrayOfTypeChecker(typeChecker) { function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; if (!Array.isArray(propValue)) { var locationName = ReactPropTypeLocationNames[location]; var propType = getPropType(propValue); return new Error('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.')); } for (var i = 0; i < propValue.length; i++) { var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']'); if (error instanceof Error) { return error; } } return null; } return createChainableTypeChecker(validate); }
Collection of methods that allow declaration and validation of props that are supplied to React components. Example usage: var Props = require('ReactPropTypes'); var MyArticle = React.createClass({ propTypes: { // An optional string prop named "description". description: Props.string, // A required enum prop named "category". category: Props.oneOf(['News','Photos']).isRequired, // A prop named "dialog" that requires an instance of Dialog. dialog: Props.instanceOf(Dialog).isRequired }, render: function() { ... } }); A more formal specification of how these methods are used: type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) decl := ReactPropTypes.{type}(.isRequired)? Each and every declaration produces a function with the same signature. This allows the creation of custom validation functions. For example: var MyLink = React.createClass({ propTypes: { // An optional string or URI prop named "href". href: function(props, propName, componentName) { var propValue = props[propName]; if (propValue != null && typeof propValue !== 'string' && !(propValue instanceof URI)) { return new Error( 'Expected a string or an URI for ' + propName + ' in ' + componentName ); } } }, render: function() {...} }); @internal
createArrayOfTypeChecker
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; if (!Array.isArray(propValue)) { var locationName = ReactPropTypeLocationNames[location]; var propType = getPropType(propValue); return new Error('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.')); } for (var i = 0; i < propValue.length; i++) { var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']'); if (error instanceof Error) { return error; } } return null; }
Collection of methods that allow declaration and validation of props that are supplied to React components. Example usage: var Props = require('ReactPropTypes'); var MyArticle = React.createClass({ propTypes: { // An optional string prop named "description". description: Props.string, // A required enum prop named "category". category: Props.oneOf(['News','Photos']).isRequired, // A prop named "dialog" that requires an instance of Dialog. dialog: Props.instanceOf(Dialog).isRequired }, render: function() { ... } }); A more formal specification of how these methods are used: type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) decl := ReactPropTypes.{type}(.isRequired)? Each and every declaration produces a function with the same signature. This allows the creation of custom validation functions. For example: var MyLink = React.createClass({ propTypes: { // An optional string or URI prop named "href". href: function(props, propName, componentName) { var propValue = props[propName]; if (propValue != null && typeof propValue !== 'string' && !(propValue instanceof URI)) { return new Error( 'Expected a string or an URI for ' + propName + ' in ' + componentName ); } } }, render: function() {...} }); @internal
validate
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function createElementTypeChecker() { function validate(props, propName, componentName, location, propFullName) { if (!ReactElement.isValidElement(props[propName])) { var locationName = ReactPropTypeLocationNames[location]; return new Error('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a single ReactElement.')); } return null; } return createChainableTypeChecker(validate); }
Collection of methods that allow declaration and validation of props that are supplied to React components. Example usage: var Props = require('ReactPropTypes'); var MyArticle = React.createClass({ propTypes: { // An optional string prop named "description". description: Props.string, // A required enum prop named "category". category: Props.oneOf(['News','Photos']).isRequired, // A prop named "dialog" that requires an instance of Dialog. dialog: Props.instanceOf(Dialog).isRequired }, render: function() { ... } }); A more formal specification of how these methods are used: type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) decl := ReactPropTypes.{type}(.isRequired)? Each and every declaration produces a function with the same signature. This allows the creation of custom validation functions. For example: var MyLink = React.createClass({ propTypes: { // An optional string or URI prop named "href". href: function(props, propName, componentName) { var propValue = props[propName]; if (propValue != null && typeof propValue !== 'string' && !(propValue instanceof URI)) { return new Error( 'Expected a string or an URI for ' + propName + ' in ' + componentName ); } } }, render: function() {...} }); @internal
createElementTypeChecker
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function validate(props, propName, componentName, location, propFullName) { if (!ReactElement.isValidElement(props[propName])) { var locationName = ReactPropTypeLocationNames[location]; return new Error('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a single ReactElement.')); } return null; }
Collection of methods that allow declaration and validation of props that are supplied to React components. Example usage: var Props = require('ReactPropTypes'); var MyArticle = React.createClass({ propTypes: { // An optional string prop named "description". description: Props.string, // A required enum prop named "category". category: Props.oneOf(['News','Photos']).isRequired, // A prop named "dialog" that requires an instance of Dialog. dialog: Props.instanceOf(Dialog).isRequired }, render: function() { ... } }); A more formal specification of how these methods are used: type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) decl := ReactPropTypes.{type}(.isRequired)? Each and every declaration produces a function with the same signature. This allows the creation of custom validation functions. For example: var MyLink = React.createClass({ propTypes: { // An optional string or URI prop named "href". href: function(props, propName, componentName) { var propValue = props[propName]; if (propValue != null && typeof propValue !== 'string' && !(propValue instanceof URI)) { return new Error( 'Expected a string or an URI for ' + propName + ' in ' + componentName ); } } }, render: function() {...} }); @internal
validate
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function createInstanceTypeChecker(expectedClass) { function validate(props, propName, componentName, location, propFullName) { if (!(props[propName] instanceof expectedClass)) { var locationName = ReactPropTypeLocationNames[location]; var expectedClassName = expectedClass.name || ANONYMOUS; var actualClassName = getClassName(props[propName]); return new Error('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.')); } return null; } return createChainableTypeChecker(validate); }
Collection of methods that allow declaration and validation of props that are supplied to React components. Example usage: var Props = require('ReactPropTypes'); var MyArticle = React.createClass({ propTypes: { // An optional string prop named "description". description: Props.string, // A required enum prop named "category". category: Props.oneOf(['News','Photos']).isRequired, // A prop named "dialog" that requires an instance of Dialog. dialog: Props.instanceOf(Dialog).isRequired }, render: function() { ... } }); A more formal specification of how these methods are used: type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) decl := ReactPropTypes.{type}(.isRequired)? Each and every declaration produces a function with the same signature. This allows the creation of custom validation functions. For example: var MyLink = React.createClass({ propTypes: { // An optional string or URI prop named "href". href: function(props, propName, componentName) { var propValue = props[propName]; if (propValue != null && typeof propValue !== 'string' && !(propValue instanceof URI)) { return new Error( 'Expected a string or an URI for ' + propName + ' in ' + componentName ); } } }, render: function() {...} }); @internal
createInstanceTypeChecker
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function validate(props, propName, componentName, location, propFullName) { if (!(props[propName] instanceof expectedClass)) { var locationName = ReactPropTypeLocationNames[location]; var expectedClassName = expectedClass.name || ANONYMOUS; var actualClassName = getClassName(props[propName]); return new Error('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.')); } return null; }
Collection of methods that allow declaration and validation of props that are supplied to React components. Example usage: var Props = require('ReactPropTypes'); var MyArticle = React.createClass({ propTypes: { // An optional string prop named "description". description: Props.string, // A required enum prop named "category". category: Props.oneOf(['News','Photos']).isRequired, // A prop named "dialog" that requires an instance of Dialog. dialog: Props.instanceOf(Dialog).isRequired }, render: function() { ... } }); A more formal specification of how these methods are used: type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) decl := ReactPropTypes.{type}(.isRequired)? Each and every declaration produces a function with the same signature. This allows the creation of custom validation functions. For example: var MyLink = React.createClass({ propTypes: { // An optional string or URI prop named "href". href: function(props, propName, componentName) { var propValue = props[propName]; if (propValue != null && typeof propValue !== 'string' && !(propValue instanceof URI)) { return new Error( 'Expected a string or an URI for ' + propName + ' in ' + componentName ); } } }, render: function() {...} }); @internal
validate
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function createEnumTypeChecker(expectedValues) { if (!Array.isArray(expectedValues)) { return createChainableTypeChecker(function () { return new Error('Invalid argument supplied to oneOf, expected an instance of array.'); }); } function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; for (var i = 0; i < expectedValues.length; i++) { if (propValue === expectedValues[i]) { return null; } } var locationName = ReactPropTypeLocationNames[location]; var valuesString = JSON.stringify(expectedValues); return new Error('Invalid ' + locationName + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.')); } return createChainableTypeChecker(validate); }
Collection of methods that allow declaration and validation of props that are supplied to React components. Example usage: var Props = require('ReactPropTypes'); var MyArticle = React.createClass({ propTypes: { // An optional string prop named "description". description: Props.string, // A required enum prop named "category". category: Props.oneOf(['News','Photos']).isRequired, // A prop named "dialog" that requires an instance of Dialog. dialog: Props.instanceOf(Dialog).isRequired }, render: function() { ... } }); A more formal specification of how these methods are used: type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) decl := ReactPropTypes.{type}(.isRequired)? Each and every declaration produces a function with the same signature. This allows the creation of custom validation functions. For example: var MyLink = React.createClass({ propTypes: { // An optional string or URI prop named "href". href: function(props, propName, componentName) { var propValue = props[propName]; if (propValue != null && typeof propValue !== 'string' && !(propValue instanceof URI)) { return new Error( 'Expected a string or an URI for ' + propName + ' in ' + componentName ); } } }, render: function() {...} }); @internal
createEnumTypeChecker
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; for (var i = 0; i < expectedValues.length; i++) { if (propValue === expectedValues[i]) { return null; } } var locationName = ReactPropTypeLocationNames[location]; var valuesString = JSON.stringify(expectedValues); return new Error('Invalid ' + locationName + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.')); }
Collection of methods that allow declaration and validation of props that are supplied to React components. Example usage: var Props = require('ReactPropTypes'); var MyArticle = React.createClass({ propTypes: { // An optional string prop named "description". description: Props.string, // A required enum prop named "category". category: Props.oneOf(['News','Photos']).isRequired, // A prop named "dialog" that requires an instance of Dialog. dialog: Props.instanceOf(Dialog).isRequired }, render: function() { ... } }); A more formal specification of how these methods are used: type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) decl := ReactPropTypes.{type}(.isRequired)? Each and every declaration produces a function with the same signature. This allows the creation of custom validation functions. For example: var MyLink = React.createClass({ propTypes: { // An optional string or URI prop named "href". href: function(props, propName, componentName) { var propValue = props[propName]; if (propValue != null && typeof propValue !== 'string' && !(propValue instanceof URI)) { return new Error( 'Expected a string or an URI for ' + propName + ' in ' + componentName ); } } }, render: function() {...} }); @internal
validate
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function createObjectOfTypeChecker(typeChecker) { function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; var propType = getPropType(propValue); if (propType !== 'object') { var locationName = ReactPropTypeLocationNames[location]; return new Error('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.')); } for (var key in propValue) { if (propValue.hasOwnProperty(key)) { var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key); if (error instanceof Error) { return error; } } } return null; } return createChainableTypeChecker(validate); }
Collection of methods that allow declaration and validation of props that are supplied to React components. Example usage: var Props = require('ReactPropTypes'); var MyArticle = React.createClass({ propTypes: { // An optional string prop named "description". description: Props.string, // A required enum prop named "category". category: Props.oneOf(['News','Photos']).isRequired, // A prop named "dialog" that requires an instance of Dialog. dialog: Props.instanceOf(Dialog).isRequired }, render: function() { ... } }); A more formal specification of how these methods are used: type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) decl := ReactPropTypes.{type}(.isRequired)? Each and every declaration produces a function with the same signature. This allows the creation of custom validation functions. For example: var MyLink = React.createClass({ propTypes: { // An optional string or URI prop named "href". href: function(props, propName, componentName) { var propValue = props[propName]; if (propValue != null && typeof propValue !== 'string' && !(propValue instanceof URI)) { return new Error( 'Expected a string or an URI for ' + propName + ' in ' + componentName ); } } }, render: function() {...} }); @internal
createObjectOfTypeChecker
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; var propType = getPropType(propValue); if (propType !== 'object') { var locationName = ReactPropTypeLocationNames[location]; return new Error('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.')); } for (var key in propValue) { if (propValue.hasOwnProperty(key)) { var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key); if (error instanceof Error) { return error; } } } return null; }
Collection of methods that allow declaration and validation of props that are supplied to React components. Example usage: var Props = require('ReactPropTypes'); var MyArticle = React.createClass({ propTypes: { // An optional string prop named "description". description: Props.string, // A required enum prop named "category". category: Props.oneOf(['News','Photos']).isRequired, // A prop named "dialog" that requires an instance of Dialog. dialog: Props.instanceOf(Dialog).isRequired }, render: function() { ... } }); A more formal specification of how these methods are used: type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) decl := ReactPropTypes.{type}(.isRequired)? Each and every declaration produces a function with the same signature. This allows the creation of custom validation functions. For example: var MyLink = React.createClass({ propTypes: { // An optional string or URI prop named "href". href: function(props, propName, componentName) { var propValue = props[propName]; if (propValue != null && typeof propValue !== 'string' && !(propValue instanceof URI)) { return new Error( 'Expected a string or an URI for ' + propName + ' in ' + componentName ); } } }, render: function() {...} }); @internal
validate
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function createUnionTypeChecker(arrayOfTypeCheckers) { if (!Array.isArray(arrayOfTypeCheckers)) { return createChainableTypeChecker(function () { return new Error('Invalid argument supplied to oneOfType, expected an instance of array.'); }); } function validate(props, propName, componentName, location, propFullName) { for (var i = 0; i < arrayOfTypeCheckers.length; i++) { var checker = arrayOfTypeCheckers[i]; if (checker(props, propName, componentName, location, propFullName) == null) { return null; } } var locationName = ReactPropTypeLocationNames[location]; return new Error('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.')); } return createChainableTypeChecker(validate); }
Collection of methods that allow declaration and validation of props that are supplied to React components. Example usage: var Props = require('ReactPropTypes'); var MyArticle = React.createClass({ propTypes: { // An optional string prop named "description". description: Props.string, // A required enum prop named "category". category: Props.oneOf(['News','Photos']).isRequired, // A prop named "dialog" that requires an instance of Dialog. dialog: Props.instanceOf(Dialog).isRequired }, render: function() { ... } }); A more formal specification of how these methods are used: type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) decl := ReactPropTypes.{type}(.isRequired)? Each and every declaration produces a function with the same signature. This allows the creation of custom validation functions. For example: var MyLink = React.createClass({ propTypes: { // An optional string or URI prop named "href". href: function(props, propName, componentName) { var propValue = props[propName]; if (propValue != null && typeof propValue !== 'string' && !(propValue instanceof URI)) { return new Error( 'Expected a string or an URI for ' + propName + ' in ' + componentName ); } } }, render: function() {...} }); @internal
createUnionTypeChecker
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function validate(props, propName, componentName, location, propFullName) { for (var i = 0; i < arrayOfTypeCheckers.length; i++) { var checker = arrayOfTypeCheckers[i]; if (checker(props, propName, componentName, location, propFullName) == null) { return null; } } var locationName = ReactPropTypeLocationNames[location]; return new Error('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.')); }
Collection of methods that allow declaration and validation of props that are supplied to React components. Example usage: var Props = require('ReactPropTypes'); var MyArticle = React.createClass({ propTypes: { // An optional string prop named "description". description: Props.string, // A required enum prop named "category". category: Props.oneOf(['News','Photos']).isRequired, // A prop named "dialog" that requires an instance of Dialog. dialog: Props.instanceOf(Dialog).isRequired }, render: function() { ... } }); A more formal specification of how these methods are used: type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) decl := ReactPropTypes.{type}(.isRequired)? Each and every declaration produces a function with the same signature. This allows the creation of custom validation functions. For example: var MyLink = React.createClass({ propTypes: { // An optional string or URI prop named "href". href: function(props, propName, componentName) { var propValue = props[propName]; if (propValue != null && typeof propValue !== 'string' && !(propValue instanceof URI)) { return new Error( 'Expected a string or an URI for ' + propName + ' in ' + componentName ); } } }, render: function() {...} }); @internal
validate
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function createNodeChecker() { function validate(props, propName, componentName, location, propFullName) { if (!isNode(props[propName])) { var locationName = ReactPropTypeLocationNames[location]; return new Error('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.')); } return null; } return createChainableTypeChecker(validate); }
Collection of methods that allow declaration and validation of props that are supplied to React components. Example usage: var Props = require('ReactPropTypes'); var MyArticle = React.createClass({ propTypes: { // An optional string prop named "description". description: Props.string, // A required enum prop named "category". category: Props.oneOf(['News','Photos']).isRequired, // A prop named "dialog" that requires an instance of Dialog. dialog: Props.instanceOf(Dialog).isRequired }, render: function() { ... } }); A more formal specification of how these methods are used: type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) decl := ReactPropTypes.{type}(.isRequired)? Each and every declaration produces a function with the same signature. This allows the creation of custom validation functions. For example: var MyLink = React.createClass({ propTypes: { // An optional string or URI prop named "href". href: function(props, propName, componentName) { var propValue = props[propName]; if (propValue != null && typeof propValue !== 'string' && !(propValue instanceof URI)) { return new Error( 'Expected a string or an URI for ' + propName + ' in ' + componentName ); } } }, render: function() {...} }); @internal
createNodeChecker
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT
function validate(props, propName, componentName, location, propFullName) { if (!isNode(props[propName])) { var locationName = ReactPropTypeLocationNames[location]; return new Error('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.')); } return null; }
Collection of methods that allow declaration and validation of props that are supplied to React components. Example usage: var Props = require('ReactPropTypes'); var MyArticle = React.createClass({ propTypes: { // An optional string prop named "description". description: Props.string, // A required enum prop named "category". category: Props.oneOf(['News','Photos']).isRequired, // A prop named "dialog" that requires an instance of Dialog. dialog: Props.instanceOf(Dialog).isRequired }, render: function() { ... } }); A more formal specification of how these methods are used: type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) decl := ReactPropTypes.{type}(.isRequired)? Each and every declaration produces a function with the same signature. This allows the creation of custom validation functions. For example: var MyLink = React.createClass({ propTypes: { // An optional string or URI prop named "href". href: function(props, propName, componentName) { var propValue = props[propName]; if (propValue != null && typeof propValue !== 'string' && !(propValue instanceof URI)) { return new Error( 'Expected a string or an URI for ' + propName + ' in ' + componentName ); } } }, render: function() {...} }); @internal
validate
javascript
amol-/dukpy
dukpy/jsmodules/react/react.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/react/react.js
MIT