GithubHelp home page GithubHelp logo

eventuate-filter's Introduction

eventuate-filter

NPM version Build Status Coverage Status Sauce Test Status

Create an eventuate that re-produces a subset of events from another eventuate.

This tiny module is also part of the larger aggregate module: eventuate

This module may also be used stand-alone, with eventuate-core.

example

var eventuate = require('eventuate-core'),
    filter    = require('eventuate-filter')

var logMessage = eventuate()
var errorMessage = filter(logMessage, function (log) {
  return log.level === 'error'
})

errorMessage(function (log) {
  console.error(log.message)
})

logMessage.produce({ level: 'info', message: 'something happened' })
logMessage.produce({ level: 'error', message: 'something bad happened' })
logMessage.produce({ level: 'info', message: 'something else happened' })

// output:
// something bad happened

api

var eventuate = require('eventuate-core')
var filter    = require('eventuate-filter')

var upstreamEventuate = eventuate()

The API of the filteredEventuate is mostly identical to the eventuate it is filtering.

var filteredEventuate = filter(upstreamEventuate, options, filterFunc)

Returns a new eventuate, filteredEventuate, which re-produces events from a non-basic eventuate, upstreamEventuate, for which filterFunc returns or resolves to true.

Valid options are:

  • requireConsumption (default: false) - throw an error if a produced event is not consumed
  • destroyResidual (default: true) - call the destroy function when the last consumer is removed via removeConsumer or removeAllConsumers (after at least one consumer was added)
  • lazy (default: true) - wait until a consumer is added before consuming from upstreamEventuate. If set to false, will begin consuming/filtering/producing immediately, even with no consumers added. This is useful when used in conjunction with requireConsumption, for example.
  • order (default: false) - insure the order of items output match the order of input, even with an async filter. Be careful using this option, as it will cause buffering.

The filterFunc function should accept at least one argument, data, but may optionally accept a 2nd argument of a callback; eventuate-filter will determine whether a callback is accepted based on the argument length of the filterFunc function.

If a callback is NOT accepted, then filterFunc should return either a boolean or a Promise. If a Promise is returned, it should resolve to a boolean. If a callback is accepted, the return value of filterFunc is ignored, and the error-first style callback (function (err, bool) {}) must be called with either a truthy error or a falsey error and a boolean.

Upon receiving a truthy boolean from either a return value, Promise, or callback, the filteredEventuate will produce the data in question.

If either the callback is supplied an error, or the Promise is rejected, then the filteredEventuate will produce an Error object.

If the callback or Promise are resolved/rejected after the filteredEventuate has been destroyed, the value will not be produced.

filteredEventuate.destroy()

When destroyed, the filteredEventuate will stop consuming from the upstreamEventuate. The filteredEventuate is automatically destroyed unless the destroyResidual option was given as false during creation of the filteredEventuate.

filteredEventuate.upstreamConsumer

The function added as a consumer to the upstreamEventuate.

install

With npm do:

npm install --save eventuate-core

testing

npm test

Or to run tests in phantom: npm run phantom

coverage

npm run view-cover

This will output a textual coverage report.

npm run open-cover

This will open an HTML coverage report in the default browser.

eventuate-filter's People

Contributors

jasonpincin avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.