Comments (9)
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!
from observer-util.
i am checking it. it might take some time for me to fully grasp it though 😉
from observer-util.
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?
from observer-util.
Yes, that's basically it. Thank you.
However, I was implementing it in a transparent way, without the need of the .value
property, by assigning streams to an object.
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 'observable-xstream'
would be much easier to implement.
from observer-util.
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.
from observer-util.
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 (;
from observer-util.
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
from observer-util.
sorry, i was busy during the weekend, i don't want to ruin your motivation/inspiration for this. is your fork public?
from observer-util.
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
- I've added a global WeakMap named
streamResults
for caching the "current" stream values. - On object initialization, for each property, and whenever a new property is added to an observable I call
function handleStream (stream) {
if (stream && typeof stream.subscribe === 'function') {
stream.subscribe({
next (v) {
streamResults.set(stream, v)
},
error (e) {
streamResults.set(stream, e)
}
})
}
}
- on the common
get
handler for objects, right aftervar result = Reflect.get(target, key, receiver)
I do
if (result.subscribe) {
result = streamResults.get(result)
}
from observer-util.
Related Issues (20)
- Mutating observables in reactions is forbidden HOT 2
- 4.2.0 broke something HOT 3
- Trap "toJSON" to allow serialization of proxies HOT 2
- Deeply observe object HOT 12
- Documentation suggestion HOT 2
- Is it possible to receive the type of change when observing a value? HOT 9
- Observables arrays don't appear to observe correctly HOT 3
- Question about scheduler batching and observe optimizations. HOT 2
- Problem when changing whole objects HOT 1
- Understanding reactions HOT 1
- Angular 7 Integration HOT 1
- Not sure I'm understanding this at all HOT 4
- Object.defineProperty should trigger reactions HOT 3
- computed properties no cache? HOT 3
- Observing through a Proxy HOT 2
- `construct` trap fails for observed constructors HOT 1
- Bug or user error? Copying observable to other position in array converts it to the raw item
- should observe explicit array length changes
- Shallow observing HOT 1
- rawToProxy WeakMap.set is never called
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from observer-util.