This repository contains two example implementations of a Todo application to demonstrate the differences between vanilla Web Components and Lit Elements.
Web Components are a set of web platform APIs that allow you to create new custom, reusable, encapsulated HTML elements. They consist of three main technologies:
- Custom Elements: JavaScript APIs to define custom elements and their behavior
- Shadow DOM: Encapsulated DOM and styling, scoped to the component
- HTML Templates: HTML markup templates that can be reused
Check out the todo-web-components
folder for an example of a Todo application built with vanilla Web Components.
Lit is a simple library for building fast, lightweight web components. It provides a set of features that make it easier to work with Web Components:
- Declarative Templates: Write HTML templates using JavaScript template literals
- Reactive Properties: Simple property management with automatic updates
- Lifecycle Management: Easy-to-use lifecycle hooks
- Efficient Updates: Smart rendering system that only updates what changed
- TypeScript Support: Built with TypeScript for better developer experience
- Less boilerplate code
- Better performance through efficient rendering
- Enhanced developer experience
- Built-in property management
- Simpler event handling
- Better TypeScript support
The todo-lit
folder contains a complete Todo application built with Lit Elements. This example includes:
- Full implementation of a Todo application
- Unit tests demonstrating how to test Lit components
- Best practices for component structure
- Property management examples
- Event handling patterns
The todo-web-components
folder contains the same Todo application built with vanilla Web Components. This implementation helps understand:
- Basic Web Component structure
- How to implement custom elements without a framework
- Shadow DOM usage
- HTML template implementation
To run either example:
- Navigate to the desired folder (
todo-lit
ortodo-web-components
) - Install dependencies:
npm install
- Start the development server:
npm run dev
- Run tests (for todo-lit):
npm test