@medieval/martingale
v1.0.3
Published
> ๐งโโ๏ธ _"Why juggle state manually, when you can let **Martingale** do it for you?"_ > โ A wise developer somewhere in the multiverse
Downloads
74
Readme
Martingale ๐ฉ
๐งโโ๏ธ "Why juggle state manually, when you can let Martingale do it for you?"
โ A wise developer somewhere in the multiverse
๐ช Welcome to Martingale โ the enchanting state management library that brings harmony to your application's state while making you feel like a wizard of code!
๐ก Features
- ๐ฎ Simple State Management: Easily manage state without the fuss. No more headache-inducing complexity! ๐คฏ
- ๐ฐ๏ธ Undo/Redo Magic: Travel back and forth through your state history like a time traveler! โณ
- ๐ State History: Keep track of your past states as if you had a magical spell book! ๐
- ๐ Getters Galore: Access your state like a pro, with built-in methods for fetching the current value.
- ๐ฐ Flexible Options: Customize your store's options to fit your needs like a well-tailored robe.
๐ Installation
Getting started with Martingale is as simple as casting a spell:
npm install @medieval/martingale --force
๐ก Pro Tip: ๐งโโ๏ธ Don't forget to run npm install
โ your magic won't work without it!
๐ Getting Started
Hereโs how you can start managing your state like a true sorcerer:
import { makestate, Store } from '@medieval/martingale';
// Create a magical state
const initialState = { count: 0 };
const store: Store<typeof initialState> = makestate(initialState);
// Subscribe to state changes
const unsubscribe = store.subscribe((state) => {
console.log('๐ฎ Current State:', state);
});
// Update the state
store.set({ count: 1 }); // ๐ฅ State updated!
// Perform an undo
store.undo(); // โช Back in time!
// Get the current state
const currentState = store.get();
console.log('๐ Retrieved State:', currentState);
๐ Disclaimer: No states were harmed during this state management!
๐ Using the Store
With Martingale, you can manage your state like a seasoned wizard. Hereโs how:
Subscribe to State Changes
Subscribe to changes and perform your magic:
const unsubscribe = store.subscribe((state) => {
console.log('๐ State Updated:', state);
});
// Unsubscribe when you no longer need to watch the state
unsubscribe();
Update the State
Change your state and watch the magic happen:
store.set({ count: 2 }); // โจ Update the state!
Undo and Redo
Time travel with undo and redo capabilities:
store.undo(); // โช Go back one state
store.redo(); // โฉ Go forward one state
Get State History
Retrieve the history of your state changes:
const history = store.getStateHistory();
console.log('๐ State History:', history);
๐ค Contributing
Weโd love your help to make Martingale even more awesome! Submit issues, PRs, or just send us a virtual high-five! ๐
๐ธ๏ธ "With great state management, comes great responsibility." โ Not Spider-Man, but very close
Feel free to contribute at the GitHub repository.
๐ License
This project is licensed under the MIT License.
๐ฉ Now go ahead and manage your state like a master wizard with Martingale! Enjoy the magic!