I'm trying to take a random Observable stream of 10 objects each with properties like:
{tileNum: '6', tileName: 'game-of-thrones' clickCount:'1'}
next the clickCount
needs to increase every time an identical tileNum
inside the object comes through the stream using tileNum
. Now for the tricky bit the streamed each tileNum
needs to be attached to a div (0-9), these divs will need to be pre populate and the clickCount
increase on the relevant div attached to object.
eg:
div 6 = clickCount:'1'
=> {tileNum: '6'..}
=> div 6 = clickCount:'2'
So far I have:
const tile = (sources) => {
const incomingMessages$ = sources.socketIO.get('newClickStream'); // continuous Observable
const state$ = model(incomingMessages$);
const view$ = view(state$);
return {
DOM: view$,
}
};
index.js
const model = actions =>
actions.groupBy((tile) => tile.tileNum)
.flatMap(
(tile$) =>
tile$
.scan((prev, {tileName, tileNum}, index) => ({
tileNum,
tileName,
clickCount: index + 1
}))
.do(x => console.log(x))
);
export default model;
model.js
const view = (state$) =>
state$.map(source => {
return div([
h(`div#${source.tileNum}`, {}, ['${source.clickCount}']),
])
});
export default view;
view.js
Right now I'm only able to populate one div that changes on every new stream object. As a caveat but not necessary if the divs could be ordered by clickCount
that would be amazing.