Skip to content

Andarist/callbag-from-event-pattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

callbag-from-event-pattern

Callbag source factory from addHandler and removeHandler pair.

Example

import forEach from 'callbag-for-each'
import fromEventPattern from 'callbag-from-event-pattern'
import map from 'callbag-map'
import pipe from 'callbag-pipe'

const addHandler = handler => {
  document.addEventListener('click', handler)
}

const removeHandler = handler => {
  document.removeEventListener('click', handler)
}

pipe(
  fromEventPattern(addHandler, removeHandler),
  map(({ clientX: x, clientY: y }) => ({ x, y })),
  forEach(coord => {
    // will log coordinate of each click
    console.log(coord)
  }),
)

About

👜 Callbag source factory from addHandler and removeHandler pair.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published