PenguLoader / PenguLoader

✨ The ultimate JavaScript plugin loader, build your unmatched LoL Client.
https://pengu.lol
Do What The F*ck You Want To Public License
346 stars 56 forks source link

rcp.whenReady should support for late init #96

Closed nomi-san closed 4 months ago

nomi-san commented 5 months ago

That was lacking in v1.1.0.

export function init(ctx) {
  setTimeout(async () => {
    const api = await ctx.rcp.whenReady('rcp-some-lib')
    // fix me (currently never fires)
  }, 10000)
}
BakaFT commented 5 months ago

This trick may fix that.

export function init(context) {
    context.rcp.preInit('rcp-fe-common-libs', async (provider) => {
        window.provider = provider
    })

    setTimeout(async () => {
        const api = await window.provider.getOptional("rcp-fe-lol-social")
        console.log(api)
        // fix me
      }, 10000)
}
User344 commented 5 months ago

It should be noted that getOptional will actually load plugin if its not loaded yet, which might not be ideal. I think to clear up any confusion there should be separate APIs to wait for a plugin (which will of course also instantly fire a callback if its already loaded when its called) and separate API to load them like load/getOrLoad.

nomi-san commented 5 months ago

This issue just marks a note for next update. The current whenReady impl wraps the callback inside Promise, no checks for even loaded plugins.

Never saw getOptional before, and it could be changed in the future.