Hello everyone!
Great news for those still migrating to Meteor 3 and blocked by peerlibrary:reactive-publish
.
nachocodoner:reactive-publish is the modern version with async support. This package is an alternative to reywood:publish-composite
. Feel free to use this solution to publish composite data.
I decided to revive it, since I use it in my Meteor 2 hobby apps. With the core updated and modern tools arriving, I found time to move my apps to Meteor 3 over last months. The last hurdle was peerlibrary:reactive-publish
. You can read about why I keep using it here.
The package is now in alpha and the full test suite passes . I’ve integrated it into my apps, and all tests are green. I’ll release a beta once I confirm that Meteor core tests aren’t affected by the changes to core publish and other modules, but so far both package tests and my app tests pass.
I’d appreciate feedback from anyone who needs it or wants to try it. Are your tests passing? I published early to address the requests from Reactive publish using async collection functions.
Hands on
meteor add nachocodoner:reactive-publish@1.0.0-alpha.2
Basic usage
The package makes any changes in your queries inside an autorun
block publish updated data reactively, even for linked collections.
Because of isomorphism and minimongo, you can reuse the same code on client and server. This keeps your query logic unified, one of the main benefits over publish-composite.
Meteor.publish('subscribed-posts', function () {
this.autorun(async () => {
const user = await User.findOneAsync(this.userId, {
fields: { subscribedPosts: 1 },
});
return Posts.find({ _id: { $in: user?.subscribedPosts || [] } });
});
});
In the example above, you publish the user’s subscribed posts. When the User’s subscribedPosts
field changes, autorun reruns and publishes the updated posts. Any queries with related data work the same way. You can also publish an array of cursors and use the same logic as in a normal publication body.
The package and more details are on GitHub: nachocodoner:reactive-publish
Roadmap
Current version: 1.0.0-alpha.2. I’ll update this post with future releases.
-
Stability
- Ensure core changes in this package don’t affect Meteor core tests
- Release betas and RCs, with a feedback period for early adopters
-
Expansion
- Support for
AsyncTracker
andReactiveVarAsync
on the client - Migrate
peerlibrary:subscription-data
to support publishing derived data reactively
- Support for
-
Performance
- Run benchmarks to identify performance improvement opportunities
- Compare results with
reywood:publish-composite
to ensure equal or better behavior
Keep going with Meteor 3 and building cool apps!