6 ms·
Observable API Proposal
- Alifatisk 3y agoI like this!
- bpierre 3y agoSome context about the current status: https://twitter.com/domfarolino/status/1684921351004430336 https://twitter.com/domfarolino/status/1684921351004430336
- jwilber 3y agoWould absolutely love this.
- Eduard 3y agowhich programming language and / or platform ? Is it too obvious to mention it?
- frankfrank13 3y agoecmascript I have to assume
- bsimpson 3y agoTC39 (the JS standards body) and WHATWG (the web standards body) have been ping-ponging this back and forth between one another. I believe WHATWG is being favored so Observables will have a "killer app" (events) and could hence be built into the platform. As I recall, there was friction in TC39 to the effect of "RxJS exists. Why bother specifying this in the language?"
- badlucklottery 3y ago> "RxJS exists. Why bother specifying this in the language?" And, honestly, that's a great point. It's even easy to wrap EventTargets: fromEvent(target, 'eventName'). For the record: I'm a big fan of RxJS and have used it in production client-side code for several years. But even I'm not hot on this proposal to build it into the language.
- noelwelsh 3y agoI only skimmed the document but I didn't see any mention of glitches. If this hasn't been addressed I'm worried there hasn't been sufficient thought about the semantics of Observables. Glitches, and avoiding them in push systems, is addressed in Flapjax (2009): https://www.flapjax-lang.org/publications/ https://www.flapjax-lang.org/publications/ I also don't see why this needs to be part of Javascript when it can be adequately implemented in a library. Today's great idea is tomorrow's legacy.
- sippeangelo 3y agoWhat are Glitches?
- noelwelsh 3y agoGlitches are transient incorrect values due to delays in propagating values. Imagine a diamond pattern of reactive values like: a = 0, 1, 2, ... b = a c = a d = b + c d should be 0, 2, 4, ... but if, say, b updates and d sees this update before c updates then you can get incorrect values in d.
- aatd86 3y agoQuite interesting. How does one resolve this? Naive me would have d observe a and recalculate its value by recomputing b and c then. Other naive but complexity indulging me would store a dependency graph and use this graph to determine when one should wait for a value to update. Surely there must be an easier way?
- mappu 3y agoIf b, c, and d were lazily evaluated (pull-based) you would also avoid this issue,
- wlib 3y agoThe key is topological sorting of a dependency graph. This can be done implicitly by storing a reactive variable node’s depth once it is created, and just making sure that updates are enqueued in separate queues per depth. I have a somewhat small implementation that transparently batches updates with queueMicrotask in this library (bruh): https://github.com/Technical-Source/bruh/blob/a829af9df9405b906aca07f2dce24f25568b9ff8/packages/bruh/src/reactive/index.mjs#L37 https://github.com/Technical-Source/bruh/blob/a829af9df9405b...
- pwdisswordfishc 3y agoHow does it differ from <https://github.com/tc39/proposal-observable/ https://github.com/tc39/proposal-observable/>?
- TeffenEllis 3y agoControversial but brave take: I think adding this to JavaScript is a bad idea. It’s not that observables are inherently bad. It’s just that they produce some of the least intuitive code imaginable. I’ve never seen a codebase with observables where I didn’t question the engineering team’s technical motivations. The three horsemen of unmaintainable JavaScript have always been generators, RxJS, and Redux. I can’t quite find an accurate metaphor to describe my experience with these data design patterns, but the first that comes to mind is “Hollywood accounting.” It’s always the same hat trick. Take a straightforward task of single directional data flow and subdivide it up into a Haskellian map/reduce game of musical chairs. Don’t get me wrong, I understand the importance of having observability in data streams. But we already have them via the ReadableStream and TransformStream APIs. Combined with native proxies and we’re just about covered on the use-cases described in the examples section. I’m also suspect of the lack of insight in this explainer on why the two previous proposals were rejected. We need more concrete evidence of why an additional API should be the answer to the question of whether there are too many competing observable frameworks. This isn’t a jQuery or Bluebird Promises scenario where the observerable paradigm is so entrenched in contemporary engineering, or even that a sizable amount of software development would require a third-party library to fill in the gap. JavaScript has many missing features. This is not one of them.
- troupo 3y ago> It’s just that they produce some of the least intuitive code imaginable. The three horsemen of JavaScript have always been generators, RxJS, and Redux. It took the author of RxJava months to understand the concepts. And he had the author of Rx.Net to explain them to him [1] It's also strange is that what we realy want is Excel-like reativity. But instead we're always getting Rx-like reactivity. [1] From his book: https://pbs.twimg.com/media/C0M-U1DXcAADTS3?format=jpg&name=medium https://pbs.twimg.com/media/C0M-U1DXcAADTS3?format=jpg&name=...
- nwienert 3y agoA time ago I had a project where we had an intense tree-like data structure where at any given level there may be a finite async-stream. Basically recursively needed to await streams until they finished. I was using for RxDB based on RxJS, so after a couple nights of banging my head I went into the RxJS chat and asked for help. One of the maintainers of the library who worked at MS said it was a perfect problem and I think I nerd-baited him into helping out... ... we ended up spending like a week on it going back and forth, and neither of us could figure it out. The code we ended up with was frightening.
- pictur 3y agoWhat exactly will this benefit from?
- earthboundkid 3y agoShouldn't this just be like a two line utility function to turn a addEventListner call into an async iterable?
- imbnwa 3y agoLol first thing I did was Ctrl+F for async iterator
- _greim_ 3y agoWhy not have it return an async iterable, which has both push and pull semantics? Combined with the iterable helpers proposal you'd get a lot of things for free, including end-to-end backpressure.
- kavaruka 3y agojs does not need Observable API, it already had Async Iterables that soon will be enhanced with these helpers https://github.com/tc39/proposal-async-iterator-helpers https://github.com/tc39/proposal-async-iterator-helpers that are similar to this proposal
- abss 3y agoMy "observation" about observability and "reactive type" of code is that old school proxies, events and ways of defining expressions that get computed when the dependecies change is a much simpler way of programm reactive UIs (for example MVVM style of architectures) compared with a functional programming approach. Of course the naive approch does not work properly because any change in dependent values will trigger undesired side effects, reentrace, infinite loops, etc. However in a programming language like JavaScript if the observability is based on a Sound PubSub System these kind of problems reduce to becoming surpinsingly irelevant. If you want to undestand more about this, take a look on https://github.com/OpenDSU/soundpubsub/ https://github.com/OpenDSU/soundpubsub/ We used this approach to implement two ways binding and reactive MVVM web frameworks but this comment is to present this insight that it is possible to have a "procedural" and "spreadsheet like" method of implementing intuitive and sound rectivity without bending your mind with streams or anything very abstract. In a low code environment this could be essential.