瀏覽代碼

Add documentation for `rootInjects` interface

bubble
Kyle Shockey 6 年之前
父節點
當前提交
56caeec8c8
共有 1 個文件被更改,包括 19 次插入1 次删除
  1. +19
    -1
      docs/customization/plugin-api.md

+ 19
- 1
docs/customization/plugin-api.md 查看文件

@@ -19,6 +19,7 @@ A plugin return value may contain any of these keys, where `myStateKey` is a nam
},
components: {},
wrapComponents: {},
rootInjects: {},
afterLoad: (system) => {},
fn: {},
}
@@ -364,11 +365,28 @@ const MyWrapComponentPlugin = function(system) {
}
```

##### `rootInjects`

The `rootInjects` interface allows you to inject values at the top level of the system.

This interface takes an object, which will be merged in with the top-level system object at runtime.

```js
const MyRootInjectsPlugin = function(system) {
return {
rootInjects: {
myConstant: 123,
myMethod: (...params) => console.log(...params)
}
}
}
```

##### `afterLoad`

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

This interface is used in the core code to attach methods that are driven by bound selectors or actions directly to the plugin context.
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.

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:



Loading…
取消
儲存