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 unescape(key) { var unescapeRegex = /(=0|=2)/g; var unescaperLookup = { '=0': '=', '=2': ':' }; var keySubstring = key[0] === '.' && key[1] === '$' ? key.substring(2) : key.substring(1); return ('' + keySubstring).replace(unescapeRegex, function (match) { return unescaperLookup[match]; }); }
Unescape and unwrap key for human-readable display @param {string} key to unescape. @return {string} the unescaped key.
unescape
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.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
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
defineDeprecationWarning = function (methodName, info) { if (canDefineProperty) { Object.defineProperty(ReactComponent.prototype, methodName, { get: function () { process.env.NODE_ENV !== 'production' ? warning(false, '%s(...) is deprecated in plain JavaScript React classes. %s', info[0], info[1]) : void 0; 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
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function ReactPureComponent(props, context, updater) { // Duplicated from ReactComponent. 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.
ReactPureComponent
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function validateTypeDef(Constructor, typeDef, location) { for (var propName in typeDef) { if (typeDef.hasOwnProperty(propName)) { // use a warning instead of an invariant so components // don't show up in prod but only in __DEV__ process.env.NODE_ENV !== 'production' ? warning(typeof typeDef[propName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', Constructor.displayName || 'ReactClass', ReactPropTypeLocationNames[location], propName) : void 0; } } }
Special case getDefaultProps which should move into statics but requires automatic merging.
validateTypeDef
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function validateMethodOverride(isAlreadyDefined, name) { var specPolicy = ReactClassInterface.hasOwnProperty(name) ? ReactClassInterface[name] : null; // Disallow overriding of base class methods unless explicitly allowed. if (ReactClassMixin.hasOwnProperty(name)) { !(specPolicy === 'OVERRIDE_BASE') ? process.env.NODE_ENV !== '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) : _prodInvariant('73', name) : void 0; } // Disallow defining methods more than once unless explicitly allowed. if (isAlreadyDefined) { !(specPolicy === 'DEFINE_MANY' || specPolicy === 'DEFINE_MANY_MERGED') ? process.env.NODE_ENV !== '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) : _prodInvariant('74', name) : void 0; } }
Special case getDefaultProps which should move into statics but requires automatic merging.
validateMethodOverride
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function mixSpecIntoComponent(Constructor, spec) { if (!spec) { if (process.env.NODE_ENV !== 'production') { var typeofSpec = typeof spec; var isMixinValid = typeofSpec === 'object' && spec !== null; process.env.NODE_ENV !== 'production' ? warning(isMixinValid, '%s: You\'re attempting to include a mixin that is either null ' + 'or not an object. Check the mixins included by the component, ' + 'as well as any mixins they include themselves. ' + 'Expected object but got %s.', Constructor.displayName || 'ReactClass', spec === null ? null : typeofSpec) : void 0; } return; } !(typeof spec !== 'function') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactClass: You\'re attempting to use a component class or function as a mixin. Instead, just use a regular object.') : _prodInvariant('75') : void 0; !!ReactElement.isValidElement(spec) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactClass: You\'re attempting to use a component as a mixin. Instead, just use a regular object.') : _prodInvariant('76') : void 0; var proto = Constructor.prototype; var autoBindPairs = proto.__reactAutoBindPairs; // 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]; var isAlreadyDefined = proto.hasOwnProperty(name); validateMethodOverride(isAlreadyDefined, 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 isFunction = typeof property === 'function'; var shouldAutoBind = isFunction && !isReactClassMethod && !isAlreadyDefined && spec.autobind !== false; if (shouldAutoBind) { autoBindPairs.push(name, property); proto[name] = property; } else { if (isAlreadyDefined) { var specPolicy = ReactClassInterface[name]; // These cases should already be caught by validateMethodOverride. !(isReactClassMethod && (specPolicy === 'DEFINE_MANY_MERGED' || specPolicy === 'DEFINE_MANY')) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactClass: Unexpected spec policy %s for key %s when mixing in component specs.', specPolicy, name) : _prodInvariant('77', specPolicy, name) : void 0; // For methods which are defined more than once, call the existing // methods before calling the new property, merging if appropriate. if (specPolicy === 'DEFINE_MANY_MERGED') { proto[name] = createMergedResultFunction(proto[name], property); } else if (specPolicy === 'DEFINE_MANY') { proto[name] = createChainedFunction(proto[name], property); } } else { proto[name] = property; if (process.env.NODE_ENV !== '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 classes.
mixSpecIntoComponent
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.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 ? process.env.NODE_ENV !== '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) : _prodInvariant('78', name) : void 0; var isInherited = name in Constructor; !!isInherited ? process.env.NODE_ENV !== '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) : _prodInvariant('79', name) : void 0; Constructor[name] = property; } }
Mixin helper which handles policy validation and reserved specification keys when building React classes.
mixStaticSpecIntoComponent
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function mergeIntoWithNoDuplicateKeys(one, two) { !(one && two && typeof one === 'object' && typeof two === 'object') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.') : _prodInvariant('80') : void 0; for (var key in two) { if (two.hasOwnProperty(key)) { !(one[key] === undefined) ? process.env.NODE_ENV !== '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) : _prodInvariant('81', key) : void 0; 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
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.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
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.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
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function bindAutoBindMethod(component, method) { var boundMethod = method.bind(component); if (process.env.NODE_ENV !== 'production') { boundMethod.__reactBoundContext = component; boundMethod.__reactBoundMethod = method; boundMethod.__reactBoundArguments = null; var componentName = component.constructor.displayName; var _bind = boundMethod.bind; 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) { process.env.NODE_ENV !== 'production' ? warning(false, 'bind(): React component methods may only be bound to the ' + 'component instance. See %s', componentName) : void 0; } else if (!args.length) { process.env.NODE_ENV !== '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) : void 0; return boundMethod; } var reboundMethod = _bind.apply(boundMethod, arguments); reboundMethod.__reactBoundContext = component; reboundMethod.__reactBoundMethod = method; reboundMethod.__reactBoundArguments = args; return reboundMethod; }; } 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
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function bindAutoBindMethods(component) { var pairs = component.__reactAutoBindPairs; for (var i = 0; i < pairs.length; i += 2) { var autoBindKey = pairs[i]; var method = pairs[i + 1]; 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
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.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
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function getCurrentComponentErrorInfo(parentType) { var info = getDeclarationErrorAddendum(); if (!info) { var parentName = typeof parentType === 'string' ? parentType : parentType.displayName || parentType.name; if (parentName) { info = ' Check the top-level render call using <' + parentName + '>.'; } } return info; }
Warn if there's no key explicitly set on dynamic arrays of children or object keys are not valid. This allows us to keep track of children between updates.
getCurrentComponentErrorInfo
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function validateExplicitKey(element, parentType) { if (!element._store || element._store.validated || element.key != null) { return; } element._store.validated = true; var memoizer = ownerHasKeyUseWarning.uniqueKey || (ownerHasKeyUseWarning.uniqueKey = {}); var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType); if (memoizer[currentComponentErrorInfo]) { return; } memoizer[currentComponentErrorInfo] = true; // 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. var childOwner = ''; if (element && element._owner && element._owner !== ReactCurrentOwner.current) { // Give the component that originally created this child. childOwner = ' It was passed a child from ' + element._owner.getName() + '.'; } process.env.NODE_ENV !== 'production' ? warning(false, 'Each child in an array or iterator should have a unique "key" prop.' + '%s%s See https://fb.me/react-warning-keys for more information.%s', currentComponentErrorInfo, childOwner, ReactComponentTreeHook.getCurrentStackAddendum(element)) : void 0; }
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. Error statuses are cached so a warning will only be shown once. @internal @param {ReactElement} element Element that requires a key. @param {*} parentType element's parent's type.
validateExplicitKey
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.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
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function validatePropTypes(element) { var componentClass = element.type; if (typeof componentClass !== 'function') { return; } var name = componentClass.displayName || componentClass.name; if (componentClass.propTypes) { checkReactTypeSpec(componentClass.propTypes, element.props, 'prop', name, element, null); } if (typeof componentClass.getDefaultProps === 'function') { process.env.NODE_ENV !== 'production' ? warning(componentClass.getDefaultProps.isReactClassApproved, 'getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.') : void 0; } }
Given an element, validate that its props follow the propTypes definition, provided by the type. @param {ReactElement} element
validatePropTypes
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function checkReactTypeSpec(typeSpecs, values, location, componentName, element, debugID) { for (var typeSpecName in typeSpecs) { if (typeSpecs.hasOwnProperty(typeSpecName)) { 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 typeSpecs[typeSpecName] === 'function') ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s: %s type `%s` is invalid; it must be a function, usually from React.PropTypes.', componentName || 'React class', ReactPropTypeLocationNames[location], typeSpecName) : _prodInvariant('84', componentName || 'React class', ReactPropTypeLocationNames[location], typeSpecName) : void 0; error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret); } catch (ex) { error = ex; } process.env.NODE_ENV !== '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], typeSpecName, typeof error) : void 0; 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 componentStackInfo = ''; if (process.env.NODE_ENV !== 'production') { if (!ReactComponentTreeHook) { ReactComponentTreeHook = __webpack_require__(28); } if (debugID !== null) { componentStackInfo = ReactComponentTreeHook.getStackAddendumByID(debugID); } else if (element !== null) { componentStackInfo = ReactComponentTreeHook.getCurrentStackAddendum(element); } } process.env.NODE_ENV !== 'production' ? warning(false, 'Failed %s type: %s%s', location, error.message, componentStackInfo) : void 0; } } } }
Assert that the values match with the type specs. Error messages are memorized and will only be shown once. @param {object} typeSpecs Map of name to a ReactPropType @param {object} values Runtime values that need to be type-checked @param {string} location e.g. "prop", "context", "child context" @param {string} componentName Name of the component for error messages. @param {?object} element The React element that is being type-checked @param {?number} debugID The React component instance that is being type-checked @private
checkReactTypeSpec
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function PropTypeError(message) { this.message = message; this.stack = ''; }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
PropTypeError
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function createChainableTypeChecker(validate) { if (process.env.NODE_ENV !== 'production') { var manualPropTypeCallCache = {}; } function checkType(isRequired, props, propName, componentName, location, propFullName, secret) { componentName = componentName || ANONYMOUS; propFullName = propFullName || propName; if (process.env.NODE_ENV !== 'production') { if (secret !== ReactPropTypesSecret && typeof console !== 'undefined') { var cacheKey = componentName + ':' + propName; if (!manualPropTypeCallCache[cacheKey]) { process.env.NODE_ENV !== 'production' ? warning(false, 'You are manually calling a React.PropTypes validation ' + 'function for the `%s` prop on `%s`. This is deprecated ' + 'and will not work in production with the next major version. ' + 'You may be seeing this warning due to a third-party PropTypes ' + 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.', propFullName, componentName) : void 0; manualPropTypeCallCache[cacheKey] = true; } } } if (props[propName] == null) { var locationName = ReactPropTypeLocationNames[location]; if (isRequired) { if (props[propName] === null) { return new PropTypeError('The ' + locationName + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.')); } return new PropTypeError('The ' + locationName + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.')); } return null; } else { return validate(props, propName, componentName, location, propFullName); } } var chainedCheckType = checkType.bind(null, false); chainedCheckType.isRequired = checkType.bind(null, true); return chainedCheckType; }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
createChainableTypeChecker
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) { componentName = componentName || ANONYMOUS; propFullName = propFullName || propName; if (process.env.NODE_ENV !== 'production') { if (secret !== ReactPropTypesSecret && typeof console !== 'undefined') { var cacheKey = componentName + ':' + propName; if (!manualPropTypeCallCache[cacheKey]) { process.env.NODE_ENV !== 'production' ? warning(false, 'You are manually calling a React.PropTypes validation ' + 'function for the `%s` prop on `%s`. This is deprecated ' + 'and will not work in production with the next major version. ' + 'You may be seeing this warning due to a third-party PropTypes ' + 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.', propFullName, componentName) : void 0; manualPropTypeCallCache[cacheKey] = true; } } } if (props[propName] == null) { var locationName = ReactPropTypeLocationNames[location]; if (isRequired) { if (props[propName] === null) { return new PropTypeError('The ' + locationName + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.')); } return new PropTypeError('The ' + locationName + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.')); } return null; } else { return validate(props, propName, componentName, location, propFullName); } }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
checkType
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function createPrimitiveTypeChecker(expectedType) { function validate(props, propName, componentName, location, propFullName, secret) { 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 PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.')); } return null; } return createChainableTypeChecker(validate); }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
createPrimitiveTypeChecker
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function validate(props, propName, componentName, location, propFullName, secret) { 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 PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.')); } return null; }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
validate
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function createAnyTypeChecker() { return createChainableTypeChecker(emptyFunction.thatReturns(null)); }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
createAnyTypeChecker
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function createArrayOfTypeChecker(typeChecker) { function validate(props, propName, componentName, location, propFullName) { if (typeof typeChecker !== 'function') { return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.'); } var propValue = props[propName]; if (!Array.isArray(propValue)) { var locationName = ReactPropTypeLocationNames[location]; var propType = getPropType(propValue); return new PropTypeError('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 + ']', ReactPropTypesSecret); if (error instanceof Error) { return error; } } return null; } return createChainableTypeChecker(validate); }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
createArrayOfTypeChecker
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function validate(props, propName, componentName, location, propFullName) { if (typeof typeChecker !== 'function') { return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.'); } var propValue = props[propName]; if (!Array.isArray(propValue)) { var locationName = ReactPropTypeLocationNames[location]; var propType = getPropType(propValue); return new PropTypeError('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 + ']', ReactPropTypesSecret); if (error instanceof Error) { return error; } } return null; }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
validate
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function createElementTypeChecker() { function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; if (!ReactElement.isValidElement(propValue)) { var locationName = ReactPropTypeLocationNames[location]; var propType = getPropType(propValue); return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.')); } return null; } return createChainableTypeChecker(validate); }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
createElementTypeChecker
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; if (!ReactElement.isValidElement(propValue)) { var locationName = ReactPropTypeLocationNames[location]; var propType = getPropType(propValue); return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.')); } return null; }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
validate
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.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 PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.')); } return null; } return createChainableTypeChecker(validate); }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
createInstanceTypeChecker
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.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 PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.')); } return null; }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
validate
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function createEnumTypeChecker(expectedValues) { if (!Array.isArray(expectedValues)) { process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOf, expected an instance of array.') : void 0; return emptyFunction.thatReturnsNull; } function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; for (var i = 0; i < expectedValues.length; i++) { if (is(propValue, expectedValues[i])) { return null; } } var locationName = ReactPropTypeLocationNames[location]; var valuesString = JSON.stringify(expectedValues); return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.')); } return createChainableTypeChecker(validate); }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
createEnumTypeChecker
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; for (var i = 0; i < expectedValues.length; i++) { if (is(propValue, expectedValues[i])) { return null; } } var locationName = ReactPropTypeLocationNames[location]; var valuesString = JSON.stringify(expectedValues); return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.')); }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
validate
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function createObjectOfTypeChecker(typeChecker) { function validate(props, propName, componentName, location, propFullName) { if (typeof typeChecker !== 'function') { return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.'); } var propValue = props[propName]; var propType = getPropType(propValue); if (propType !== 'object') { var locationName = ReactPropTypeLocationNames[location]; return new PropTypeError('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, ReactPropTypesSecret); if (error instanceof Error) { return error; } } } return null; } return createChainableTypeChecker(validate); }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
createObjectOfTypeChecker
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function validate(props, propName, componentName, location, propFullName) { if (typeof typeChecker !== 'function') { return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.'); } var propValue = props[propName]; var propType = getPropType(propValue); if (propType !== 'object') { var locationName = ReactPropTypeLocationNames[location]; return new PropTypeError('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, ReactPropTypesSecret); if (error instanceof Error) { return error; } } } return null; }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
validate
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function createUnionTypeChecker(arrayOfTypeCheckers) { if (!Array.isArray(arrayOfTypeCheckers)) { process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOfType, expected an instance of array.') : void 0; return emptyFunction.thatReturnsNull; } 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, ReactPropTypesSecret) == null) { return null; } } var locationName = ReactPropTypeLocationNames[location]; return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.')); } return createChainableTypeChecker(validate); }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
createUnionTypeChecker
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.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, ReactPropTypesSecret) == null) { return null; } } var locationName = ReactPropTypeLocationNames[location]; return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.')); }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
validate
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function createNodeChecker() { function validate(props, propName, componentName, location, propFullName) { if (!isNode(props[propName])) { var locationName = ReactPropTypeLocationNames[location]; return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.')); } return null; } return createChainableTypeChecker(validate); }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
createNodeChecker
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function validate(props, propName, componentName, location, propFullName) { if (!isNode(props[propName])) { var locationName = ReactPropTypeLocationNames[location]; return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.')); } return null; }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
validate
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function createShapeTypeChecker(shapeTypes) { function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; var propType = getPropType(propValue); if (propType !== 'object') { var locationName = ReactPropTypeLocationNames[location]; return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); } for (var key in shapeTypes) { var checker = shapeTypes[key]; if (!checker) { continue; } var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret); if (error) { return error; } } return null; } return createChainableTypeChecker(validate); }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
createShapeTypeChecker
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.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 PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); } for (var key in shapeTypes) { var checker = shapeTypes[key]; if (!checker) { continue; } var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret); if (error) { return error; } } return null; }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
validate
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function isNode(propValue) { switch (typeof propValue) { case 'number': case 'string': case 'undefined': return true; case 'boolean': return !propValue; case 'object': if (Array.isArray(propValue)) { return propValue.every(isNode); } if (propValue === null || ReactElement.isValidElement(propValue)) { return true; } var iteratorFn = getIteratorFn(propValue); if (iteratorFn) { var iterator = iteratorFn.call(propValue); var step; if (iteratorFn !== propValue.entries) { while (!(step = iterator.next()).done) { if (!isNode(step.value)) { return false; } } } else { // Iterator will provide entry [k,v] tuples rather than values. while (!(step = iterator.next()).done) { var entry = step.value; if (entry) { if (!isNode(entry[1])) { return false; } } } } } else { return false; } return true; default: return false; } }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
isNode
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function isSymbol(propType, propValue) { // Native Symbol. if (propType === 'symbol') { return true; } // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol' if (propValue['@@toStringTag'] === 'Symbol') { return true; } // Fallback for non-spec compliant Symbols which are polyfilled. if (typeof Symbol === 'function' && propValue instanceof Symbol) { return true; } return false; }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
isSymbol
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function getPropType(propValue) { var propType = typeof propValue; if (Array.isArray(propValue)) { return 'array'; } if (propValue instanceof RegExp) { // Old webkits (at least until Android 4.0) return 'function' rather than // 'object' for typeof a RegExp. We'll normalize this here so that /bla/ // passes PropTypes.object. return 'object'; } if (isSymbol(propType, propValue)) { return 'symbol'; } return propType; }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
getPropType
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function getPreciseType(propValue) { var propType = getPropType(propValue); if (propType === 'object') { if (propValue instanceof Date) { return 'date'; } else if (propValue instanceof RegExp) { return 'regexp'; } } return propType; }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
getPreciseType
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function getClassName(propValue) { if (!propValue.constructor || !propValue.constructor.name) { return ANONYMOUS; } return propValue.constructor.name; }
We use an Error-like object for backward compatibility as people may call PropTypes directly and inspect their output. However we don't use real Errors anymore. We don't inspect their stack anyway, and creating them is prohibitively expensive if they are created too often, such as what happens in oneOfType() for any type before the one that matched.
getClassName
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function onlyChild(children) { !ReactElement.isValidElement(children) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'React.Children.only expected to receive a single React element child.') : _prodInvariant('143') : void 0; return children; }
Returns the first child in a collection of children and verifies that there is only one child in the collection. See https://facebook.github.io/react/docs/top-level-api.html#react.children.only The current implementation of this function assumes that a single child gets passed without a wrapper, but the purpose of this helper function is to abstract away the particular structure of children. @param {?object} children Child collection structure. @return {ReactElement} The first and only `ReactElement` contained in the structure.
onlyChild
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function shouldPrecacheNode(node, nodeID) { return node.nodeType === 1 && node.getAttribute(ATTR_NAME) === String(nodeID) || node.nodeType === 8 && node.nodeValue === ' react-text: ' + nodeID + ' ' || node.nodeType === 8 && node.nodeValue === ' react-empty: ' + nodeID + ' '; }
Check if a given node should be cached.
shouldPrecacheNode
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function getRenderedHostOrTextFromComponent(component) { var rendered; while (rendered = component._renderedComponent) { component = rendered; } return component; }
Drill down (through composites and empty components) until we get a host or host text component. This is pretty polymorphic but unavoidable with the current structure we have for `_renderedChildren`.
getRenderedHostOrTextFromComponent
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function precacheNode(inst, node) { var hostInst = getRenderedHostOrTextFromComponent(inst); hostInst._hostNode = node; node[internalInstanceKey] = hostInst; }
Populate `_hostNode` on the rendered host/text component with the given DOM node. The passed `inst` can be a composite.
precacheNode
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function uncacheNode(inst) { var node = inst._hostNode; if (node) { delete node[internalInstanceKey]; inst._hostNode = null; } }
Populate `_hostNode` on the rendered host/text component with the given DOM node. The passed `inst` can be a composite.
uncacheNode
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function precacheChildNodes(inst, node) { if (inst._flags & Flags.hasCachedChildNodes) { return; } var children = inst._renderedChildren; var childNode = node.firstChild; outer: for (var name in children) { if (!children.hasOwnProperty(name)) { continue; } var childInst = children[name]; var childID = getRenderedHostOrTextFromComponent(childInst)._domID; if (childID === 0) { // We're currently unmounting this child in ReactMultiChild; skip it. continue; } // We assume the child nodes are in the same order as the child instances. for (; childNode !== null; childNode = childNode.nextSibling) { if (shouldPrecacheNode(childNode, childID)) { precacheNode(childInst, childNode); continue outer; } } // We reached the end of the DOM children without finding an ID match. true ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Unable to find element with ID %s.', childID) : _prodInvariant('32', childID) : void 0; } inst._flags |= Flags.hasCachedChildNodes; }
Populate `_hostNode` on each child of `inst`, assuming that the children match up with the DOM (element) children of `node`. We cache entire levels at once to avoid an n^2 problem where we access the children of a node sequentially and have to walk from the start to our target node every time. Since we update `_renderedChildren` and the actual DOM at (slightly) different times, we could race here and see a newer `_renderedChildren` than the DOM nodes we see. To avoid this, ReactMultiChild calls `prepareToManageChildren` before we change `_renderedChildren`, at which time the container's child nodes are always cached (until it unmounts).
precacheChildNodes
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function getClosestInstanceFromNode(node) { if (node[internalInstanceKey]) { return node[internalInstanceKey]; } // Walk up the tree until we find an ancestor whose instance we have cached. var parents = []; while (!node[internalInstanceKey]) { parents.push(node); if (node.parentNode) { node = node.parentNode; } else { // Top of the tree. This node must not be part of a React tree (or is // unmounted, potentially). return null; } } var closest; var inst; for (; node && (inst = node[internalInstanceKey]); node = parents.pop()) { closest = inst; if (parents.length) { precacheChildNodes(inst, node); } } return closest; }
Given a DOM node, return the closest ReactDOMComponent or ReactDOMTextComponent instance ancestor.
getClosestInstanceFromNode
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function getInstanceFromNode(node) { var inst = getClosestInstanceFromNode(node); if (inst != null && inst._hostNode === node) { return inst; } else { return null; } }
Given a DOM node, return the ReactDOMComponent or ReactDOMTextComponent instance, or null if the node was not rendered by this React.
getInstanceFromNode
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function getNodeFromInstance(inst) { // Without this first invariant, passing a non-DOM-component triggers the next // invariant for a missing parent, which is super confusing. !(inst._hostNode !== undefined) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'getNodeFromInstance: Invalid argument.') : _prodInvariant('33') : void 0; if (inst._hostNode) { return inst._hostNode; } // Walk up the tree until we find an ancestor whose DOM node we have cached. var parents = []; while (!inst._hostNode) { parents.push(inst); !inst._hostParent ? process.env.NODE_ENV !== 'production' ? invariant(false, 'React DOM tree root should always have a node reference.') : _prodInvariant('34') : void 0; inst = inst._hostParent; } // Now parents contains each ancestor that does *not* have a cached native // node, and `inst` is the deepest ancestor that does. for (; parents.length; inst = parents.pop()) { precacheChildNodes(inst, inst._hostNode); } return inst._hostNode; }
Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding DOM node.
getNodeFromInstance
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function reactProdInvariant(code) { var argCount = arguments.length - 1; var message = 'Minified React error #' + code + '; visit ' + 'http://facebook.github.io/react/docs/error-decoder.html?invariant=' + code; for (var argIdx = 0; argIdx < argCount; argIdx++) { message += '&args[]=' + encodeURIComponent(arguments[argIdx + 1]); } message += ' for the full message or use the non-minified dev environment' + ' for full errors and additional helpful warnings.'; var error = new Error(message); error.name = 'Invariant Violation'; error.framesToPop = 1; // we don't care about reactProdInvariant's own frame throw error; }
WARNING: DO NOT manually require this module. This is a replacement for `invariant(...)` used by the error code system and will _only_ be required by the corresponding babel pass. It always throws.
reactProdInvariant
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function isPresto() { var opera = window.opera; return typeof opera === 'object' && typeof opera.version === 'function' && parseInt(opera.version(), 10) <= 12; }
Opera <= 12 includes TextEvent in window, but does not fire text input events. Rely on keypress instead.
isPresto
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function isKeypressCommand(nativeEvent) { return (nativeEvent.ctrlKey || nativeEvent.altKey || nativeEvent.metaKey) && // ctrlKey && altKey is equivalent to AltGr, and is not a command. !(nativeEvent.ctrlKey && nativeEvent.altKey); }
Return whether a native keypress event is assumed to be a command. This is required because Firefox fires `keypress` events for key commands (cut, copy, select-all, etc.) even though no character is inserted.
isKeypressCommand
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function getCompositionEventType(topLevelType) { switch (topLevelType) { case 'topCompositionStart': return eventTypes.compositionStart; case 'topCompositionEnd': return eventTypes.compositionEnd; case 'topCompositionUpdate': return eventTypes.compositionUpdate; } }
Translate native top level events into event types. @param {string} topLevelType @return {object}
getCompositionEventType
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function isFallbackCompositionStart(topLevelType, nativeEvent) { return topLevelType === 'topKeyDown' && nativeEvent.keyCode === START_KEYCODE; }
Does our fallback best-guess model think this event signifies that composition has begun? @param {string} topLevelType @param {object} nativeEvent @return {boolean}
isFallbackCompositionStart
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function isFallbackCompositionEnd(topLevelType, nativeEvent) { switch (topLevelType) { case 'topKeyUp': // Command keys insert or clear IME input. return END_KEYCODES.indexOf(nativeEvent.keyCode) !== -1; case 'topKeyDown': // Expect IME keyCode on each keydown. If we get any other // code we must have exited earlier. return nativeEvent.keyCode !== START_KEYCODE; case 'topKeyPress': case 'topMouseDown': case 'topBlur': // Events are not possible without cancelling IME. return true; default: return false; } }
Does our fallback mode think that this event is the end of composition? @param {string} topLevelType @param {object} nativeEvent @return {boolean}
isFallbackCompositionEnd
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function getDataFromCustomEvent(nativeEvent) { var detail = nativeEvent.detail; if (typeof detail === 'object' && 'data' in detail) { return detail.data; } return null; }
Google Input Tools provides composition data via a CustomEvent, with the `data` property populated in the `detail` object. If this is available on the event object, use it. If not, this is a plain composition event and we have nothing special to extract. @param {object} nativeEvent @return {?string}
getDataFromCustomEvent
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function getNativeBeforeInputChars(topLevelType, nativeEvent) { switch (topLevelType) { case 'topCompositionEnd': return getDataFromCustomEvent(nativeEvent); case 'topKeyPress': /** * If native `textInput` events are available, our goal is to make * use of them. However, there is a special case: the spacebar key. * In Webkit, preventing default on a spacebar `textInput` event * cancels character insertion, but it *also* causes the browser * to fall back to its default spacebar behavior of scrolling the * page. * * Tracking at: * https://code.google.com/p/chromium/issues/detail?id=355103 * * To avoid this issue, use the keypress event as if no `textInput` * event is available. */ var which = nativeEvent.which; if (which !== SPACEBAR_CODE) { return null; } hasSpaceKeypress = true; return SPACEBAR_CHAR; case 'topTextInput': // Record the characters to be added to the DOM. var chars = nativeEvent.data; // If it's a spacebar character, assume that we have already handled // it at the keypress level and bail immediately. Android Chrome // doesn't give us keycodes, so we need to blacklist it. if (chars === SPACEBAR_CHAR && hasSpaceKeypress) { return null; } return chars; default: // For other native event types, do nothing. return null; } }
@param {string} topLevelType Record from `EventConstants`. @param {object} nativeEvent Native browser event. @return {?string} The string corresponding to this `beforeInput` event.
getNativeBeforeInputChars
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function getFallbackBeforeInputChars(topLevelType, nativeEvent) { // If we are currently composing (IME) and using a fallback to do so, // try to extract the composed characters from the fallback object. // If composition event is available, we extract a string only at // compositionevent, otherwise extract it at fallback events. if (currentComposition) { if (topLevelType === 'topCompositionEnd' || !canUseCompositionEvent && isFallbackCompositionEnd(topLevelType, nativeEvent)) { var chars = currentComposition.getData(); FallbackCompositionState.release(currentComposition); currentComposition = null; return chars; } return null; } switch (topLevelType) { case 'topPaste': // If a paste event occurs after a keypress, throw out the input // chars. Paste events should not lead to BeforeInput events. return null; case 'topKeyPress': /** * As of v27, Firefox may fire keypress events even when no character * will be inserted. A few possibilities: * * - `which` is `0`. Arrow keys, Esc key, etc. * * - `which` is the pressed key code, but no char is available. * Ex: 'AltGr + d` in Polish. There is no modified character for * this key combination and no character is inserted into the * document, but FF fires the keypress for char code `100` anyway. * No `input` event will occur. * * - `which` is the pressed key code, but a command combination is * being used. Ex: `Cmd+C`. No character is inserted, and no * `input` event will occur. */ if (nativeEvent.which && !isKeypressCommand(nativeEvent)) { return String.fromCharCode(nativeEvent.which); } return null; case 'topCompositionEnd': return useFallbackCompositionData ? null : nativeEvent.data; default: return null; } }
For browsers that do not provide the `textInput` event, extract the appropriate string to use for SyntheticInputEvent. @param {string} topLevelType Record from `EventConstants`. @param {object} nativeEvent Native browser event. @return {?string} The fallback string for this `beforeInput` event.
getFallbackBeforeInputChars
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function extractBeforeInputEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget) { var chars; if (canUseTextInputEvent) { chars = getNativeBeforeInputChars(topLevelType, nativeEvent); } else { chars = getFallbackBeforeInputChars(topLevelType, nativeEvent); } // If no characters are being inserted, no BeforeInput event should // be fired. if (!chars) { return null; } var event = SyntheticInputEvent.getPooled(eventTypes.beforeInput, targetInst, nativeEvent, nativeEventTarget); event.data = chars; EventPropagators.accumulateTwoPhaseDispatches(event); return event; }
Extract a SyntheticInputEvent for `beforeInput`, based on either native `textInput` or fallback behavior. @return {?object} A SyntheticInputEvent.
extractBeforeInputEvent
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function listenerAtPhase(inst, event, propagationPhase) { var registrationName = event.dispatchConfig.phasedRegistrationNames[propagationPhase]; return getListener(inst, registrationName); }
Some event types have a notion of different registration names for different "phases" of propagation. This finds listeners by a given phase.
listenerAtPhase
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function accumulateDirectionalDispatches(inst, phase, event) { if (process.env.NODE_ENV !== 'production') { process.env.NODE_ENV !== 'production' ? warning(inst, 'Dispatching inst must not be null') : void 0; } var listener = listenerAtPhase(inst, event, phase); if (listener) { event._dispatchListeners = accumulateInto(event._dispatchListeners, listener); event._dispatchInstances = accumulateInto(event._dispatchInstances, inst); } }
Tags a `SyntheticEvent` with dispatched listeners. Creating this function here, allows us to not have to bind or create functions for each event. Mutating the event's members allows us to not have to create a wrapping "dispatch" object that pairs the event with the listener.
accumulateDirectionalDispatches
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function accumulateTwoPhaseDispatchesSingle(event) { if (event && event.dispatchConfig.phasedRegistrationNames) { EventPluginUtils.traverseTwoPhase(event._targetInst, accumulateDirectionalDispatches, event); } }
Collect dispatches (must be entirely collected before dispatching - see unit tests). Lazily allocate the array to conserve memory. We must loop through each event and perform the traversal for each one. We cannot perform a single traversal for the entire collection of events because each event may have a different target.
accumulateTwoPhaseDispatchesSingle
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function accumulateTwoPhaseDispatchesSingleSkipTarget(event) { if (event && event.dispatchConfig.phasedRegistrationNames) { var targetInst = event._targetInst; var parentInst = targetInst ? EventPluginUtils.getParentInstance(targetInst) : null; EventPluginUtils.traverseTwoPhase(parentInst, accumulateDirectionalDispatches, event); } }
Same as `accumulateTwoPhaseDispatchesSingle`, but skips over the targetID.
accumulateTwoPhaseDispatchesSingleSkipTarget
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function accumulateDispatches(inst, ignoredDirection, event) { if (event && event.dispatchConfig.registrationName) { var registrationName = event.dispatchConfig.registrationName; var listener = getListener(inst, registrationName); if (listener) { event._dispatchListeners = accumulateInto(event._dispatchListeners, listener); event._dispatchInstances = accumulateInto(event._dispatchInstances, inst); } } }
Accumulates without regard to direction, does not look for phased registration names. Same as `accumulateDirectDispatchesSingle` but without requiring that the `dispatchMarker` be the same as the dispatched ID.
accumulateDispatches
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function accumulateDirectDispatchesSingle(event) { if (event && event.dispatchConfig.registrationName) { accumulateDispatches(event._targetInst, null, event); } }
Accumulates dispatches on an `SyntheticEvent`, but only for the `dispatchMarker`. @param {SyntheticEvent} event
accumulateDirectDispatchesSingle
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function accumulateTwoPhaseDispatches(events) { forEachAccumulated(events, accumulateTwoPhaseDispatchesSingle); }
Accumulates dispatches on an `SyntheticEvent`, but only for the `dispatchMarker`. @param {SyntheticEvent} event
accumulateTwoPhaseDispatches
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function accumulateTwoPhaseDispatchesSkipTarget(events) { forEachAccumulated(events, accumulateTwoPhaseDispatchesSingleSkipTarget); }
Accumulates dispatches on an `SyntheticEvent`, but only for the `dispatchMarker`. @param {SyntheticEvent} event
accumulateTwoPhaseDispatchesSkipTarget
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function accumulateEnterLeaveDispatches(leave, enter, from, to) { EventPluginUtils.traverseEnterLeave(from, to, accumulateDispatches, leave, enter); }
Accumulates dispatches on an `SyntheticEvent`, but only for the `dispatchMarker`. @param {SyntheticEvent} event
accumulateEnterLeaveDispatches
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function accumulateDirectDispatches(events) { forEachAccumulated(events, accumulateDirectDispatchesSingle); }
Accumulates dispatches on an `SyntheticEvent`, but only for the `dispatchMarker`. @param {SyntheticEvent} event
accumulateDirectDispatches
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
executeDispatchesAndRelease = function (event, simulated) { if (event) { EventPluginUtils.executeDispatchesInOrder(event, simulated); if (!event.isPersistent()) { event.constructor.release(event); } } }
Dispatches an event and releases it back into the pool, unless persistent. @param {?object} event Synthetic event to be dispatched. @param {boolean} simulated If the event is simulated (changes exn behavior) @private
executeDispatchesAndRelease
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
executeDispatchesAndReleaseSimulated = function (e) { return executeDispatchesAndRelease(e, true); }
Dispatches an event and releases it back into the pool, unless persistent. @param {?object} event Synthetic event to be dispatched. @param {boolean} simulated If the event is simulated (changes exn behavior) @private
executeDispatchesAndReleaseSimulated
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
executeDispatchesAndReleaseTopLevel = function (e) { return executeDispatchesAndRelease(e, false); }
Dispatches an event and releases it back into the pool, unless persistent. @param {?object} event Synthetic event to be dispatched. @param {boolean} simulated If the event is simulated (changes exn behavior) @private
executeDispatchesAndReleaseTopLevel
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
getDictionaryKey = function (inst) { // Prevents V8 performance issue: // https://github.com/facebook/react/pull/7232 return '.' + inst._rootNodeID; }
Dispatches an event and releases it back into the pool, unless persistent. @param {?object} event Synthetic event to be dispatched. @param {boolean} simulated If the event is simulated (changes exn behavior) @private
getDictionaryKey
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function isInteractive(tag) { return tag === 'button' || tag === 'input' || tag === 'select' || tag === 'textarea'; }
Dispatches an event and releases it back into the pool, unless persistent. @param {?object} event Synthetic event to be dispatched. @param {boolean} simulated If the event is simulated (changes exn behavior) @private
isInteractive
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function shouldPreventMouseEvent(name, type, props) { switch (name) { case 'onClick': case 'onClickCapture': case 'onDoubleClick': case 'onDoubleClickCapture': case 'onMouseDown': case 'onMouseDownCapture': case 'onMouseMove': case 'onMouseMoveCapture': case 'onMouseUp': case 'onMouseUpCapture': return !!(props.disabled && isInteractive(type)); default: return false; } }
Dispatches an event and releases it back into the pool, unless persistent. @param {?object} event Synthetic event to be dispatched. @param {boolean} simulated If the event is simulated (changes exn behavior) @private
shouldPreventMouseEvent
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function recomputePluginOrdering() { if (!eventPluginOrder) { // Wait until an `eventPluginOrder` is injected. return; } for (var pluginName in namesToPlugins) { var pluginModule = namesToPlugins[pluginName]; var pluginIndex = eventPluginOrder.indexOf(pluginName); !(pluginIndex > -1) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginRegistry: Cannot inject event plugins that do not exist in the plugin ordering, `%s`.', pluginName) : _prodInvariant('96', pluginName) : void 0; if (EventPluginRegistry.plugins[pluginIndex]) { continue; } !pluginModule.extractEvents ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginRegistry: Event plugins must implement an `extractEvents` method, but `%s` does not.', pluginName) : _prodInvariant('97', pluginName) : void 0; EventPluginRegistry.plugins[pluginIndex] = pluginModule; var publishedEvents = pluginModule.eventTypes; for (var eventName in publishedEvents) { !publishEventForPlugin(publishedEvents[eventName], pluginModule, eventName) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginRegistry: Failed to publish event `%s` for plugin `%s`.', eventName, pluginName) : _prodInvariant('98', eventName, pluginName) : void 0; } } }
Recomputes the plugin list using the injected plugins and plugin ordering. @private
recomputePluginOrdering
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function publishEventForPlugin(dispatchConfig, pluginModule, eventName) { !!EventPluginRegistry.eventNameDispatchConfigs.hasOwnProperty(eventName) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginHub: More than one plugin attempted to publish the same event name, `%s`.', eventName) : _prodInvariant('99', eventName) : void 0; EventPluginRegistry.eventNameDispatchConfigs[eventName] = dispatchConfig; var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames; if (phasedRegistrationNames) { for (var phaseName in phasedRegistrationNames) { if (phasedRegistrationNames.hasOwnProperty(phaseName)) { var phasedRegistrationName = phasedRegistrationNames[phaseName]; publishRegistrationName(phasedRegistrationName, pluginModule, eventName); } } return true; } else if (dispatchConfig.registrationName) { publishRegistrationName(dispatchConfig.registrationName, pluginModule, eventName); return true; } return false; }
Publishes an event so that it can be dispatched by the supplied plugin. @param {object} dispatchConfig Dispatch configuration for the event. @param {object} PluginModule Plugin publishing the event. @return {boolean} True if the event was successfully published. @private
publishEventForPlugin
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function publishRegistrationName(registrationName, pluginModule, eventName) { !!EventPluginRegistry.registrationNameModules[registrationName] ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginHub: More than one plugin attempted to publish the same registration name, `%s`.', registrationName) : _prodInvariant('100', registrationName) : void 0; EventPluginRegistry.registrationNameModules[registrationName] = pluginModule; EventPluginRegistry.registrationNameDependencies[registrationName] = pluginModule.eventTypes[eventName].dependencies; if (process.env.NODE_ENV !== 'production') { var lowerCasedName = registrationName.toLowerCase(); EventPluginRegistry.possibleRegistrationNames[lowerCasedName] = registrationName; if (registrationName === 'onDoubleClick') { EventPluginRegistry.possibleRegistrationNames.ondblclick = registrationName; } } }
Publishes a registration name that is used to identify dispatched events and can be used with `EventPluginHub.putListener` to register listeners. @param {string} registrationName Registration name to add. @param {object} PluginModule Plugin publishing the event. @private
publishRegistrationName
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function isEndish(topLevelType) { return topLevelType === 'topMouseUp' || topLevelType === 'topTouchEnd' || topLevelType === 'topTouchCancel'; }
- `ComponentTree`: [required] Module that can convert between React instances and actual node references.
isEndish
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function isMoveish(topLevelType) { return topLevelType === 'topMouseMove' || topLevelType === 'topTouchMove'; }
- `ComponentTree`: [required] Module that can convert between React instances and actual node references.
isMoveish
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function isStartish(topLevelType) { return topLevelType === 'topMouseDown' || topLevelType === 'topTouchStart'; }
- `ComponentTree`: [required] Module that can convert between React instances and actual node references.
isStartish
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function executeDispatch(event, simulated, listener, inst) { var type = event.type || 'unknown-event'; event.currentTarget = EventPluginUtils.getNodeFromInstance(inst); if (simulated) { ReactErrorUtils.invokeGuardedCallbackWithCatch(type, listener, event); } else { ReactErrorUtils.invokeGuardedCallback(type, listener, event); } event.currentTarget = null; }
Dispatch the event to the listener. @param {SyntheticEvent} event SyntheticEvent to handle @param {boolean} simulated If the event is simulated (changes exn behavior) @param {function} listener Application-level callback @param {*} inst Internal component instance
executeDispatch
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function executeDispatchesInOrder(event, simulated) { var dispatchListeners = event._dispatchListeners; var dispatchInstances = event._dispatchInstances; if (process.env.NODE_ENV !== 'production') { validateEventDispatches(event); } if (Array.isArray(dispatchListeners)) { for (var i = 0; i < dispatchListeners.length; i++) { if (event.isPropagationStopped()) { break; } // Listeners and Instances are two parallel arrays that are always in sync. executeDispatch(event, simulated, dispatchListeners[i], dispatchInstances[i]); } } else if (dispatchListeners) { executeDispatch(event, simulated, dispatchListeners, dispatchInstances); } event._dispatchListeners = null; event._dispatchInstances = null; }
Standard/simple iteration through an event's collected dispatches.
executeDispatchesInOrder
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function executeDispatchesInOrderStopAtTrueImpl(event) { var dispatchListeners = event._dispatchListeners; var dispatchInstances = event._dispatchInstances; if (process.env.NODE_ENV !== 'production') { validateEventDispatches(event); } if (Array.isArray(dispatchListeners)) { for (var i = 0; i < dispatchListeners.length; i++) { if (event.isPropagationStopped()) { break; } // Listeners and Instances are two parallel arrays that are always in sync. if (dispatchListeners[i](event, dispatchInstances[i])) { return dispatchInstances[i]; } } } else if (dispatchListeners) { if (dispatchListeners(event, dispatchInstances)) { return dispatchInstances; } } return null; }
Standard/simple iteration through an event's collected dispatches, but stops at the first dispatch execution returning true, and returns that id. @return {?string} id of the first dispatch execution who's listener returns true, or null if no listener returned true.
executeDispatchesInOrderStopAtTrueImpl
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function executeDirectDispatch(event) { if (process.env.NODE_ENV !== 'production') { validateEventDispatches(event); } var dispatchListener = event._dispatchListeners; var dispatchInstance = event._dispatchInstances; !!Array.isArray(dispatchListener) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'executeDirectDispatch(...): Invalid `event`.') : _prodInvariant('103') : void 0; event.currentTarget = dispatchListener ? EventPluginUtils.getNodeFromInstance(dispatchInstance) : null; var res = dispatchListener ? dispatchListener(event) : null; event.currentTarget = null; event._dispatchListeners = null; event._dispatchInstances = null; return res; }
Execution of a "direct" dispatch - there must be at most one dispatch accumulated on the event or it is considered an error. It doesn't really make sense for an event with multiple dispatches (bubbled) to keep track of the return values at each dispatch execution, but it does tend to make sense when dealing with "direct" dispatches. @return {*} The return value of executing the single dispatch.
executeDirectDispatch
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function hasDispatches(event) { return !!event._dispatchListeners; }
@param {SyntheticEvent} event @return {boolean} True iff number of dispatches accumulated is greater than 0.
hasDispatches
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function invokeGuardedCallback(name, func, a) { try { func(a); } catch (x) { if (caughtError === null) { caughtError = x; } } }
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
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function accumulateInto(current, next) { !(next != null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'accumulateInto(...): Accumulated items must not be null or undefined.') : _prodInvariant('30') : void 0; if (current == null) { return next; } // Both are not empty. Warning: Never call x.concat(y) when you are not // certain that x is an Array (x could be a string with concat method). if (Array.isArray(current)) { if (Array.isArray(next)) { current.push.apply(current, next); return current; } current.push(next); return current; } if (Array.isArray(next)) { // A bit too dangerous to mutate `next`. return [current].concat(next); } return [current, next]; }
Accumulates items that must not be null or undefined into the first one. This is used to conserve memory by avoiding array allocations, and thus sacrifices API cleanness. Since `current` can be null before being passed in and not null after this function, make sure to assign it back to `current`: `a = accumulateInto(a, b);` This API should be sparingly used. Try `accumulate` for something cleaner. @return {*|array<*>} An accumulation of items.
accumulateInto
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function forEachAccumulated(arr, cb, scope) { if (Array.isArray(arr)) { arr.forEach(cb, scope); } else if (arr) { cb.call(scope, arr); } }
@param {array} arr an "accumulation" of items which is either an Array or a single item. Useful when paired with the `accumulate` module. This is a simple utility that allows us to reason about a collection of items, but handling the case when there is exactly one item (and we do not need to allocate an array).
forEachAccumulated
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
function FallbackCompositionState(root) { this._root = root; this._startText = this.getText(); this._fallbackText = null; }
This helper class stores information about text content of a target node, allowing comparison of content before and after a given event. Identify the node where selection currently begins, then observe both its text content and its current position in the DOM. Since the browser may natively replace the target node during composition, we can use its position to find its replacement. @param {DOMEventTarget} root
FallbackCompositionState
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
oneArgumentPooler = function (copyFieldsFrom) { var Klass = this; if (Klass.instancePool.length) { var instance = Klass.instancePool.pop(); Klass.call(instance, copyFieldsFrom); return instance; } else { return new Klass(copyFieldsFrom); } }
Static poolers. Several custom versions for each potential number of arguments. A completely generic pooler is easy to implement, but would require accessing the `arguments` object. In each of these, `this` refers to the Class itself, not an instance. If any others are needed, simply add them here, or in their own files.
oneArgumentPooler
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
twoArgumentPooler = function (a1, a2) { var Klass = this; if (Klass.instancePool.length) { var instance = Klass.instancePool.pop(); Klass.call(instance, a1, a2); return instance; } else { return new Klass(a1, a2); } }
Static poolers. Several custom versions for each potential number of arguments. A completely generic pooler is easy to implement, but would require accessing the `arguments` object. In each of these, `this` refers to the Class itself, not an instance. If any others are needed, simply add them here, or in their own files.
twoArgumentPooler
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
threeArgumentPooler = function (a1, a2, a3) { var Klass = this; if (Klass.instancePool.length) { var instance = Klass.instancePool.pop(); Klass.call(instance, a1, a2, a3); return instance; } else { return new Klass(a1, a2, a3); } }
Static poolers. Several custom versions for each potential number of arguments. A completely generic pooler is easy to implement, but would require accessing the `arguments` object. In each of these, `this` refers to the Class itself, not an instance. If any others are needed, simply add them here, or in their own files.
threeArgumentPooler
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT
fourArgumentPooler = function (a1, a2, a3, a4) { var Klass = this; if (Klass.instancePool.length) { var instance = Klass.instancePool.pop(); Klass.call(instance, a1, a2, a3, a4); return instance; } else { return new Klass(a1, a2, a3, a4); } }
Static poolers. Several custom versions for each potential number of arguments. A completely generic pooler is easy to implement, but would require accessing the `arguments` object. In each of these, `this` refers to the Class itself, not an instance. If any others are needed, simply add them here, or in their own files.
fourArgumentPooler
javascript
stitchfix/pyxley
tests/app/static/bundle.js
https://github.com/stitchfix/pyxley/blob/master/tests/app/static/bundle.js
MIT