Skip to content

Commit

Permalink
Remove transaction from ref lifecycle code path
Browse files Browse the repository at this point in the history
We don't need to pass the transaction around anymore since we store the
test options on _hostContainerInfo instead
  • Loading branch information
Brandon Dail committed Nov 11, 2016
1 parent 7b8366f commit e3dc639
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1205,10 +1205,10 @@ var ReactCompositeComponent = {
* @final
* @private
*/
attachRef: function(ref, component, transaction) {
attachRef: function(ref, component) {
var inst = this.getPublicInstance();
invariant(inst != null, 'Stateless function components cannot have refs.');
var publicComponentInstance = component.getPublicInstance(transaction);
var publicComponentInstance = component.getPublicInstance();
if (__DEV__) {
var componentName = component && component.getName ?
component.getName() : 'a component';
Expand Down
4 changes: 1 addition & 3 deletions src/renderers/shared/stack/reconciler/ReactOwner.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
var invariant = require('invariant');

import type { ReactInstance } from 'ReactInstanceType';
import type { Transaction } from 'Transaction';

/**
* @param {?object} object
Expand Down Expand Up @@ -74,7 +73,6 @@ var ReactOwner = {
component: ReactInstance,
ref: string,
owner: ReactInstance,
transaction: Transaction,
): void {
invariant(
isValidOwner(owner),
Expand All @@ -83,7 +81,7 @@ var ReactOwner = {
'`render` method, or you have multiple copies of React loaded ' +
'(details: https://fb.me/react-refs-must-have-owner).'
);
owner.attachRef(ref, component, transaction);
owner.attachRef(ref, component);
},

/**
Expand Down
8 changes: 2 additions & 6 deletions src/renderers/shared/stack/reconciler/ReactReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ var warning = require('warning');
* Helper to call ReactRef.attachRefs with this composite component, split out
* to avoid allocations in the transaction mount-ready queue.
*/
function attachRefs(transaction) {
ReactRef.attachRefs(
this,
this._currentElement,
transaction,
);
function attachRefs() {
ReactRef.attachRefs(this, this._currentElement);
}

var ReactReconciler = {
Expand Down
9 changes: 3 additions & 6 deletions src/renderers/shared/stack/reconciler/ReactRef.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@ var ReactOwner = require('ReactOwner');

import type { ReactInstance } from 'ReactInstanceType';
import type { ReactElement } from 'ReactElementType';
import type { Transaction } from 'Transaction';

var ReactRef = {};

function attachRef(ref, component, owner, transaction) {
function attachRef(ref, component, owner) {
if (typeof ref === 'function') {
ref(component.getPublicInstance(transaction));
ref(component.getPublicInstance());
} else {
// Legacy ref
ReactOwner.addComponentAsRefTo(
component,
ref,
owner,
transaction,
);
}
}
Expand All @@ -46,14 +44,13 @@ function detachRef(ref, component, owner) {
ReactRef.attachRefs = function(
instance: ReactInstance,
element: ReactElement | string | number | null | false,
transaction: Transaction,
): void {
if (element === null || typeof element !== 'object') {
return;
}
var ref = element.ref;
if (ref != null) {
attachRef(ref, instance, element._owner, transaction);
attachRef(ref, instance, element._owner);
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/renderers/testing/ReactTestMount.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ TopLevelWrapper.isReactTopLevelWrapper = true;
* Mounts this component and inserts it into the DOM.
*
* @param {ReactComponent} componentInstance The instance to mount.
* @param {number} rootID ID of the root node.
* @param {number} containerTag container element to mount into.
* @param {ReactReconcileTransaction} transaction
* @param {Object} hostParent
* @param {Object} hostContainerInfo
*/
function mountComponentIntoNode(
componentInstance,
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/testing/ReactTestRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ReactTestComponent {
this.updateChildren(nextElement.props.children, transaction, context);
}

getPublicInstance(transaction: ReactTestReconcileTransaction): Object {
getPublicInstance(): Object {
var element = this._currentElement;
var hostContainerInfo = this._hostContainerInfo;
invariant(
Expand Down

0 comments on commit e3dc639

Please sign in to comment.