without-propagation
    TypeScript icon, indicating that this package has built-in type declarations

    0.3.1 • Public • Published

    without-propagation build codecov

    You don't want a propagation, right?

    <div>
      <button>Click me</button>
    </div>
    const div = document.querySelector('div')
    const button = document.querySelector('button')
     
    div.addEventListener('click', (e) => {
      console.log('Catch a click on the div')
    })
     
    button.addEventListener('click', (e) => {
      console.log('Catch a click on the button')
    })
     
    button.click()
     
    // > Catch a click on the button
    // > Catch a click on the div

    Oh my... sure I don't

    yarn add without-propagation

    You're fine now:

    import withoutPropagation from 'without-propagation'
     
    const div = document.querySelector('div')
    const button = document.querySelector('button')
     
    div.addEventListener('click', (e) => {
      console.log('The event will be never fired')
    })
     
    button.addEventListener('click', withoutPropagation((e) => {
      console.log('Catch a click on the button only')
    }))
     
    button.click()
     
    // > Catch a click on the button only

    Install

    npm i without-propagation

    DownloadsWeekly Downloads

    0

    Version

    0.3.1

    License

    MIT

    Unpacked Size

    7.09 kB

    Total Files

    13

    Last publish

    Collaborators

    • sadorlovsky