Skip to content

Commit

Permalink
fix(components): Fix sharing of last event data between different tra…
Browse files Browse the repository at this point in the history
…ckers (#78)
  • Loading branch information
Blagoja Evkoski authored Dec 12, 2017
1 parent de74f0a commit aff1a6a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/components/src/shared/WithEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import PropTypes from 'prop-types'

const listeners = '@@girders-elements.internal/listeners'
const lastEvent = '@@girders-elements.internal/lastEvent'

/**
* A mixin that adds event handling methods to a React component
Expand All @@ -25,7 +26,6 @@ const listeners = '@@girders-elements.internal/listeners'
export default (eventDefinitons, OriginalComponent) => {
const defs = normalizeEventDefinitions(eventDefinitons)
const inChildContext = defs.filter(d => d.inChildContext)
let lastEvent = null

class Derived extends OriginalComponent {
constructor(props, context) {
Expand Down Expand Up @@ -71,7 +71,9 @@ export default (eventDefinitons, OriginalComponent) => {
Derived.prototype[d.addMethod] = function(callback) {
if (this[listeners][d.name].indexOf(callback === -1)) {
this[listeners][d.name].push(callback)
d.notifiesWithLastEventOnAdd && lastEvent && callback(lastEvent)
d.notifiesWithLastEventOnAdd &&
this[lastEvent] &&
callback(this[lastEvent])
}
}

Expand All @@ -84,7 +86,7 @@ export default (eventDefinitons, OriginalComponent) => {

Derived.prototype[d.notifyMethod] = function(evt) {
this[listeners][d.name].forEach(callback => callback(evt))
lastEvent = evt
this[lastEvent] = evt
}
})

Expand Down

0 comments on commit aff1a6a

Please sign in to comment.