Why not use event callbacks?
See original GitHub issueIts an interesting choice how drivers work in Cycle. I’m curious why you didn’t stick with the whole “callback” style of registering events. This would make it easier to build drivers and to integrate with other libraries.
I think this example maintains the spirit of Cycle, but allows you to use React (and React Native) and entirely deals away with the the issue of isolation (isolateSink and isolateSource).
import {stream, scan} from 'flyd'
import lift from 'flyd/module/lift'
import h from 'react-hypersrcipt'
const counter = (props$) => {
const action$ = stream()
const state$ = scan(add, 0, action$)
const inc = () => action$(+1)
const dec = () => action$(-1)
const view = (props, state) => {
return h('div', props, [
h('button', {onClick: dec}, '-'),
h('span', state),
h('button', {onClick: inc}, '+')
])
}
return {
html$: list(view, props$, state$),
count$: state$
}
}
The way the current DOM driver works (binding actions before creating the DOM), makes me think that they’re may be certain dynamic interfaces that couldnt be created.
Anyways, I’m curious about your thoughs on this decision.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:12 (4 by maintainers)
Top Results From Across the Web
Difference between event handlers and callbacks
Callback is for asking another function to do business operations and send a result whereas events are not but asking for handover ...
Read more >Callbacks vs Event handlers (Example) | Treehouse Community
Callbacks methods do not need to be associated with events. In fact, generally speaking, when someone uses the term callback, they are referring ......
Read more >Events Are Not Call Backs - C2 wiki
The 'observer' pattern is a communications pattern, and the use of the callback (or 'event method') is just a mechanism to 'send' a...
Read more >Defining behavior with event callbacks and listeners
A script can use this method to generate events in the controls of a window, as if a user was clicking buttons, entering...
Read more >Events and Callbacks - HTML Dog
Events occur when the page loads, when user interacts (clicks, hovers, changes) and myriad other times, and can be triggered manually too. To...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m not a Cycle expert but I wanted to make clear that even React does not actually “inject handlers into vdom”. It is usually bad for performance to attach many event handlers, so under the hood React just registers component handlers in a map by the internal component ID, and only sets up a single event handler at the root of React hierarchy. This is similar to the event delegation approach that has long been used in Backbone and jQuery. I think in some cases React might actually subscribe to the node in question (depends on the event and browser quirks) but more often I think (it’s best if you verify!) it subscribes to the root node.
Nowadays Cycle DOM also does event delegation.