1.0.3 โ€ข Published 1 year ago

@medieval/martingale v1.0.3

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

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!

1.0.3

1 year ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago