This is a lightweight JavaScript library for reactivity, state management, and DOM rendering. It’s designed to be simple and easy to understand.
Install via npm:
npm install blipdom- Reactivity: Automatically updates the DOM when state changes.
- Stateful: Allows for reactive state management using proxies.
- DOM Rendering: Renders only the necessary DOM elements.
Here's a basic usage example to get you started:
import { createReactiveState, render } from "my-framework";
// Define an initial reactive state
const state = createReactiveState({ count: 0 });
// Define a template function for rendering the state
const template = (state) => `<div>Count: ${state.count}</div>`;
// Render the template with the current state to an HTML element
render(document.getElementById("app"), template, state);In this example:
createReactiveStateinitializes a reactive state.renderbinds the state to an HTML element, updating the DOM whenever the state changes.
Creates a reactive state object. Changes to this object will automatically trigger updates in any components or DOM elements using this state.
-
Parameters:
initialState(Object): An object containing initial state properties.
-
Returns: A reactive version of
initialState. -
Example:
const state = createReactiveState({ count: 0 }); state.count = 1; // This will automatically trigger an update in the UI.
Renders a DOM element based on the provided state and template function. Automatically re-renders when the state changes.
-
Parameters:
targetElement(HTMLElement): The HTML element to render into.templateFunction(Function): A function that takesstateas a parameter and returns an HTML string.state(Object): The reactive state object to be rendered.
-
Example:
render(document.getElementById("app"), template, state);
See examples/example.html for a sample setup.
Contributions are welcome! To get started:
- Fork this repository.
- Create a new branch for your feature (
git checkout -b feature-branch). - Commit your changes (
git commit -m "Add new feature"). - Push to the branch (
git push origin feature-branch). - Open a pull request.
Please follow the code of conduct and include tests where applicable.
This library is licensed under the MIT License. See the LICENSE file for details.