Skip to content

hsmyc/kraai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KRAAI

Overview

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.

Features

  • 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.

Installation

To use @yucedev/kraai directly in your project, install it via your preferred package manager:

Using bun

bunx jsr add @yucedev/kraai

Using npm

npx jsr add @yucedev/kraai

Using deno

deno add jsr:@yucedev/kraai

Using yarn

yarn dlx jsr add @yucedev/kraai

Using pnpm

pnpm dlx jsr add @yucedev/kraai

Usage

Creating a State

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

Creating a Computed State

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

Creating a Hybrid State

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

Testing

To run the tests for the state manager, use:

bun test

Contributing

Contributions are welcome! To contribute:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Make your changes and commit them (git commit -m 'Add new feature').
  4. Push to the branch (git push origin feature-branch).
  5. Open a Pull Request.

Please ensure that your code follows our coding standards and includes tests.

  1. Clone the repository:
git clone https://github.com/hsmyc/kraai.git
cd kraai
  1. Install dependencies:
bun install

To run the app locally, use:

bun run dev

License

This project is licensed under the MIT License. See the LICENSE file for more details.

About

Web

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors