-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
288 additions
and
284 deletions.
There are no files selected for viewing
27 changes: 0 additions & 27 deletions
27
.../development/core/public/kibana-plugin-public.contextcontainer.createhandler.md
This file was deleted.
Oops, something went wrong.
76 changes: 0 additions & 76 deletions
76
docs/development/core/public/kibana-plugin-public.contextcontainer.md
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
...evelopment/core/public/kibana-plugin-public.contextcontainer.registercontext.md
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
docs/development/core/public/kibana-plugin-public.contextprovider.md
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...development/core/public/kibana-plugin-public.icontextcontainer.createhandler.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IContextContainer](./kibana-plugin-public.icontextcontainer.md) > [createHandler](./kibana-plugin-public.icontextcontainer.createhandler.md) | ||
|
||
## IContextContainer.createHandler() method | ||
|
||
Create a new handler function pre-wired to context for the plugin. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
createHandler(pluginId: string, handler: IContextHandler<TContext, THandlerReturn, THandlerParameters>): (...rest: THandlerParameters) => Promisify<THandlerReturn>; | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| pluginId | <code>string</code> | The plugin ID for the plugin that registers this handler. | | ||
| handler | <code>IContextHandler<TContext, THandlerReturn, THandlerParameters></code> | Handler function to pass context object to. | | ||
|
||
<b>Returns:</b> | ||
|
||
`(...rest: THandlerParameters) => Promisify<THandlerReturn>` | ||
|
||
A function that takes `THandlerParameters`<!-- -->, calls `handler` with a new context, and returns a Promise of the `handler` return value. | ||
|
76 changes: 76 additions & 0 deletions
76
docs/development/core/public/kibana-plugin-public.icontextcontainer.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IContextContainer](./kibana-plugin-public.icontextcontainer.md) | ||
|
||
## IContextContainer interface | ||
|
||
An object that handles registration of context providers and configuring handlers with context. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export interface IContextContainer<TContext extends {}, THandlerReturn, THandlerParameters extends any[] = []> | ||
``` | ||
|
||
## Methods | ||
|
||
| Method | Description | | ||
| --- | --- | | ||
| [createHandler(pluginId, handler)](./kibana-plugin-public.icontextcontainer.createhandler.md) | Create a new handler function pre-wired to context for the plugin. | | ||
| [registerContext(pluginId, contextName, provider)](./kibana-plugin-public.icontextcontainer.registercontext.md) | Register a new context provider. | | ||
|
||
## Remarks | ||
|
||
A [IContextContainer](./kibana-plugin-public.icontextcontainer.md) can be used by any Core service or plugin (known as the "service owner") which wishes to expose APIs in a handler function. The container object will manage registering context providers and configuring a handler with all of the contexts that should be exposed to the handler's plugin. This is dependent on the dependencies that the handler's plugin declares. | ||
|
||
Contexts providers are executed in the order they were registered. Each provider gets access to context values provided by any plugins that it depends on. | ||
|
||
In order to configure a handler with context, you must call the [IContextContainer.createHandler()](./kibana-plugin-public.icontextcontainer.createhandler.md) function and use the returned handler which will automatically build a context object when called. | ||
|
||
When registering context or creating handlers, the \_calling plugin's id\_ must be provided. Note this should NOT be the context service owner, but the plugin that is actually registering the context or handler. | ||
|
||
```ts | ||
// GOOD | ||
class MyPlugin { | ||
private readonly handlers = new Map(); | ||
|
||
setup(core) { | ||
this.contextContainer = core.context.createContextContainer(); | ||
return { | ||
registerContext(pluginId, contextName, provider) { | ||
this.contextContainer.registerContext(pluginId, contextName, provider); | ||
}, | ||
registerRoute(pluginId, path, handler) { | ||
this.handlers.set( | ||
path, | ||
this.contextContainer.createHandler(pluginId, handler) | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// BAD | ||
class MyPlugin { | ||
private readonly handlers = new Map(); | ||
|
||
setup(core) { | ||
this.contextContainer = core.context.createContextContainer(); | ||
return { | ||
registerContext(pluginId, contextName, provider) { | ||
// This would leak this context to all handlers rather that only plugins that depend on the calling plugin. | ||
this.contextContainer.registerContext('my_plugin', contextName, provider); | ||
}, | ||
registerRoute(pluginId, path, handler) { | ||
this.handlers.set( | ||
path, | ||
// This handler will not receive any contexts provided by other dependencies of the calling plugin. | ||
this.contextContainer.createHandler('my_plugin', handler) | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
||
``` | ||
|
34 changes: 34 additions & 0 deletions
34
...velopment/core/public/kibana-plugin-public.icontextcontainer.registercontext.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IContextContainer](./kibana-plugin-public.icontextcontainer.md) > [registerContext](./kibana-plugin-public.icontextcontainer.registercontext.md) | ||
|
||
## IContextContainer.registerContext() method | ||
|
||
Register a new context provider. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
registerContext<TContextName extends keyof TContext>(pluginId: string, contextName: TContextName, provider: IContextProvider<TContext, TContextName, THandlerParameters>): this; | ||
``` | ||
## Parameters | ||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| pluginId | <code>string</code> | The plugin ID for the plugin that registers this context. | | ||
| contextName | <code>TContextName</code> | The key of the <code>TContext</code> object this provider supplies the value for. | | ||
| provider | <code>IContextProvider<TContext, TContextName, THandlerParameters></code> | A [IContextProvider](./kibana-plugin-public.icontextprovider.md) to be called each time a new context is created. | | ||
<b>Returns:</b> | ||
`this` | ||
The [IContextContainer](./kibana-plugin-public.icontextcontainer.md) for method chaining. | ||
## Remarks | ||
The value (or resolved Promise value) returned by the `provider` function will be attached to the context object on the key specified by `contextName`<!-- -->. | ||
Throws an exception if more than one provider is registered for the same `contextName`<!-- -->. | ||
Oops, something went wrong.