Live data from Hacker News

Cycle.js – A functional and reactive JavaScript framework for predictable code

cycle.js.org

51–60 of 64 posts

Re: Cycle.js – A functional and reactive JavaScript framework for predictable code

#51
post #49

Earlier quoted context omitted.

I suppose you were using Cycle.js before Cycle State was released No, I was using cycle state/onionify. [cycle-js] is not a competitor to React That's not the impression you give in this article: https://staltz.com/some-problems-with-react-redux.html React may be superior in ecosystem, or with feature coverage, but not so as a paradigm [compared to cycle-js]... Once you learn Elm or Cycle, getting things done will be…

That article was written many months/years before Cycle-React interop was built. I still maintain some of those positions because of Redux, but when you take React without Redux, it's just a rendering library, and as such could be theoretically used with Cycle.js. Now that React has good APIs like Context, ForwardRef, and function components, the interop with Cycle.js is easy and well done.

FWIW I agree with you I'm not enamoured by react/redux.

Re: Cycle.js – A functional and reactive JavaScript framework for predictable code

#52
post #36

"const input$ = sources.DOM.select('.field').events('input')" Is there a switchMap in here? What happens if the input element is removed/inserted back into the DOM? "input('.field', {attrs: {type: 'text'}})," It's possible right now for the value in this input to differ from the value in input$. Maybe use a combineLatest and then this? "input('.field', {attrs: {type: 'text', value: inputVal}}),"

`select().event()` does not use `querySelector` directly under the hood, it filtering and routing all incoming events accordingly. So even if you change the elements, as long as they match the selector, they will be routed correctly. Source: I recently rewrote the DOM driver :)

Re: Cycle.js – A functional and reactive JavaScript framework for predictable code

#53
post #48

Earlier quoted context omitted.

It's misleading to say observables are not asynchronous. The raison d'etre of obserables is to support asynchronous operations, and it's this capability that constrains the programming model. To quote Erik Meijer - the godfather of observables - in this article https://queue.acm.org/detail.cfm?id=2169076 There are many ways to derive Rx, some involving category theory and appealing to mathematical duality, but this a…

I didn't say "observables are not asynchronous", I was referring to the comment "interactions between components are asynchronous" which to me sounds like "event emission and propagation". Propagation is often synchronous when using RxJS 6 which uses by default the recursive scheduler, and with xstream, which is similar. For instance, event emissions along the chain a$.map (f).filter(g).take(10) are synchronous. But…

With observables, they can be executed synchronously or asynchronously in JS, but it's a bit of a leaky abstraction when you have to be aware of the internals of particular stream operation to known whether it is synchronous or not, so to avoid unnecessary complexity you need to assume asynch behavior for all streams.

Re: Cycle.js – A functional and reactive JavaScript framework for predictable code

#54

I am definitely an advocate for reactive programming, as I have used React Native to develop a cross-platform mobile application ( https://dedicate.datasilk.io ), but when it comes to web development, I am very much an advocate for using the basic tools that were given to us web developers to build web applications. These tools include mainly HTML & CSS, and when needed, "vanilla" JavaScript (and maybe even a compact…

I’ve been writing single-page apps for about 4 years now, and somewhat agree with your sentiment.

Lately I’ve been experimenting with Jekyll and Vue. The approach is not perfect but it’s a lot closer to the simplicity of the old-school approach you are preaching.

Re: Cycle.js – A functional and reactive JavaScript framework for predictable code

#55

I am definitely an advocate for reactive programming, as I have used React Native to develop a cross-platform mobile application ( https://dedicate.datasilk.io ), but when it comes to web development, I am very much an advocate for using the basic tools that were given to us web developers to build web applications. These tools include mainly HTML & CSS, and when needed, "vanilla" JavaScript (and maybe even a compact…

This is an unnecessarily absolutist position. If HTML, CSS and JavaScript are a "near-perfect solution to a very complex, graphically interactive problem", then why did people come up with front-end frameworks in the first place? Because they're useful! Frontend developers aren't just cargo culting their architecture decisions; they're trying to finding that the benefits outweigh the downsides, particularly with comp…

No single approach covers all use cases, but a real problem is that single-page apps have been overused.

It makes sense for something like Trello or Gmail, but using the same approach on every project is a mistake.

Re: Cycle.js – A functional and reactive JavaScript framework for predictable code

#56

I've used cycle.js on a small commercial project. I'm drawn to novel non-mainstream approaches, and am happy to put up with teething pains with new technology. However, my experience with cycle.js was such that I couldn't recommend the framework to others. Central to the understanding of cycle.js is the concept of observables. An observable is powerful abstraction, as it allows event streams to be programmable. Howev…

Every framework or tool will go out of its way to demonstrate the things it makes easy. They usually don't mention at all the things it makes hard. Often you don't discover what those are until you've tried building something non-trivial with it, but there are always tradeoffs.

Re: Cycle.js – A functional and reactive JavaScript framework for predictable code

#57

I've used cycle.js on a small commercial project. I'm drawn to novel non-mainstream approaches, and am happy to put up with teething pains with new technology. However, my experience with cycle.js was such that I couldn't recommend the framework to others. Central to the understanding of cycle.js is the concept of observables. An observable is powerful abstraction, as it allows event streams to be programmable. Howev…

What do you mean that all interactions between components are asynchronous?

I've built and am maintaining a rather large chrome extension for video recording using xstream/cyclejs.

I find that the thing xstream get exactly right is that stream is an abstraction of Values Over Time and not a queue of messages.

It's a subtle but important distinction. xstream and by consequence cyclejs is synchronous. When a value goes into the stream, all interconnected streams ar executed synchronously.

Re: Cycle.js – A functional and reactive JavaScript framework for predictable code

#58
post #49

Earlier quoted context omitted.

That article was written many months/years before Cycle-React interop was built. I still maintain some of those positions because of Redux, but when you take React without Redux, it's just a rendering library, and as such could be theoretically used with Cycle.js. Now that React has good APIs like Context, ForwardRef, and function components, the interop with Cycle.js is easy and well done.

FWIW I agree with you I'm not enamoured by react/redux.

redux-observable has helped me get some of the better parts I liked about Cycle into a more "traditional" React app setup.

For maintainability by other developers I've been migrating my biggest Cycle app into a "traditional" React app. Partly because I got very caught up into some "plumbing" issues in Cycle, with lots of dynamic components and keeping them performative starting being far too much work, especially if I expected other developers to read it, much less touch it. The Cycle/React-interop has gotten better so that I might contemplate React-hosted Cycle components for future needs, but at this point with the vast React ecosystem and increasing Junior Developer-friendliness of "traditional" React, it makes the most sense to just use as much off-the-shelf React as possible and Redux seems familiar to more developers (even if they might not immediately get what redux-observable "epics" are doing).

Re: Cycle.js – A functional and reactive JavaScript framework for predictable code

#60
This is interesting feedback. There are obviously subjective parts in it, but that's valuable all the same.

Focusing on the objective parts :

  An observable is powerful abstraction, as it allows event streams to be programmable. However, an overreached abstraction can be even worse than a lack of abstraction. Cycle.js gratuitously applies the observable abstraction to its component model.

Some caveats aside, cyclejs allows you :

- to express your app as a series of equations

- separate side-effects from pure dataflow processing

Whether that is gratuitous or overreached is a question of taste, familiarity and other things, I won't discuss with you on that.

What I will say is that under some conditions, the cyclejs approach actually can make your application much easier to understand that standard imperative workflow processing. For instance, I could write for a super simplified reservation system :

- screen `=def=` booking_details_screen + booking_feedback_screen

- booking_feedback_screen `=def=` is_ok(booking_response) ? nothing : display_errors(booking_feedback_screen)

- booking_details_screen `=def=` whatever interface you want

- book_button_click `

- flight `=def=` read_flight (booking_details_screen)

- booking_request `=def=` makeBookingRequest(flight) sampled by book_button_click

- booking_response `The `=def=` relations are equations which are always true. the `On another note, as you can see from the equations, there is no notions of component. Or if you prefer a component is a variable on the leftside of the equations. So for instance screen is a component with two children components.

That is the underlying theory. In practice:

- code does not get written as a list of equations, but through doing some juggling with streams operators. Nothing of the other world really, but there is certainly a ceremony to it, and tips, tricks, gotchas to be aware of.

- Cycle actually does not have a component model stricto sensu. A component model should at least provide a systematic way to combine components into a hierarchy, i.e. a `combine` function by which `parentComponent` = combine(childrenComponents)`. For instance in React, `reactElement = React.createElement(parentComponent, props, childrenComponents)`. With `cyclejs` you must explicitly write your `combine` function yourself, everytime. That represent probably a portion of the pain you felt.

But conversely look at the other approach. Let's imagine a `ParentComponent` with two child components. To reason about your application, you need to know about the end-to-end sequence of operations involved in all the framework's API. So for instance: `render = render Parent -then-> call onRender of Parent -then-> render Child1 -then-> fetch data -then-> render Child2 -then-> etc.`. This is obviously possible, that is how React works and your own proposed framework too - by the way you do not offer a component model either, stricto sensu). Nothing of the other world really, but there is certainly a ceremony to it, and tips, tricks, gotchas to be aware of (yes I copy pasted from before).

So in short, your evaluation of how bad the ceremony is, the effort it involves etc. will obviously include factors which are specific to you. So I am not doubting your feedback. My whole point here is to say that your mileage may vary and that there is no a priori superiority of one approach over another (stuff like `realizing the appropriate abstraction` as you mention in your post). There are real pain points both ways and what is appropriate to you might be in part the result of a higher familiarity with one approach over another.

If you want to understand what I mean by component model, or want to see what a component model for cyclejs look like, I created my cyclejs component model to address some of the pain points you probably encountered : cf. https://brucou.github.io/posts/a-componentization-framework-...

Post reply on HN