1.7.1 • Published 6 years ago
cycle-state v1.7.1
cycle-state
NOTICE: While this worked on a small scale, I've decided that it doesn't do enough. I've moved development to cycle-channel.
Create a stream of state for your view layer in cycle
Usage
Alright, so you've got a simple Cycle.js application built:
import xstream from "xstream"
function application (state) {
return p({
inner: `Hello, world! My nam e is ${state.author.name}`,
})
}
function cycle (sources) {
const state = sources.DOM.events("click")
const view = state.map(application)
return {
DOM: view,
}
}
const drivers = {
DOM: makeDOMDriver("body"),
}
run(cycle, drivers)
Here you're mapping click events into a state. Wouldn't it be cool if we could redux this bitch:
const intents = {
openModal: (state) => (event) => (payload) => {
return {
...state,
modal: true,
}
}
}
const initialState = {
openModal: false,
}
function cycle (sources) {
const state = cycleState(
intents
)(
initialState
)(
sources.DOM.events("click")
)
const view = state.map(application)
return {
DOM: view,
}
}