lit/lit

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

Open

#3,573 opened on Jan 17, 2023

 (1 comment) (0 reactions) (0 assignees)TypeScript (874 forks)batch import
Good First Issue

Repository metrics

Stars
 (16,966 stars)
PR merge metrics
 (Avg merge 8d 10h) (3 merged PRs in 30d)

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