function detachRef(ref, component, owner) { if (ref instanceof ReactRef) { ReactRef.detachRef(ref, component); } else { ReactOwner.removeComponentAsRefFrom(component, ref, owner); } }
updateComponent: function(transaction, prevElement) { var nextElement = this._currentElement; // If either the owner or a `ref` has changed, make sure the newest owner // has stored a reference to `this`, and the previous owner (if different) // has forgotten the reference to `this`. We use the element instead // of the public this.props because the post processing cannot determine // a ref. The ref conceptually lives on the element. // TODO: Should this even be possible? The owner cannot change because // it's forbidden by shouldUpdateReactComponent. The ref can change // if you swap the keys of but not the refs. Reconsider where this check // is made. It probably belongs where the key checking and // instantiateReactComponent is done. if (nextElement._owner !== prevElement._owner || nextElement.ref !== prevElement.ref) { if (prevElement.ref != null) { ReactOwner.removeComponentAsRefFrom( this, prevElement.ref, prevElement._owner ); } // Correct, even if the owner is the same, and only the ref has changed. if (nextElement.ref != null) { ReactOwner.addComponentAsRefTo( this, nextElement.ref, nextElement._owner ); } } },
function detachRef(ref, component, owner) { if (typeof ref === 'function') { ref(null); } else { ReactOwner.removeComponentAsRefFrom(component, ref, owner); } }
unmountComponent: function() { invariant( this.isMounted(), 'unmountComponent(): Can only unmount a mounted component.' ); var props = this.props; if (props.ref != null) { ReactOwner.removeComponentAsRefFrom(this, props.ref, this._owner); } ReactComponent.unmountIDFromEnvironment(this._rootNodeID); this._rootNodeID = null; this._lifeCycleState = ComponentLifeCycle.UNMOUNTED; },
unmountComponent: function() { invariant( this._lifeCycleState === ComponentLifeCycle.MOUNTED, 'unmountComponent(): Can only unmount a mounted component.' ); var props = this.props; if (props.ref != null) { ReactOwner.removeComponentAsRefFrom(this, props.ref, props[OWNER]); } this._rootNode = null; this._rootNodeID = null; this._lifeCycleState = ComponentLifeCycle.UNMOUNTED; },
updateComponent: function(transaction, prevProps, prevOwner) { var props = this.props; // If either the owner or a `ref` has changed, make sure the newest owner // has stored a reference to `this`, and the previous owner (if different) // has forgotten the reference to `this`. if (this._owner !== prevOwner || props.ref !== prevProps.ref) { if (prevProps.ref != null) { ReactOwner.removeComponentAsRefFrom( this, prevProps.ref, prevOwner ); } // Correct, even if the owner is the same, and only the ref has changed. if (props.ref != null) { ReactOwner.addComponentAsRefTo(this, props.ref, this._owner); } } },
receiveProps: function(nextProps, transaction) { invariant( this._lifeCycleState === ComponentLifeCycle.MOUNTED, 'receiveProps(...): Can only update a mounted component.' ); var props = this.props; // If either the owner or a `ref` has changed, make sure the newest owner // has stored a reference to `this`, and the previous owner (if different) // has forgotten the reference to `this`. if (nextProps[OWNER] !== props[OWNER] || nextProps.ref !== props.ref) { if (props.ref != null) { ReactOwner.removeComponentAsRefFrom(this, props.ref, props[OWNER]); } // Correct, even if the owner is the same, and only the ref has changed. if (nextProps.ref != null) { ReactOwner.addComponentAsRefTo(this, nextProps.ref, nextProps[OWNER]); } } },