Skip to content

Commit 56caeec

Browse files
committedDec 28, 2017
Add documentation for rootInjects interface
1 parent 9d48c47 commit 56caeec

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed
 

‎docs/customization/plugin-api.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ A plugin return value may contain any of these keys, where `myStateKey` is a nam
1919
},
2020
components: {},
2121
wrapComponents: {},
22+
rootInjects: {},
2223
afterLoad: (system) => {},
2324
fn: {},
2425
}
@@ -364,11 +365,28 @@ const MyWrapComponentPlugin = function(system) {
364365
}
365366
```
366367

368+
##### `rootInjects`
369+
370+
The `rootInjects` interface allows you to inject values at the top level of the system.
371+
372+
This interface takes an object, which will be merged in with the top-level system object at runtime.
373+
374+
```js
375+
const MyRootInjectsPlugin = function(system) {
376+
return {
377+
rootInjects: {
378+
myConstant: 123,
379+
myMethod: (...params) => console.log(...params)
380+
}
381+
}
382+
}
383+
```
384+
367385
##### `afterLoad`
368386

369387
The `afterLoad` plugin method allows you to get a reference to the system after your plugin has been registered.
370388

371-
This interface is used in the core code to attach methods that are driven by bound selectors or actions directly to the plugin context.
389+
This interface is used in the core code to attach methods that are driven by bound selectors or actions. You can also use it to execute logic that requires your plugin to already be ready, for example fetching initial data from a remote endpoint and passing it to an action your plugin creates.
372390

373391
The plugin context, which is bound to `this`, is undocumented, but below is an example of how to attach a bound action as a top-level method:
374392

0 commit comments

Comments
 (0)
Please sign in to comment.