js-state-manager Tailwind Templates

Js State Manager

This repository demonstrates handling promises in JavaScript with a custom-built state manager. It includes examples of fetching and managing data from an API, updating the DOM based on state changes, and ensuring a responsive design using Tailwind CSS.

JS State Manager

This repository demonstrates handling promises in JavaScript with a custom-built state manager. It includes examples of fetching and managing data from an API, updating the DOM based on state changes, and ensuring a responsive design using Tailwind CSS.

Features

  • Simple state management
  • Listener subscription for state changes
  • Unsubscribe functionality
  • Promise handling

Installation

To get started with this project, clone the repository and install the dependencies:

git clone https://github.com/ZahraJiryaee/js-state-manager.git
cd js-state-manager
npm install

Usage

Here's an example of how to use the StateManager:

// index.js
import StateManager from "./stateManager.js";

const initialState = { count: 0 };
const store = new StateManager(initialState);

// Subscriber function
const listener = (state) => {
  console.log("State changed:", state);
};

// Subscribe to state changes
const unsubscribe = store.subscribe(listener);

// Update state
store.setState({ count: store.getState().count + 1 });

// Unsubscribe if needed
// unsubscribe();

Running Tests

Here's an example of how to use the StateManager:

node src/test.js

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any changes.

Acknowledgments

Contact

For any inquiries or issues, please open an issue on this repository.

Top categories

Loading Svelte Themes