lit/lit

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

Open

#3,573 opened on Jan 17, 2023

View on GitHub
 (1 comment) (0 reactions) (0 assignees)TypeScript (16,966 stars) (874 forks)batch import
Good First Issue

Description

Should this be an RFC?

  • This is not a substantial change

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.

Contributor guide

[labs/context] Allow multiple provider contexts to be added at the same time · lit/lit#3573 | Good First Issue