-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I plug into the observation process? #12
Comments
It is starting to feel that I should create a fork of this repository just to implement my thing, but I don't like that idea. However, it is not clear how should I do it even in a fork. Please help! |
i am checking it. it might take some time for me to fully grasp it though 😉 |
If I understand correctly you would like to do something like this: import xs from 'observable-xstream'
const observableStream = xs.periodic(1000)
.filter(i => i % 2 === 0)
.map(i => i * i)
.endWhen(xs.periodic(5000).take(1))
// auto logs a number that increments every second from 1 to 5
observe(() => console.log(observableStream.value)) Is this roughly correct or am I totally off track? |
Yes, that's basically it. Thank you. However, I was implementing it in a transparent way, without the need of the import xs from 'xstream'
import observableStreams from 'observables-xstream'
const stream = xs.periodic(1000)
.filter(i => i % 2 === 0)
.map(i => i * i)
.endWhen(xs.periodic(5000).take(1))
var state = observableStreams({
number: stream
})
// auto logs a number that increments every second from 1 to 5
observe(() => console.log(state.number)) Looking now, I think that all my problems arise from that implementation and that your |
It gets worse when I remember that the values emitted by the stream may be objects or collections, even with others streams as values, and those should be observables too, just like the top object. |
No worries, nested observable construction is automatic in nx-js observer util. I have to work now but I will get back to this in the afternoon. I think it will be much simpler than it seems like (; |
Nested observables are automatic, but not in my special case if it requires a special function to turn streams into observable values. I'm counting on you to give me an awesome magical solution here :P |
sorry, i was busy during the weekend, i don't want to ruin your motivation/inspiration for this. is your fork public? |
You're not ruining anything. I don't know if my approach is solid and you have no responsibility for my incompetence. I've just found https://github.com/calmm-js/karet, that does something similar of what I wanted to do, without passing through the process of converting things to observables, they just make the component somehow listen to emitted values on the stream. The point is that I can't understand what they're doing there, much less than I could at observer-util or react-easy-state, it's pure magic. Anyway, what do you said you thought would be "much simpler"? You're talking about adding new features to this repository (for "plugging in"), or writing a wrapper around it? My "fork" is currently a mess of files in my local disk, but the only relevant changes are
function handleStream (stream) {
if (stream && typeof stream.subscribe === 'function') {
stream.subscribe({
next (v) {
streamResults.set(stream, v)
},
error (e) {
streamResults.set(stream, e)
}
})
}
}
if (result.subscribe) {
result = streamResults.get(result)
} |
I want to take a bunch of observable/streams (like RxJS, I don't know the exact name of those) and pass them to a function that will return an
observable
that will have all their last emitted values stored, and every time one of those observable/streams emit something that will update theobservable
and trigger updates accordingly toobservers
.This seemed like a simple thing to do, but I'm somehow seeing a lot of unexpected errors.
There's a lot of complication here because I had to introduce
initialValue
, which wasn't needed when I was trying to build this from scratch without usingProxy
or@nx-js/observer-util
(in my previous implementation the observers were only triggered when the streams emitted their first values, but now they're triggered before that.)I'm just looking for some help, but if there was a way to "intercept" values before
get
I think it would solve it to me.The text was updated successfully, but these errors were encountered: