This project provides a flexible and efficient state management system for handling different types of states: regular, computed, and hybrid states. It is designed for simplicity, performance, and extensibility, making it suitable for various applications where state handling and dependency management are crucial.
- State Management: Create, manage, and subscribe to state changes with a simple API.
- Computed State: Automatically compute derived state values based on dependencies.
- Hybrid State: Combine computed and manual state management for advanced use cases.
- Dependency Tracking: Efficiently track dependencies between states, ensuring accurate and minimal updates.
To use @yucedev/kraai directly in your project, install it via your preferred package manager:
bunx jsr add @yucedev/kraainpx jsr add @yucedev/kraaideno add jsr:@yucedev/kraaiyarn dlx jsr add @yucedev/kraaipnpm dlx jsr add @yucedev/kraaiAfter installing @yucedev/kraai, you can start using it by importing and creating your first state:
import { createState } from "@yucedev/kraai";
const [getState, setState, subscribe] = createState(0);
subscribe((value) => {
console.log("State updated:", value);
});
setState(1);// Outputs: 1Computed states automatically derive their value from other states:
const [getCount, setCount] = createState(0);
const [getDoubleCount, subscribeDoubleCount] = createComputedState(
() => getCount() * 2
);
subscribeDoubleCount((value) => {
console.log("Double count:", value);
});
setCount(2); // Outputs: Double count: 4Hybrid states allow both manual updates and computed values:
const [getHybrid, setHybrid, subscribeHybrid] = createHybridState(
() => ({ count: 0 }),
{ count: 0 }
);
subscribeHybrid((state) => {
console.log("Hybrid state:", state);
});
setHybrid({ count: 5 });
console.log(getHybrid().count); // Outputs: 5To run the tests for the state manager, use:
bun testContributions are welcome! To contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch). - Make your changes and commit them (
git commit -m 'Add new feature'). - Push to the branch (
git push origin feature-branch). - Open a Pull Request.
Please ensure that your code follows our coding standards and includes tests.
- Clone the repository:
git clone https://github.com/hsmyc/kraai.git
cd kraai- Install dependencies:
bun installTo run the app locally, use:
bun run devThis project is licensed under the MIT License. See the LICENSE file for more details.