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.
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
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();
Here's an example of how to use the StateManager:
node src/test.js
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request for any changes.
For any inquiries or issues, please open an issue on this repository.