Skip to content

Commit

Permalink
fix(system): allow wrapping components both from presets and plugins (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
char0n committed May 7, 2024
1 parent 6ae2c1f commit 877470b
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 36 deletions.
4 changes: 0 additions & 4 deletions docs/customization/plugin-api.md
Expand Up @@ -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`

The `rootInjects` interface allows you to inject values at the top level of the system.
Expand Down
7 changes: 0 additions & 7 deletions docs/usage/configuration.md
Expand Up @@ -39,16 +39,9 @@ Read more about the plugin system in the [Customization documentation](/docs/cus
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="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="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

<table role="table">
Expand Down
7 changes: 0 additions & 7 deletions src/core/config/defaults.js
Expand Up @@ -70,13 +70,6 @@ const defaultOptions = Object.freeze({
// Plugins; ( loaded after presets )
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: {},

// Inline Plugin
Expand Down
1 change: 0 additions & 1 deletion src/core/config/factorization/system.js
Expand Up @@ -37,7 +37,6 @@ const systemFactorization = (options) => {
configs: options.configs,
},
plugins: options.presets,
pluginsOptions: options.pluginsOptions,
state,
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/core/config/type-cast/mappings.js
Expand Up @@ -55,11 +55,6 @@ const mappings = {
typeCaster: arrayTypeCaster,
defaultValue: defaultOptions.plugins,
},
pluginsOptions: {
typeCaster: objectTypeCaster,
pluginsOptions: defaultOptions.pluginsOptions,
},
"pluginsOptions.pluginsLoadType": { typeCaster: stringTypeCaster },
presets: {
typeCaster: arrayTypeCaster,
defaultValue: defaultOptions.presets,
Expand Down
13 changes: 5 additions & 8 deletions src/core/system.js
Expand Up @@ -35,7 +35,6 @@ export default class Store {
deepExtend(this, {
state: {},
plugins: [],
pluginsOptions: {},
system: {
configs: {},
fn: {},
Expand Down Expand Up @@ -64,7 +63,7 @@ export default class Store {
}

register(plugins, rebuild=true) {
var pluginSystem = combinePlugins(plugins, this.getSystem(), this.pluginsOptions)
var pluginSystem = combinePlugins(plugins, this.getSystem())
systemExtend(this.system, pluginSystem)
if(rebuild) {
this.buildSystem()
Expand Down Expand Up @@ -311,21 +310,19 @@ export default class Store {

}

function combinePlugins(plugins, toolbox, pluginOptions) {
function combinePlugins(plugins, toolbox) {
if(isObject(plugins) && !isArray(plugins)) {
return merge({}, plugins)
}

if(isFunc(plugins)) {
return combinePlugins(plugins(toolbox), toolbox, pluginOptions)
return combinePlugins(plugins(toolbox), toolbox)
}

if(isArray(plugins)) {
const dest = pluginOptions.pluginLoadType === "chain" ? toolbox.getComponents() : {}

return plugins
.map(plugin => combinePlugins(plugin, toolbox, pluginOptions))
.reduce(systemExtend, dest)
.map(plugin => combinePlugins(plugin, toolbox))
.reduce(systemExtend, { components: { ...toolbox.getComponents() } })
}

return {}
Expand Down
5 changes: 1 addition & 4 deletions test/unit/core/system/wrapComponent.jsx
Expand Up @@ -187,14 +187,11 @@ describe("wrapComponents", () => {
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

const mySystem = new System({
pluginsOptions: {
pluginLoadType: "chain"
},
plugins: [
() => {
return {
Expand Down

0 comments on commit 877470b

Please sign in to comment.