Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A typescript example for further clarification #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Data>;
}

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<ItemSources[]>= res$.map(res =>
<Data[]> JSON.parse(res.text)
).map(items => items.map(item => <ItemSources> {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`?
---

Expand Down