I'm trying to wrap my head around CycleJS but I'm stuck! I'm trying to put a small app together that loads a JSON file containing an array of objects, but I can't get the app to execute the http request
Here in my code so far
'use strict';
import Rx from 'rx';
import Cycle from '@cycle/core';
import {h, makeDOMDriver} from '@cycle/dom';
import {makeHTTPDriver} from '@cycle/http';
function intent(DOM) {
return {
edit: DOM.select('div')
.events('click')
.map(evt => evt.target.value),
add: DOM.select('div')
.events('click')
.map(evt => evt.target.value)
};
}
function model(actions, response) {
return response
}
function view(state) {
return state.map(item => {
h('div', [
item.map(todo => h('div', todo.title))
])
});
}
function main(sources) {
const URL = 'http://localhost:3000/js/planinator/data.json';
let response = sources.HTTP
.mergeAll()
.map(res => res.body)
.startWith([]);
const actions = intent(sources.DOM);
const state = model(actions, response);
return {
DOM: view(state),
HTTP: Rx.Observable.of(URL)
}
}
Cycle.run(main, {
DOM: makeDOMDriver('#appmount'),
HTTP: makeHTTPDriver()
});
What I'm trying to achieve is; load JSON data and render it as div tags for now.
When I run the code in chrome I get this in the console
bundle.js:14182 TypeError: Cannot read property 'subscribe' of undefined(…)
I have checked the questions found by stackoverflow, but they didn't get me ay further