question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why not use event callbacks?

See original GitHub issue

Its 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:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
gaearoncommented, Jan 25, 2016

I just don’t understand how to you connect drivers.DOM.select(‘input’).events(‘click’) to the input thats eventually returned to the DOM driver. It seems pretty challenging or littered with mutations. Take React for example – how does the event handler get injected into the vdom before its rendered?

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.

1reaction
staltzcommented, Jan 25, 2016

Nowadays Cycle DOM also does event delegation.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found