VulcanJS / Vulcan

🌋 A toolkit to quickly build apps with React, GraphQL & Meteor
http://vulcanjs.org
MIT License
7.98k stars 1.89k forks source link

Before populate/ after populate hook to allow adding route in Meteor.startup #2404

Closed eric-burel closed 5 years ago

eric-burel commented 5 years ago

Hi,

Currently we can't addRoute in a Meteor.startup call, because we can't guarantee the call to addRoute is made before we populate the Routes object. So if addRoute is called after the populate call, they are ignored.

So far I think the best solution is to add new callbacks, populate.routes.before and populate.components.before that are guaranteed to run before those calls, in start.jsx. This way we can be sure that addRoute is correctly called.

We could also review whether populating is still necessary and why.

This is needed to implement the automated backoffice https://github.com/VulcanJS/Vulcan/issues/2176

eric-burel commented 5 years ago

@SachaG However I don't get why this need calls to populate for components and routes, but not for Collections for example? Couldn't the Routes object be always "ready" somehow, like Collections ?

Maybe getComponent is obsolete now HOCs can work without the fragment being initialized first.

eric-burel commented 5 years ago

For routes it's because we need childRoutes to be populated. I think we could just get those routes dynamically every times we iterate on Routes (it's actually called only once in start.jsx). Edit: I confirm getting routes dynamically Routes using a getRoutes function does the trick, without adding more complexity. I'll PR that.

eric-burel commented 5 years ago

I've ended up adding a more generic startup.before callback. We can put any operation that needs to be ran before routes and components population, as well as the initial rendering, eg adding routes dynamically, see the PR.