Skip to content
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

Observable.proxy idea #15

Open
pkieltyka opened this issue May 20, 2021 · 2 comments
Open

Observable.proxy idea #15

pkieltyka opened this issue May 20, 2021 · 2 comments

Comments

@pkieltyka
Copy link

I have a scenario where I have an object that I'd like to turn into a micro-observable so I can use with the rest of observable state in the project.

I initially thought I could use Observable.compute(), but of course this is to compute only other structures already represented as an Observable value from micro-observables.

How about the idea of adding a Observable.proxy or Observable.wrap method, which could use the Proxy API to listen for changes in these situations?

@simontreny
Copy link
Collaborator

simontreny commented May 21, 2021

Hi Peter!

Thanks for the very interesting idea! Personally, I'm not fond of the Proxy API as I think it adds too much implicitness and it makes it hard to track the code that mutates observables and that could trigger side-effects (e.g. re-rendering of components, writing to storage).

I have the idea to integrate Immer into Micro-observables to make it easier to update complex objects, without having to rely on complex spread operators. That would basically work like this:

const person = observable({
   firstName: "Steve",
   children: ["Mary"]
});

person.mutate(p => {
   p.firstName = "Tim";
   p.children.push("Oliver");
});

Do you think it could work for your use case? If not, could you tell me more about what you are trying to do?

@otaviomad
Copy link

+1 for the Immer integration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants