From 2bc2b52eaa7f541dd3ad30ede41e2a8dba74d9c8 Mon Sep 17 00:00:00 2001 From: CommitSyncScript Date: Fri, 21 Jun 2013 13:53:25 -0700 Subject: [PATCH] Allow accessing siblings by ref This makes it possible to write a wider range of components without depending on internal implementations. --- src/core/ReactComponent.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/core/ReactComponent.js b/src/core/ReactComponent.js index 530a6f9c66..d312881068 100644 --- a/src/core/ReactComponent.js +++ b/src/core/ReactComponent.js @@ -564,6 +564,22 @@ var ReactComponent = { */ isOwnedBy: function(owner) { return this.props[OWNER] === owner; + }, + + /** + * Gets another component, that shares the same owner as this one, by ref. + * + * @param {string} ref of a sibling Component. + * @return {?ReactComponent} the actual sibling Component. + * @final + * @internal + */ + getSiblingByRef: function(ref) { + var owner = this.props[OWNER]; + if (!owner || !owner.refs) { + return null; + } + return owner.refs[ref]; } }