Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Reducible DOM APIs
JavaScript
Branch: next

This branch is 4 commits behind master

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 reduce = require("reducers/reduce")
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.
reduce(lineAxis, function(previous, position) {
  draw(position)
  return 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.