Operator: filter

Filter is the data flow control node, it allows signal to pass under certain conditions

Signature

NS.filter(comment : string, inputs : map, outputs : map, accept : function) : Node

Alias:

NS.when(comment : string, inputs : map, outputs : map, accept : function) : Node

Arguments

Arguement Type Description
comment string optional, the comment of the sensor
inputs map optional, the input description
outputs map optional, the output description
accept function the condition function, allow signal pass if return true, otherwise return false

accept function signature:

function accept(signal : Signal) : Boolean

Return

Type Description
Node the filter node

Create a filter

const ns = collar.ns('collarjs.demo.sensor');
const input = ns.input('input');
input
  .filter(s => {
    return s.get('v') % 2 === 0;
  })
  .do(s => console.log(s.payload));

input.push({v: 1}); // --> output nothing
input.push({v: 2}); // --> {v: 2}

results matching ""

    No results matching ""