Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rcp.whenReady should support for late init #96

Closed
nomi-san opened this issue Nov 18, 2023 · 3 comments
Closed

rcp.whenReady should support for late init #96

nomi-san opened this issue Nov 18, 2023 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@nomi-san
Copy link
Member

nomi-san commented Nov 18, 2023

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)
}
@nomi-san nomi-san added the enhancement New feature or request label Nov 18, 2023
@nomi-san nomi-san added this to the v1.1.1 milestone Nov 18, 2023
@BakaFT
Copy link
Member

BakaFT commented Nov 18, 2023

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
Copy link
Contributor

User344 commented Nov 18, 2023

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
Copy link
Member Author

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.

nomi-san added a commit that referenced this issue Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants