An event emitter that emits only new events.
An event emitter that emits only new events. Because sometimes we don't care about old events.
var NewsEmitter = require'newsemitter';var news = ;newson'item'console.log'new item:' itemtitle;;newsemit'item' title: 'hello there' ;newsemit'item' title: 'hello world' ;newsemit'item' title: 'hello there' ;newsemit'item' title: 'hey' ;newsemit'item' title: 'hey' ;newsemit'item' title: 'hey' ;// new item: hello there// new item: hello world// new item: hey
Creates an instance of a NewsEmitter.
options can be
filter- An array of events that will be affected. If not given, events names will not be filtered.
maxHistory- Maximum number of history items to remember. Default is
manageHistory- If true, does not add emitted events to history. Instead expects you to manually manage history with
addHistory(). Defaults to
comparator- Function used to compare one event to another. Takes 2 arguments, first is possibly new arguments item, and second is item from history. Default is a deep equal function.
Emits an event, only if it has not been emitted before. Returns true if item is new and emtted. False otherwise.
Resets history of an event. If no event given, resets all history.
Adds items in
event's history. Truncated as necessary based on max history length considering the last item in the array as newest.
npm install newsemitter
Tests are written with mocha