feat: add parentConfig to extension context for more extendable extensions, fix #259

This commit is contained in:
Philipp Kühn
2021-04-12 11:11:02 +02:00
parent 8090bc63c1
commit 5e1ec5d2a6
12 changed files with 218 additions and 42 deletions

View File

@@ -0,0 +1,21 @@
import { AnyExtension, AnyObject } from '../types'
export default function createExtensionContext<T>(
extension: AnyExtension,
data: T,
): T & { parentConfig: AnyObject } {
const context = {
...data,
get parentConfig() {
return Object.fromEntries(Object.entries(extension.parentConfig).map(([key, value]) => {
if (typeof value !== 'function') {
return [key, value]
}
return [key, value.bind(context)]
}))
},
}
return context
}