Search code examples
noflo

Optional synchronization of IP:s in NoFlo component


I am writing a component that has one required IP and three optional IPs. The catch is that even though the three latter IPs are optional, at least one of them is required. It looks something like this:

@inPorts.add 'search_term', new noflo.InPort datatype: 'string'
@inPorts.add 'category1', new noflo.InPort datatype: 'boolean'
@inPorts.add 'category2', new noflo.InPort datatype: 'boolean'
@inPorts.add 'category3', new noflo.InPort datatype: 'boolean'

So, basically, the component should perform a search in some (at least one!) category or combination of categories.

The problem is that the component has to wait until it has gathered data from all connected inputs, then search and send the result forward.

I have looked into the wirePattern / groupedInput helpers but I cannot figure out if this type of optional grouping is supported. Am I missing something trivial here? Is there an easier way of achieving this behaviour? I have also looked some into the required option on IPs, but haven't got it working.


Solution

  • I recommend that you have only two inPorts; search_term and category. The category port could accept an object with up to three properties matching the category names.

    @inPorts.add 'search_term', new noflo.InPort datatype: 'string'
    @inPorts.add 'category', new noflo.InPort datatype: 'object'
    
    # Example input object
    {
      category1: true,
      category2: false,
      category3: true
    }