This framework is designed for building a modular todo list application using custom DOM manipulation, event handling, state management, and routing functionalities. The project is structured in a way that separates concerns, making it easier to maintain and scale.
/core
├── dom.js // DOM manipulation functions
├── events.js // Event handling functions
├── router.js // Routing functionality
└── state.js // State management
/public
├── index.html // Main HTML file
└── style.css // Styles for the application
/src
├── app.js // Main application logic
└── components
| └── TodoItem.js // Component logic for individual Todo items
└── app
├── components
├── TodoApp.js // The root Todo application component
├── TodoItem.js // Logic specific to a single Todo item
└── TodoList.js // Logic for rendering the list of Todo items
├── index.html // HTML file for the app's main entry point
├── index.js // JS file for initializing the app
└── style.css // Styles for the app
The /core directory contains the core functionalities of the framework, such as DOM manipulation, event handling, state management, and routing.
This module provides utility functions for creating and rendering DOM elements.
-
createElement(tag, attrs, children)- Creates a new DOM element with the specified attributes and children.
- Parameters:
tag(String): The HTML tag (e.g.,'div','li').attrs(Object): Key-value pairs of attributes to set (e.g.,{ class: 'my-class' }).children(Array): List of child elements or text to append to the created element.
-
renderElements(container, elements)- Clears the specified container and appends the given elements.
- Parameters:
container(Element): The DOM element to append the new elements to.elements(Array|Object): A list of elements or a single element to append.
This file provides utility functions for attaching event listeners to DOM elements.
on(element, eventType, handler)- Attaches an event listener to the specified element.
- Parameters:
element(Element): The DOM element to attach the event listener to.eventType(String): The event type (e.g.,'click','keydown').handler(Function): The callback function triggered by the event.
This module manages the application's client-side routing.
Router- Handles URL-based navigation.
- Constructor:
constructor(routes): Initializes the router with a set of routes.- Parameters:
routes(Object): A map of routes to handler functions.
- Methods:
handleRoute(): Detects the current URL path and executes the corresponding route handler.navigate(path): Pushes the new URL to the browser history and handles the route change.
This module provides a simple state management solution.
State- Manages the global application state.
- Constructor:
constructor(initialState): Initializes the state with the given initial state.
- Methods:
getState(): Returns the current state.setState(newState): Updates the state and notifies any subscribers.subscribe(listener): Subscribes a listener function to state changes.
The /public directory contains the static assets such as the main index.html file and application styles.
This is the main HTML file loaded in the browser. It serves as the entry point for the application.
This file contains the base styles for the application.
The /src directory contains the main application logic, components, and framework-specific logic.
This is the main entry point of the application. It initializes the app, sets up routing, state management, and renders the components.
- Initialize the router.
- Manage the app's state using the
Stateclass. - Set up event listeners.
- Render the
TodoAppcomponent.
This file contains logic related to the rendering and behavior of individual todo items. It provides functions that manipulate the state of todo items (e.g., toggling, deleting).
addTodoItem(text, appState): Adds a new todo item to the app state.removeTodoItem(id, appState): Removes a todo item from the app state.toggleTodoItem(id, appState): Toggles the completion status of a todo item.
The /framework directory contains framework-level functionality. This provides an abstraction over the core logic, making it reusable across different parts of the application.
This file is responsible for managing events in the context of the framework, built on top of the core event handling.
This is the framework’s routing system, abstracting over the core Router class to integrate with other framework elements.
This file integrates state management with the overall application framework, based on the State class from /core/state.js.
This file serves as the entry point for the framework, re-exporting functionality from the event, router, and state files for easy importing.
This directory contains the application-specific components, entry point, and styles. It is structured to contain a clear separation between different parts of the app.
This folder contains components that are directly related to the todo app.
The root component that manages the rendering of the entire Todo application.
A reusable component that renders an individual todo item.
This component manages the list of todos and their interactions (filtering, displaying).
The main HTML file for the app.
The entry point that initializes the Todo application.
Custom styles for the Todo application, including layout, buttons, and todo item styling.