Skip to content

Managing lists of components that don't have a key

Nathan Ridley edited this page Aug 6, 2016 · 1 revision

Sometimes we don't care to manually identify our child components. Instead we just want to build a list by appending items and otherwise letting things manage themselves. This example revolves around a hypothetical simulation of the Chrome developer console. Each log message potentially displays items of data that can be clicked and expanded for further inspection.

To add an item for which we don't have a key, simply use the add method, which generates a unique key and then appends the item internally using set. Remember, collections use ordered maps internally, which is why we're able to use keys but still treat the collection like a list.

function ConsoleMessage(sources) { /* ... */ }

const console$ = logMessage$
  .scan((messages, msg) => messages.add(msg), Collection(ConsoleMessage));

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