Skip to content
Reducible DOM APIs
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test
.travis.yml
History.md
License.md
Readme.md
event.js
index.js
package.json

Readme.md

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.

Something went wrong with that request. Please try again.