Skip to content

Commit

Permalink
Fix stories sorting by removing cycle/collection
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrc committed Aug 8, 2016
1 parent 4979c6c commit 3960595
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"author": "Thomas Belin",
"license": "ISC",
"dependencies": {
"@cycle/collection": "^0.3.0",
"@cycle/dom": "^12.0.0",
"@cycle/isolate": "^1.2.0",
"@cycle/xstream-run": "^3.0.0",
Expand Down
27 changes: 17 additions & 10 deletions src/js/components/Timeline/StoriesList.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
import xs from "xstream";
import Collection from '@cycle/collection';
import {div} from "@cycle/dom";
import isolate from "@cycle/isolate";

import Story from "./Story";

function pluck(sources$, attr) {
return sources$.map(sources => sources.map(source => source[attr]))
}
function merge(sources$, attr) {
return pluck(sources$, attr)
.map(attrs => xs.merge(...attrs))
.flatten()
}

function StoriesList(sources) {
const {stories$, selectedElement$} = sources;

const viewDatas$ = xs
.combine(stories$, selectedElement$.startWith(null))
.map(([stories, element]) => {
return stories.map(story => ({ id: story.id, story$: story, options$: { selected: story.id === (element || {}).id }}));
return stories.map(story => ({ story$: xs.of(story), options$: xs.of({ selected: story.id === (element || {}).id })}));
});

const storyItems$ = Collection.gather(
Story,
sources,
viewDatas$
);
const storyItems$ = viewDatas$
.map(datas => datas.map(data => isolate(Story)({ ...sources, ...data })))
.remember()

const itemViews$ = Collection.pluck(storyItems$, item => item.DOM);
const itemNavigate$ = Collection.merge(storyItems$, item => item.router);
const itemAction$ = Collection.merge(storyItems$, item => item.action$);
const itemViews$ = pluck(storyItems$, "DOM");
const itemNavigate$ = merge(storyItems$, "router");
const itemAction$ = merge(storyItems$, "action$");

return {
DOM: itemViews$.map(views => div(".stories-list", views)),
Expand Down
1 change: 0 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = {
"@cycle/xstream-run",
"@cycle/dom",
"@cycle/isolate",
"@cycle/collection",
"uuid",
"cyclic-router",
"cyclejs-auth0",
Expand Down

0 comments on commit 3960595

Please sign in to comment.