Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sunwukung
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunwukung/69c1be92215112e93a87 to your computer and use it in GitHub Desktop.
Save sunwukung/69c1be92215112e93a87 to your computer and use it in GitHub Desktop.
kefir event listener question
// domStreams
var K = require("kefir")
, exported = {}
, evts = ["click", "mouseenter", "mousemove", "mouseexit"];
evts.forEach((eventKey, i, arr) => {
exported[eventKey] = (elem) => {
return K.fromEvent(elem, eventKey);
};
});
// UI
var rootNode = document.querySelector("#foo")
, mousemoveStream = domStreams.mousemove(rootNode)
, hits = 0;
mousemoveStream.onValue(() => {
hits++;
console.log("still firing the on value method");
if (hits === 100) {
console.log("removing the value output");
mousemoveStream.off(); // should end messages?
};
});
@sunwukung
Copy link
Author

updated:

var rootNode = createElement(tree)
    , mousemoveStream = domStreams.mousemove(rootNode)
    , hits = 0
    , handler = () => {
        hits++;
        console.log("handling that event");
        if (hits > 10) {
            mousemoveStream.offValue(handler);
        }
    };

  mousemoveStream.onValue(handler);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment