From e2fe2ce5569485576250ed5cdfff8eae4be7b978 Mon Sep 17 00:00:00 2001 From: ochicf Date: Fri, 27 Jul 2018 10:16:56 +0200 Subject: [PATCH 1/2] initalizeFragments can now be parametrized with fragments to initialize --- packages/vulcan-lib/lib/modules/fragments.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/vulcan-lib/lib/modules/fragments.js b/packages/vulcan-lib/lib/modules/fragments.js index aea8f34e08..7e016efeb6 100644 --- a/packages/vulcan-lib/lib/modules/fragments.js +++ b/packages/vulcan-lib/lib/modules/fragments.js @@ -188,10 +188,18 @@ export const getFragmentText = fragmentName => { /* +Get names of non initialized fragments. + +*/ +export const getNonInitializedFragmentNames = () => + _.keys(Fragments).filter(name => !Fragments[name].fragmentObject); + +/* + Perform all fragment extensions (called from routing) */ -export const initializeFragments = () => { +export const initializeFragments = (fragments = getNonInitializedFragmentNames()) => { const errorFragmentKeys = []; @@ -207,7 +215,7 @@ export const initializeFragments = () => { // create fragment objects // initialize fragments *with no subfragments* first to avoid unresolved dependencies - const keysWithoutSubFragments = _.filter(_.keys(Fragments), fragmentName => !Fragments[fragmentName].subFragments); + const keysWithoutSubFragments = _.filter(fragments, fragmentName => !Fragments[fragmentName].subFragments); _.forEach(keysWithoutSubFragments, fragmentName => { const fragment = Fragments[fragmentName]; fragment.fragmentObject = getFragmentObject(fragment.fragmentText, fragment.subFragments) From 65cc9e0b38d04938f0af3e42e2736f2cd40426be Mon Sep 17 00:00:00 2001 From: ochicf Date: Fri, 27 Jul 2018 10:17:53 +0200 Subject: [PATCH 2/2] initialize fragment when trying to retrieve it for the first time --- packages/vulcan-lib/lib/modules/fragments.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vulcan-lib/lib/modules/fragments.js b/packages/vulcan-lib/lib/modules/fragments.js index 7e016efeb6..f511e5236f 100644 --- a/packages/vulcan-lib/lib/modules/fragments.js +++ b/packages/vulcan-lib/lib/modules/fragments.js @@ -167,7 +167,7 @@ export const getFragment = fragmentName => { throw new Error(`Fragment "${fragmentName}" not registered.`); } if (!Fragments[fragmentName].fragmentObject) { - throw new Error(`Fragment "${fragmentName}" registered, but not initialized.`) + initializeFragments([fragmentName]); } // return fragment object created by gql return Fragments[fragmentName].fragmentObject;