Skip to content
This repository has been archived by the owner on Oct 24, 2021. It is now read-only.

Using minimongo as a reactive variable #78

Closed
mitar opened this issue Oct 31, 2015 · 3 comments
Closed

Using minimongo as a reactive variable #78

mitar opened this issue Oct 31, 2015 · 3 comments

Comments

@mitar
Copy link
Contributor

mitar commented Oct 31, 2015

One pattern I think we should suggest to people and I have seen it rarely documented is to use local minimongo collections as a reactive state variable. So instead of using reactive vars or dicts even better is to use local minimongo. You can query stuff on it, you can limit reactivity very precisely to a field you care about and so on. And also it forces you to store data in a EJSON-compatible way and not as complex JavaScript objects you can store into reactive variables which improves reactivity (by default reactive variables have equality defined which makes all references different), and also I think it improves communication between various parts of the code better because you do not have some hidden state inside of a JavaScript object but clearly serialized into local Minimongo collection.

So, we should encourage people to do so and do not be scared of this pattern. Sometimes it feels a bit too big, but I think it is better than some temporary local arrays and stuff like that. And then you have to patch reactivity on top of it.

@tmeasday
Copy link
Contributor

tmeasday commented Nov 2, 2015

I think so too. See: https://github.com/meteor/guide/blob/master/outlines/data-loading.md 5.ii.c

I suppose whacking one on a component is also a possibility but I'd be inclined to do that only in special cases (for instance if you want to do a "click here to see changes" UX pattern for a list, where the component would include this.visibilePosts and this.data.posts, and sync the two on click).

@stubailo
Copy link
Contributor

stubailo commented Nov 2, 2015

This seems related to #79, and seems like it would go nicely in a guide about client-side reactivity, Tracker, etc.

@tmeasday
Copy link
Contributor

tmeasday commented Apr 6, 2016

Let's put this in #234 maybe

@tmeasday tmeasday closed this as completed Apr 6, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants