I’m thinking about how to better integrate Meteor with React, and have some thoughts. Here’s what I’d like to do, which will be followed up with some questions about how Meteor’s data system currently works.
- Build a sort of global stateful collection provider, kind of like Redux. React really needs data loading to happen asynchronously with rendering, and Meteor’s current hook implementation doesn’t make that easy. An easy solution is to just not make data available immediately, but that would suck for a lot of reasons. The better solution is to hoist the loading and management of data to a provider, and get it out of render methods entirely. Then data has high availability, and queries are available during render, and we can still make sure not to leak memory in render.
- Build subscription and cursor hooks that integrate more tightly in to react, and follow the rules of hooks very closely. Among other things, this will manage more clearly when subs are created and destroyed, but also use Cursors in React loops, so that individual documents changes in a list won’t update entire trees in react.
My questions are about how Meteor currently handles some of this stuff. I know that we can do
Meteor.subscribe() in a hook, and then briefly destroy the computation to remount it, and that doesn’t immediately remove all the data from the collection, but I’m not sure how that works. I guess I’m just looking for an overview of how Meteor’s merge-box works, particularly on the client side, and particularly how/when does it clean stuff up? Odd that I’ve never had to dig in to this - I guess that describes some of the strength of the platform, that I haven’t had to know how that works at a low level. But I do want to know now.