Skip to content

Commit

Permalink
Merge pull request spring-media#12 from newying61/change_to_use_react…
Browse files Browse the repository at this point in the history
…_event_handlers

fix: change to use __reactEventHandlersXXX to get latest event handler
  • Loading branch information
chgohlke authored Apr 29, 2020
2 parents c266d2b + 993e08d commit 516dafb
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ module.exports = function retargetEvents(shadowRoot) {
for (var i = 0; i < path.length; i++) {

var el = path[i];
var props = null;
var reactComponent = findReactComponent(el);
var props = findReactProps(reactComponent);
var eventHandlers = findReactEventHandlers(el);

if (!eventHandlers) {
props = findReactProps(reactComponent);
} else {
props = eventHandlers;
}

if (reactComponent && props) {
dispatchEvent(event, reactEventName, props);
Expand Down Expand Up @@ -66,9 +73,17 @@ module.exports = function retargetEvents(shadowRoot) {
};
};

function findReactEventHandlers(item) {
return findReactProperty(item, '__reactEventHandlers');
}

function findReactComponent(item) {
return findReactProperty(item, '_reactInternal');
}

function findReactProperty(item, propertyPrefix) {
for (var key in item) {
if (item.hasOwnProperty(key) && key.indexOf('_reactInternal') !== -1) {
if (item.hasOwnProperty(key) && key.indexOf(propertyPrefix) !== -1) {
return item[key];
}
}
Expand Down

0 comments on commit 516dafb

Please sign in to comment.