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
feat: afterSourcesLoaded hook #1497
base: master
Are you sure you want to change the base?
Conversation
…verything is created
…verything is created
Thanks, @mklueh. Having a hook after the sources have loaded seems like a good idea :) Should we name it I'm not sure when we'll publish the next version yet, unfortunately. But in the meanwhile, you can try something like this in your module.exports = (api) => {
const { hooks, store } = api._app
hooks.bootstrap.tapPromise({ name: 'YourHookName', before: 'createSchema' }, async () => {
const collection = store.getCollection('YourCollection')
})
} |
Good point, but would you rather agree with
Is something blocking new releases currently? I feel like minor changes like this one should be able to be pushed to master more frequently and released more often.
That's good to know, I'll try that. Thank you :) |
I´ve renamed it now, however I cannot test it anymore locally for whatever reason. Autocompletion of the function name works in IntelliJ, but I´m running into this issue
Reverting the renaming now leads to the same issue. I think I did everything as mentioned in the contribution guide, created two projects in /projects, test and test2 with different starters. did Am I missing something? I mean two days ago the hook worked, and now it´s not found anymore. I also did unlink, yarn install --force etc |
Hi @hjvedvik , This does unfortunately not work.
the hook is not available and I get I´m also not sure how, if this would work the hook is called. Would that be done automatically because of the 'before' property? |
What I was trying to achieve was connecting collection entries of two sources with each other, based on certain fields.
However, using the
getCollection
action in theloadSources
hook for this case won´t work, as the collections from the source plugins aren´t loaded before, but afterwards and getCollection always returns 'undefined'.To solve this, I´ve created a new hook, called
afterSourcesLoaded
which is called after all source plugins have fetched their data and created their corresponding collections. You can do manipulation on all available data (that is loaded with the data store api).Although it is working as expected, I´m not sure if it´s done correctly. For example I´ve used the BOOTSTRAP_SOURCES phase twice, not sure if it has side effects in some way.
Also, the createSchemaActions(api, this._app) is called from loadSources and afterSourcesLoaded. Consequences if any?
BTW: Is there any date specified for the next Gridsome release? I have no idea how I can use my changes in production (CI build) without using the NPM releases