diff --git a/README.md b/README.md index 83421c9..11b41d8 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,37 @@ function TodoList (sources) { } ``` +### Elaboration with a TypeScript example + +Say you have a list of "Item" components that will be part of a "List" component, where "Item" has the following sources: + +```ts +export interface Sources { + dom: DOMSource; +} + +export interface ItemSources { + item$: Stream; +} + +export interface ItemSourcesAll extends ItemSources, Sources {} +``` + +`ItemSourcesAll` is used internally by the "Item" component. In our "List" component, however, we just need to be concerned with ItemSources as Collection takes care of merging ItemSources with Sources. So in our "List" component, we might have some code that looks like this: + +```ts +const itemSources$: Stream= res$.map(res => + JSON.parse(res.text) + ).map(items => items.map(item => {item$: xs.of(item)})); +``` + +You can now see that the type passed as the second sources argument is in fact a stream of sources. The call to Collection looks like: + +```ts + const listItems$ = Collection(Item, sources, itemSources$); +``` + + Wait, how do we get the `todoListItems` to show up in the `DOM`? ---