Skip to content
Nathan Ridley edited this page Aug 6, 2016 · 3 revisions

This is a library to make management of collections of child components much easier, and was inspired by Nick Johnstone's excellent collection library for Cycle.js and xstream. It's based on Most.js streams (as are all Motorcycle packages) and while it shares some similarities with cycle/collection, it was written from scratch as a universal way to manage and combine sets of child components in general, whether they're known about in advance, such as the different sections of a web page, or dynamically changing in length, such as for a live stream of messages.

Features

  • Immutable by default; perfect for managing using scan, loop, map and others.
  • Can be used as both as a dictionary or as a list, with methods to generate unique keys if not specified when adding an item to a collection
  • Define an arbitrary number of component types that the list will support
  • Add, update and remove any number of children of any of the component types defined for the collection
  • Collection size grows and shrinks dynamically
  • Manage as a dynamic array of components for cases such as lists, or set children by key to streamline the management of different predefined sections of a page
  • Merge children into unified groups of arbitrary sinks that the parent component can return directly or merge with its own local streams
  • Automatically project a common sink from each child to an array of the most recent values from each child component; ideal for use with map, combine and combineArray
  • Customizable lifecycle operations for each defined component type, including instantiation, equality and sort comparison operations
  • Well-tested with over 200 unit tests

Installation

npm install --save @motorcycle/collection

Reference the library using an import or require statement:

import collection from '@motorcycle/collection'
// or
const collection = require('@motorcycle/collection')

Next Steps

  1. Read the tutorial
  2. Refer to the [API quick reference](API - Quick Reference) while coding
  3. Check out the [detailed reference](API - Detailed Reference) section for deeper understanding of API methods

Tutorial and Guide

  • [Managing child components](Managing child components)
  • [Replacing a child component when state changes](Replacing a child component when state changes)
  • [Combining multiple sinks from child components](Combining multiple sinks from child components)
  • [Simple merging of a common sink to a derivative stream](Simple merging of a common sink to a derivative stream)
  • [Dynamic lists of child components](Dynamic lists of child components)
  • [Managing lists of components that don't have a key](Managing lists of components that don't have a key)
  • [Handling multiple component types in a single list](Handling multiple component types in a single list)
  • [Taking control of a component's lifecycle within a list](Taking control of a component's lifecycle within a list)

API Reference

  • [Quick Reference](API Quick Reference)
  • [Detailed Reference](API Detailed Reference)
Clone this wiki locally