These are chat archives for pozadi/kefir

10th
Aug 2015
findjashua
@findjashua
Aug 10 2015 17:59
hello all!
i recently started using observables, and have a question
how do i get an eventstream for when an element with a particular selector is added to the dom
which takes a callback
so do i just do kefir.fromCallback(MutationObserver)?
or rather kefir.fromCallback(observer)
where observer is an instance of Mutation Observer
Roman Pominov
@rpominov
Aug 10 2015 19:24
Hi @findjashua, I never used mutation observer before myself, but from the link you mentioned, it seems like it has quite weird API, and it will be a bit tricky to create a stream from it. First you create an instance of observer and provide a callback var inst = new MutationObserver(cb), then call inst.observe(domNode) to start observing a node, from that point callback will be called with mutation descriptions. That a normal use of MutationObserver, and to create a stream, I'd use Kefir.stream(subscribe) putting that "normal use" code into subscribe function.
There is also a chance that I misunderstand how MutationObserver works, as I said, I newer used it myself.