
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
cycle-redux
Advanced tools
If you are familiar with Redux and Cycle.js, you already know how this works.
First we include the necessary modules.
import makeStateDriver from "cycle-redux"
import { run } from "@cycle/core"
import { div, button, p } from "@cycle/dom"
Then we create our reducer. This is a very simple one, but you could also combine multiple reducers using redux's combineReducers
function.
// This is a reducer
function counter(state = 0, action) {
switch(action.type) {
case "INCREMENT":
return state + 1
case "DECREMENT":
return state - 1
default:
return state
}
}
Here we create our main method. Notice how each click-event maps to a state action, which changes the state, which then changes the DOM.
function main(sources) {
// Create increment action stream.
const increment$ = sources.DOM
.select(".increment")
.events("click")
.map(e => ({type: "INCREMENT"}))
// Create decrement action stream.
const decrement$ = sources.DOM
.select(".decrement")
.events("click")
.map(e => ({type: "DECREMENT"}))
// Merge the two action streams.
const state$ = increment$.merge(decrement$)
// Create virtual DOM tree.
const vtree$ = sources.state
.map(count => (
div([
button(".decrement", "Decrement"),
button(".increment", "Increment"),
p("Counter: " + count)
])
))
// Return virtual DOM and action stream
return {
DOM: vtree$,
state: state$
}
}
At last, we run our app.
The makeStateDriver
function takes a reducer and an optional initial state. Here we start with 1.
run(main, {
DOM: makeDOMDriver(document.getElementById("app")),
state: makeStateDriver(counter, 1)
})
FAQs
Unofficial Redux bindings for Cycle.js.
The npm package cycle-redux receives a total of 2 weekly downloads. As such, cycle-redux popularity was classified as not popular.
We found that cycle-redux demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.