fix(system): allow wrapping components both from presets and plugins (#9919)
Refs #7232
This commit is contained in:
@@ -388,10 +388,6 @@ const MyWrapComponentPlugin = function(system) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**Note:**
|
|
||||||
|
|
||||||
If you have multiple plugins wrapping the same component, you may want to change the [`pluginsOptions.pluginLoadType`](/docs/usage/configuration.md#Plugins-options) parameter to `chain`.
|
|
||||||
|
|
||||||
#### `rootInjects`
|
#### `rootInjects`
|
||||||
|
|
||||||
The `rootInjects` interface allows you to inject values at the top level of the system.
|
The `rootInjects` interface allows you to inject values at the top level of the system.
|
||||||
|
|||||||
@@ -39,16 +39,9 @@ Read more about the plugin system in the [Customization documentation](/docs/cus
|
|||||||
Parameter name | Docker variable | Description
|
Parameter name | Docker variable | Description
|
||||||
--- | --- | -----
|
--- | --- | -----
|
||||||
<a name="layout"></a>`layout` | _Unavailable_ | `String="BaseLayout"`. The name of a component available via the plugin system to use as the top-level layout for Swagger UI.
|
<a name="layout"></a>`layout` | _Unavailable_ | `String="BaseLayout"`. The name of a component available via the plugin system to use as the top-level layout for Swagger UI.
|
||||||
<a name="pluginsOptions"></a>`pluginsOptions` | _Unavailable_ | `Object`. A Javascript object to configure plugin integration and behaviors (see below).
|
|
||||||
<a name="plugins"></a>`plugins` | _Unavailable_ | `Array=[]`. An array of plugin functions to use in Swagger UI.
|
<a name="plugins"></a>`plugins` | _Unavailable_ | `Array=[]`. An array of plugin functions to use in Swagger UI.
|
||||||
<a name="presets"></a>`presets` | _Unavailable_ | `Array=[SwaggerUI.presets.ApisPreset]`. An array of presets to use in Swagger UI. Usually, you'll want to include `ApisPreset` if you use this option.
|
<a name="presets"></a>`presets` | _Unavailable_ | `Array=[SwaggerUI.presets.ApisPreset]`. An array of presets to use in Swagger UI. Usually, you'll want to include `ApisPreset` if you use this option.
|
||||||
|
|
||||||
##### Plugins options
|
|
||||||
|
|
||||||
Parameter name | Docker variable | Description
|
|
||||||
--- | --- | -----
|
|
||||||
<a name="pluginLoadType"></a>`pluginLoadType` | _Unavailable_ | `String=["legacy", "chain"]`. Control behavior of plugins when targeting the same component with wrapComponent.<br/>- `legacy` (default) : last plugin takes precedence over the others<br/>- `chain` : chain wrapComponents when targeting the same core component, allowing multiple plugins to wrap the same component
|
|
||||||
|
|
||||||
##### Display
|
##### Display
|
||||||
|
|
||||||
<table role="table">
|
<table role="table">
|
||||||
|
|||||||
@@ -70,13 +70,6 @@ const defaultOptions = Object.freeze({
|
|||||||
// Plugins; ( loaded after presets )
|
// Plugins; ( loaded after presets )
|
||||||
plugins: [],
|
plugins: [],
|
||||||
|
|
||||||
pluginsOptions: {
|
|
||||||
// Behavior during plugin registration. Can be :
|
|
||||||
// - legacy (default) : the current behavior for backward compatibility – last plugin takes precedence over the others
|
|
||||||
// - chain : chain wrapComponents when targeting the same core component
|
|
||||||
pluginLoadType: "legacy",
|
|
||||||
},
|
|
||||||
|
|
||||||
initialState: {},
|
initialState: {},
|
||||||
|
|
||||||
// Inline Plugin
|
// Inline Plugin
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ const systemFactorization = (options) => {
|
|||||||
configs: options.configs,
|
configs: options.configs,
|
||||||
},
|
},
|
||||||
plugins: options.presets,
|
plugins: options.presets,
|
||||||
pluginsOptions: options.pluginsOptions,
|
|
||||||
state,
|
state,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,11 +55,6 @@ const mappings = {
|
|||||||
typeCaster: arrayTypeCaster,
|
typeCaster: arrayTypeCaster,
|
||||||
defaultValue: defaultOptions.plugins,
|
defaultValue: defaultOptions.plugins,
|
||||||
},
|
},
|
||||||
pluginsOptions: {
|
|
||||||
typeCaster: objectTypeCaster,
|
|
||||||
pluginsOptions: defaultOptions.pluginsOptions,
|
|
||||||
},
|
|
||||||
"pluginsOptions.pluginsLoadType": { typeCaster: stringTypeCaster },
|
|
||||||
presets: {
|
presets: {
|
||||||
typeCaster: arrayTypeCaster,
|
typeCaster: arrayTypeCaster,
|
||||||
defaultValue: defaultOptions.presets,
|
defaultValue: defaultOptions.presets,
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ export default class Store {
|
|||||||
deepExtend(this, {
|
deepExtend(this, {
|
||||||
state: {},
|
state: {},
|
||||||
plugins: [],
|
plugins: [],
|
||||||
pluginsOptions: {},
|
|
||||||
system: {
|
system: {
|
||||||
configs: {},
|
configs: {},
|
||||||
fn: {},
|
fn: {},
|
||||||
@@ -64,7 +63,7 @@ export default class Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
register(plugins, rebuild=true) {
|
register(plugins, rebuild=true) {
|
||||||
var pluginSystem = combinePlugins(plugins, this.getSystem(), this.pluginsOptions)
|
var pluginSystem = combinePlugins(plugins, this.getSystem())
|
||||||
systemExtend(this.system, pluginSystem)
|
systemExtend(this.system, pluginSystem)
|
||||||
if(rebuild) {
|
if(rebuild) {
|
||||||
this.buildSystem()
|
this.buildSystem()
|
||||||
@@ -311,21 +310,19 @@ export default class Store {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function combinePlugins(plugins, toolbox, pluginOptions) {
|
function combinePlugins(plugins, toolbox) {
|
||||||
if(isObject(plugins) && !isArray(plugins)) {
|
if(isObject(plugins) && !isArray(plugins)) {
|
||||||
return merge({}, plugins)
|
return merge({}, plugins)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isFunc(plugins)) {
|
if(isFunc(plugins)) {
|
||||||
return combinePlugins(plugins(toolbox), toolbox, pluginOptions)
|
return combinePlugins(plugins(toolbox), toolbox)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isArray(plugins)) {
|
if(isArray(plugins)) {
|
||||||
const dest = pluginOptions.pluginLoadType === "chain" ? toolbox.getComponents() : {}
|
|
||||||
|
|
||||||
return plugins
|
return plugins
|
||||||
.map(plugin => combinePlugins(plugin, toolbox, pluginOptions))
|
.map(plugin => combinePlugins(plugin, toolbox))
|
||||||
.reduce(systemExtend, dest)
|
.reduce(systemExtend, { components: { ...toolbox.getComponents() } })
|
||||||
}
|
}
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|||||||
@@ -187,14 +187,11 @@ describe("wrapComponents", () => {
|
|||||||
expect(children.eq(1).text()).toEqual("WOW much data")
|
expect(children.eq(1).text()).toEqual("WOW much data")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should wrap correctly when registering multiple plugins targeting the same component", function () {
|
it("should wrap component correctly when performing subsequent plugin registering targeting the same component", function () {
|
||||||
|
|
||||||
// Given
|
// Given
|
||||||
|
|
||||||
const mySystem = new System({
|
const mySystem = new System({
|
||||||
pluginsOptions: {
|
|
||||||
pluginLoadType: "chain"
|
|
||||||
},
|
|
||||||
plugins: [
|
plugins: [
|
||||||
() => {
|
() => {
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user