lit / lit

Lit is a simple library for building fast, lightweight web components.
https://lit.dev
BSD 3-Clause "New" or "Revised" License
18.54k stars 914 forks source link

[labs/context] Allow multiple provider contexts to be added at the same time #3573

Open snicol-icanbwell opened 1 year ago

snicol-icanbwell commented 1 year ago

Should this be an RFC?

Which package is this a feature request for?

Context (@lit-labs/context)

Description

It would be useful to be able to provide multiple contexts at the same time; allowing a provider component to be instantiated the same way but with a dynamic array of contexts

  private provider = new MultiContextProvider(this, [
    [loggerContext, {
      log: (msg) => {
        console.log(`[my-app] ${msg}`);
      },
    }],
    [themeContext, myTheme],
    [apiContext, myAPI], 
  ]);

Alternatives and Workarounds

It's possible to create a separate provider for every injected service.

snicol-icanbwell commented 1 year ago

I had a conversation with @justinfagnani about this same thing in the Lit discord channel: https://discord.com/channels/1012791295170859069/1053423934453854289