Permalink
Browse files

fix(on): fix bug of inherited handler

  • Loading branch information...
kt3k committed Aug 6, 2018
1 parent 9730a2c commit 58800a7581ab015663d7fc54d2afa596ec6ea9b4
Showing with 32 additions and 5 deletions.
  1. +27 −1 src/__tests__/unmount.js
  2. +4 −3 src/decorators/on.js
  3. +1 −1 src/init-component.js
@@ -35,7 +35,33 @@ describe('unmount', () => {
el.click()
el.dispatchEvent(new CustomEvent('foo'))

setTimeout(() => done(), 200)
setTimeout(() => done(), 100)
})

it('unmounts anscestor class\'s event handler correctly', done => {
class Foo {
method () {
done(new Error('event handler called!'))
}
}

class Bar extends Foo {
}

callDecorator(on.click, Foo, 'method')
callDecorator(on('foo'), Foo, 'method')

def('bar', Bar)

const el = genel.div``
make('bar', el)

unmount('bar', el)

el.click()
el.dispatchEvent(new CustomEvent('foo'))

setTimeout(() => done(), 100)
})

it('calls __unmount__ if exists', done => {
@@ -1,5 +1,5 @@
// @flow
import { KEY_EVENT_LISTENERS, COMPONENT_NAME_KEY } from '../util/const.js'
import { KEY_EVENT_LISTENERS } from '../util/const.js'
import debugMessage from '../util/debug-message.js'
import check from '../util/check.js'

@@ -20,9 +20,10 @@ export default (event: string, { at }: { at?: string } = {}) => (target: Object,
/**
* @param el The element
* @param coelem The coelement
* @param name The component name
*/
Constructor[KEY_EVENT_LISTENERS] = (Constructor[KEY_EVENT_LISTENERS] || []).concat((el: HTMLElement, coelem: any) => {
const keyEventListeners = KEY_EVENT_LISTENERS + Constructor[COMPONENT_NAME_KEY]
Constructor[KEY_EVENT_LISTENERS] = (Constructor[KEY_EVENT_LISTENERS] || []).concat((el: HTMLElement, coelem: any, name: string) => {
const keyEventListeners = KEY_EVENT_LISTENERS + name

const listener = (e: Event): void => {
if (
@@ -28,7 +28,7 @@ export default (Constructor: Function, el: HTMLElement, name?: string): any => {

// Initialize event listeners defined by @emit decorator
;(Constructor[KEY_EVENT_LISTENERS] || []).map(listenerBinder => {
listenerBinder(el, coelem)
listenerBinder(el, coelem, name)
})

// Executes plugin hooks

0 comments on commit 58800a7

Please sign in to comment.