fix(injected-component): Correctly call methods to the injected instance

- Adds check to `_runInnerDOMMethod` to check if inner is an UnsafeComponent and
relay the call appropriately
- Removes duplicated logic from `_setRequiredMethods`
This commit is contained in:
Juan Tejada 2016-01-10 16:25:31 -08:00
parent b3841d79e6
commit f779b61dd5

View file

@ -127,27 +127,26 @@ class InjectedComponent extends React.Component
# 2. Any native implementation provided by the DOM # 2. Any native implementation provided by the DOM
# 3. Ourselves, so that the method always has /some/ effect. # 3. Ourselves, so that the method always has /some/ effect.
# #
_runInnerDOMMethod: (method) => _runInnerDOMMethod: (method, args...) =>
target = null target = null
if @refs.inner and @refs.inner[method] if @refs.inner instanceof UnsafeComponent and @refs.inner.injected[method]?
target = @refs.inner.injected
else if @refs.inner and @refs.inner[method]?
target = @refs.inner target = @refs.inner
else if @refs.inner else if @refs.inner
target = React.findDOMNode(@refs.inner) target = React.findDOMNode(@refs.inner)
else else
target = React.findDOMNode(@) target = React.findDOMNode(@)
target[method]?() target[method].bind(target)(args...)
_setRequiredMethods: (methods) => _setRequiredMethods: (methods) =>
methods.forEach (method) => methods.forEach (method) =>
Object.defineProperty(@, method, Object.defineProperty(@, method,
configurable: true configurable: true
enumerable: true enumerable: true
get: => value: (args...)=>
if @refs.inner instanceof UnsafeComponent @_runInnerDOMMethod(method, args...)
@refs.inner.injected[method]?.bind(@refs.inner.injected)
else
@refs.inner[method]?.bind(@refs.inner)
) )
_verifyRequiredMethods: => _verifyRequiredMethods: =>