Skip to content

mkotkov/mini-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Todo List Framework Documentation

Overview

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.

Updated Directory Structure

/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

/core Directory

The /core directory contains the core functionalities of the framework, such as DOM manipulation, event handling, state management, and routing.

1. dom.js

This module provides utility functions for creating and rendering DOM elements.

Functions:

  • 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.

2. events.js

This file provides utility functions for attaching event listeners to DOM elements.

Functions:

  • 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.

3. router.js

This module manages the application's client-side routing.

Classes:

  • 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.

4. state.js

This module provides a simple state management solution.

Classes:

  • 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.

/public Directory

The /public directory contains the static assets such as the main index.html file and application styles.

1. index.html

This is the main HTML file loaded in the browser. It serves as the entry point for the application.

2. style.css

This file contains the base styles for the application.


/src Directory

The /src directory contains the main application logic, components, and framework-specific logic.

1. app.js

This is the main entry point of the application. It initializes the app, sets up routing, state management, and renders the components.

Key Responsibilities:

  • Initialize the router.
  • Manage the app's state using the State class.
  • Set up event listeners.
  • Render the TodoApp component.

2. components/TodoItem.js

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).

Functions:

  • 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.

/framework Directory

The /framework directory contains framework-level functionality. This provides an abstraction over the core logic, making it reusable across different parts of the application.

1. event.js

This file is responsible for managing events in the context of the framework, built on top of the core event handling.

2. router.js

This is the framework’s routing system, abstracting over the core Router class to integrate with other framework elements.

3. state.js

This file integrates state management with the overall application framework, based on the State class from /core/state.js.

4. index.js

This file serves as the entry point for the framework, re-exporting functionality from the event, router, and state files for easy importing.


/app Directory

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.

1. components/

This folder contains components that are directly related to the todo app.

TodoApp.js

The root component that manages the rendering of the entire Todo application.

TodoItem.js

A reusable component that renders an individual todo item.

TodoList.js

This component manages the list of todos and their interactions (filtering, displaying).


2. index.html

The main HTML file for the app.

3. index.js

The entry point that initializes the Todo application.


4. style.css

Custom styles for the Todo application, including layout, buttons, and todo item styling.


About

This framework is designed for building an application using custom DOM manipulation

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors