mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-11 18:32:20 +08:00
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:
parent
b3841d79e6
commit
f779b61dd5
1 changed files with 7 additions and 8 deletions
|
@ -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: =>
|
||||||
|
|
Loading…
Reference in a new issue