Riot Client Pugin hooks
General usage
This object provides easy access and hook to the Riot Client Plugin (RCP) system.
Get the rcp
in your plugin entry:
export function init(context) {
const rcp = context.rcp
}
Or get it globally via window
object:
const rcp = window.rcp
rcp.preInit(name, callback)
functionsince v1.1.0Register a callback that will be triggered before the target plugin loads.
Params
name
- RCP name, should be prefixed withrcp-
.callback
- A function will be triggered before the plugin loads.
Example:
rcp.preInit('rcp-name', (context) => {
// do something
})
You can delay the plugin loads by blocking your async callback:
rcp.preInit('rcp-name', async () => {
// delay 2 seconds
await new Promise((r) => setTimeout(r, 2000))
})
WARNING
Do not pre-hook rcp-fe-commom-libs
. It is used for the plugin loader, so your callbacks sometimes will not triggered.
rcp.postInit(name, callback, blocking?)
functionsince v1.1.0Register a callback that will be triggered after the target plugin is loaded. Gives you an opportunity to access the plugin API.
Params
name
- RCP name, should be prefixed withrcp-
.callback
- A function will be triggered after the plugin is loaded.blocking
- A boolean value indicating whether this callback will be executed in blocking way. It'sfalse
by default.
Example:
rcp.postInit('rcp-name', (api) => {
// do something
console.log('got rcp-name:', api)
})
TIP
postInit
and preInit
should be called before the target plugin loads, preferably witin your plugin's init
entry. So they will not work after the plugin is loaded.
rcp.whenReady(name)
functionsince v1.1.0This function works as same as postInit
but allows you to get the target plugin asynchronously and also works even after the plugin is loaded.
Example with async context:
const uikit = await rcp.whenReady('rcp-fe-lol-uikit')
Or with .then chain:
rcp.whenReady('rcp-fe-lol-uikit')
.then((uikit) => {
// do something
})
With multiple plugins:
rcp.whenReady(['rcp-a', 'rcp-b', 'rcp-c'])
.then(([a, b, c]) => {
// do something
})
rcp.get(name)
functionsince v1.1.0Get a RCP plugin synchronously after it's registered in the callbacks map.
Example:
// add to callbacks map
rcp.whenReady('rcp-name')
// call it somewhere after ready
const api = rcp.get('rcp-name')
Common-libs always works:
rcp.get('rcp-fe-common-libs')