Challenges
Challenge 1: Data List with CRUD Operations
Objective
Create three custom web components using Lit that demonstrates data exchange between them. The components should
communicate using different patterns (mediator pattern, events, and observables). The components should also use a
service layer to communicate with a JSON-Server for data persistence.
Requirements
-
Component Structure:
- Create three custom elements:
data-form, data-list and data-list-item.
- The
data-form component should contain a form with fields for name, phone number, and email address, along with a
button to add the data to a list.
- The
data-list component should display the list of entries added from the data-form component using the data-list-item component.
- Each
data-list-item should have an edit and delete button.
-
Data Exchange:
- Use the mediator pattern to exchange data between the two components.
- Refactor the code to use events for data exchange between the components.
- Integrate JSON-Server to store the data, ensuring that only the service layer communicates with the JSON-Server.
- Refactor the code to use observables for data exchange between the service layer and the view layer.
-
Service Layer:
- Create a service layer that handles all communication with the JSON-Server.
- The service layer should provide methods to add, edit, delete, and fetch data from the server.
Instructions
- Create a new Lit project and set up the necessary files for the
data-form, data-list and data-list-item components.
- Implement the
data-form component with a form that includes fields for name, phone number, and email address.
- Implement the
data-list component to display the list of entries added from the data-form component.
- Implement the
data-list-item component to display individual entries with edit and delete buttons.
- Implement the mediator pattern to exchange data between the components.
- Refactor the code to use events for data exchange between the components.
- Integrate JSON-Server to store the data, ensuring that only the service layer communicates with the JSON-Server.
- Refactor the code to use observables for data exchange between the service layer and the view layer.
Home |
Observables |
Data Exchange