lit / lit.dev

The Lit website
https://lit.dev
BSD 3-Clause "New" or "Revised" License
117 stars 173 forks source link

JavaScript Context Docs / Examples #1327

Open chahu opened 5 months ago

chahu commented 5 months ago

I couldn't find any docs/examples of using lit context with modern JavaScript. All the docs are Typescript. Where can I find JavaScript examples? Thanks.

https://lit.dev/docs/data/context/

augustjk commented 5 months ago

Check out https://lit.dev/playground/#sample=examples/context-basics and toggle the language to JS for a running example.

We haven't gotten around to adding any switchable code samples for those docs but it shouldn't be too difficult to use any of the code there in vanilla JavaScript by removing any type annotations or class member keywords like private.

While decorators can work in JavaScript (they are stage 3 proposal to the language), it will currently require transpilation with something like babel as it's not yet implemented in any JS runtime/browsers.

You can use any of the controllers without transpilation though. e.g. https://lit.dev/docs/data/context/#contextprovider