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.
To use @yucedev/kraai directly in your project, install it via your preferred package manager:
bunx jsr add @yucedev/kraai
npx jsr add @yucedev/kraai
deno add jsr:@yucedev/kraai
yarn dlx jsr add @yucedev/kraai
pnpm dlx jsr add @yucedev/kraai
After 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: 1
Computed 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: 4
Hybrid 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: 5
To run the tests for the state manager, use:
bun test
Contributions are welcome! To contribute:
git checkout -b feature-branch).git commit -m 'Add new feature').git push origin feature-branch).Please ensure that your code follows our coding standards and includes tests.
git clone https://github.com/hsmyc/kraai.git
cd kraai
bun install
To run the app locally, use:
bun run dev
This project is licensed under the MIT License. See the LICENSE file for more details.