-
Notifications
You must be signed in to change notification settings - Fork 170
Open
Description
Normal config files with context references looks like:
module.exports = {
title: 'teaser-list',
context: {
items: [
'@molecules-teaser',
'@molecules-teaser',
'@molecules-teaser',
]
}
}
The Problem I have in multiple projects is, that I couldn't extend the referenced object.
This wouldn't work:
const extendedTeaserContext = Object.assign('@molecules-teaser', { newVariable: 'lorem ipsum' })
I have two ideas to solve this problem.
Possible Solution 1: getContext Function
A function to convert a context reference into the object.
const extendedTeaserContext = Object.assign(getContext('@molecules-teaser'), { newVariable: 'lorem ipsum' })
Possible Solution 2: Post Context Generation Hook
A function to adjust the context after all references are resolved.
module.exports = {
title: 'teaser-list',
context: {
items: [
'@molecules-teaser',
'@molecules-teaser',
'@molecules-teaser',
]
},
postReferenceResolvedHook(context) {
const extendedItems = [];
for (const item of context.items) {
item.newVariable = 'lorem ipsum';
delete item.globalContextVariable;
extendedItems.push(item)
}
context.items = extendedItems;
return context;
}
}