Input and Output.
Takes a Collection input and outputs another Collection. Can be used for any type of transformation like, but not limited to: filtering, sorting, mapping, and reducing.
It allows for *nix style pipeing of data:
# *nix piping
> collection | Filter | Sort | Page
# cell/Collection piping
collection.pipe Filter(), Sort(), Page()
A Pipe can either be simple or incremental.
Simple Pipe
Just a function.
# Simple passthrough pipe
passthrough = (input)-> input.toArray()
Incremental Pipe
For large, high performance, and active collections.
A pipeline of simple pipes can be very costly calculate. And when a collection changes (add, remove), starting from scratch and executing each pipe could make it piping impractical if changes occur frequently and/or the collection is large.
Incremental pipes to the rescue.
If the input collection changes (add,remove), the first pipe is notified and can choose to operate on just the small subset that has changed. This may or may not effect it's output. If no changes are made to first pipe's output, then no other downstream pipe's are notified. If there changes are made, the next pipe is notified of only the changes. Thus only the minimal amount processing is done.
# Passthrough Incremental Pipe
Passthrough = Pipe.extend
constructor: (options)->
# You can listen to changes to option values using spy.watch() and change the output as necessary
# Ex. Filtering of list changes based on user input
spy.watch @, options.option1, -> # Do stuff
onReset: -> @output.reset @input
onAdd: (item, index)-> @output.add item, index
onRemove: (item, index)-> @output.remove index
# Used in a view...
require('cell/defineView!')
render: (_)-> [
# User input can change options watched by an Incremental Pipe
_ 'textarea', (x_model prop:'filterOption1', model:@)
# Smart Pipes can be passed an options hash
_.each (inputCollection.pipe Passthrough option1:-> @get 'filterOption1'), (item)->
# Render item
]