dom-reduce

Reducible DOM APIs

npm install dom-reduce
7 downloads in the last week
13 downloads in the last month

dom-reduce

Build Status

Small library for dealing with browser DOM events in a reducible style. This lets operate on user events as with regular collection data structures in composable manner.

Usage

var open = require("dom-reduce/event")
var map = require("reducers/map")
var filter = require("reducers/filter")
var fold = require("reducers/fold")
var takeWhile = require("reducers/take-while")

// Take stream of mouse move events.
var moves = open(document.documentElement, "mousemove")
// Map it to the axis positions
var axis = map(moves, function(event) {
  return { x: event.clientX, y: event.clientY }
})
// Filter down to the area we're interested in.
var lineAxis = filter(axis, function(value) {
  return value.x > 190 && value.x < 200
})

// Take positions only until mouse reaches the edge.
// Note that when this contidion is met event listeners
// will automatically be removed.
var values = takeWhile(lineAxis, function(value) {
  return value.y > 0
})

// Drow sowething in the given range.
fold(lineAxis, function(position) {
  draw(position)
})

Install

npm install dom-reduce

Develop

Library is developed using awesome browserify! Phantomify is used for running test in a PhantomJS.

npm loves you