Skip to content

Latest commit

 

History

History

switchlatest

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

flyd-switchlatest

Flattens a stream of streams. The result stream reflects changes from the last stream only.

Graph

a:               {--.----.----}
                    {ab} {a-b}
switchLatest(a): {--ab---a-b--}

Signature

Stream (Stream a) -> Stream b

Usage

const switchLatest = require('flyd/module/switchlatest')

const chatrooms = flyd.stream()
// For each chatroom on the chatrooms stream, create a stream of chat messages.
// This gives us a series of streams nested within a parent stream.
const messages = flyd.map(createMessageStream, chatrooms)

// Create a single, unnested stream of chat messages
const currentMessages = switchLatest(messagesStreams)