Ivan Rodriguez
Ivan Rodriguez

Reputation: 11

cycle.js - is there a way to implement event handlers like in React?

I recently ran into Cycle.js, and, except for what I'm about to ask, I like the framework. Is there a way to implement event handlers directly on the DOM helper? Something like:

function main(sources) {
    //...
    const clickEvent$ = xstream.createSubject() // not a real function, I think
    const counter$ = clickEvent$.fold((counter, amount) => counter + amount, 0)
    const vdom$ = counter$.map(counter => div([
        p(['Counter: ', count]),
        button({
            on: { click: () => clickEvent$.emit(1) }
        },'+'),
        button({
            on: { click: () => clickEvent$.emit(-1) }
        },'-'),
    ]))
    //...
    return sinks
}

Or is a feature like React's event handlers being planned?

I know that the example is not (yet) possible, but if something like that gets implemented, component isolation would be a lot easier, and React devs could have minimal issues with using Cycle.js.

Upvotes: -1

Views: 43

Answers (1)

Jan van Brügge
Jan van Brügge

Reputation: 772

No, it is neither supported nor ever planned to be added. The whole point of the dom driver is to provide a declarative, stream based abstraction, not imperative onclick handlers

Upvotes: 0

Related Questions