Loading repository data…
Loading repository data…
mahfoud-elbachiri / repository
This project demonstrates a custom built, lightweight JavaScript framework inspired by React, along with a fully functional Todo application built on top of it.
This project demonstrates a custom built, lightweight JavaScript framework inspired by React, along with a fully functional Todo application built on top of it.
A minimal, component-based framework that includes:
framework/core/diff.js).useState: For state management.useEffect: For side effects and lifecycle events.framework/core/router.js) supporting navigation and parameters.jsx and createElement functions for component rendering.A complete Todo MVC implementation featuring:
Mini-Framwork/
├── framework/ # The core framework code
│ ├── core/
│ │ ├── diff.js # Virtual DOM diffing algorithm
│ │ ├── dom.js # DOM manipulation and JSX transformations
│ │ ├── events.js # Event handling system
│ │ ├── router.js # Hash-based router
│ │ └── state.js # State management (useState, useEffect)
│ └── index.js # Framework entry point exporting hooks and render
├── todoapp/ # The example Todo application
│ ├── components/ # UI Components (TodoApp, TodoItem, etc.)
│ ├── styles/ # CSS styles
│ ├── utils/ # Helper functions
│ └── app.js # Application entry point
├── index.html # Main HTML entry point
└── NOTES.md # Development notes
Since this is a client-side application using ES modules, you need to serve it using a local static server to avoid CORS issues with file:// protocol.
# Run in the root directory
python3 -m http.server 8000
npx http-server .
http://localhost:8000.To create a new component:
import { jsx, useState } from './framework/index.js';
function Counter() {
const [count, setCount] = useState(0);
return jsx('button', {
onclick: () => setCount(count + 1)
}, `Count is: ${count}`);
}
The framework uses a global state array with index tracking, similar to how React hooks work under the hood. useState returns the current state and a setter function that triggers a re-render.
The router listens to hashchange events. The useRouter hook exposes route, navigate, and getParams to components, allowing them to react to URL changes.
The render function in framework/index.js creates a virtual tree. The diff function compares the new tree with the old one and patches the actual DOM, ensuring minimal updates for better performance.
/) to #/all.