MCPcopy Index your code
hub / github.com/I-am-abdulazeez/stunk

github.com/I-am-abdulazeez/stunk @v26.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v26.0 ↗ · + Follow
71 symbols 142 edges 32 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Stunk

Stunk is a lightweight, framework-agnostic state management library built on atomic state principles. It simplifies state management by breaking state into manageable "chunks", ensuring efficient updates and reactivity.

  • Pronunciation: Stunk (A playful blend of "state" and "chunk")

Stunk is like dividing your jar into many smaller containers, each holding a single piece of state. These smaller containers are called chunks. Each chunk can be updated and accessed easily, and any part of your app can subscribe to changes in a chunk so it gets updated automatically.

Features

  • 🚀 Lightweight and Fast: No dependencies, minimal overhead
  • 🔄 Reactive: Automatic updates when state changes
  • 📦 Batch Updates: Group multiple state updates together
  • 🎯 Atomic State Management: Break down state into manageable chunks
  • 🎭 State Selection: Select and derive specific parts of the state
  • 🔄 Async Support: Handle async state with built-in loading and error states
  • 🔌 Middleware Support: Extend functionality with custom middleware
  • ⏱️ Time Travel: Undo/redo state changes
  • 🔍 Type-Safe: Written in TypeScript with full type inference

Installation

npm install stunk
# or
yarn add stunk
# or
pnpm install stunk

Read Docs:

Stunk

Creating a Chunk

import { chunk } from "stunk";

// Create a chunk holding a number
const count = chunk(0);

// Create a chunk holding a string
const name = chunk("Stunky, chunky");

👉 See full explanation in docs

Interacting with a Chunk

// Get value
console.log(count.get()); // 0

// Set a new value
count.set(10);

// Update based on the previous value
count.set((prev) => prev + 1);

// Reset to the initial value
count.reset();

// Destroy the chunk and all its subscribers.
count.destroy();

👉 See full explanation in docs

React via useChunk

The useChunk hook, enables components to reactively read and update state from a Chunk. The counter example below depicts

import { chunk } from "stunk";
import { useChunk } from "stunk/react";

const count = chunk(0);

const Counter = () => {
  const [value, set, reset] = useChunk(count);

  return (





Count: {value}


      <button onClick={() => set((prev) => prev + 1)}>Increment</button>
      <button onClick={() => reset()}>Reset</button>



  );
};

👉 See full explanation in docs

React via useDerive

Hook that lets you create a read-only derived state from a Chunk. It keeps the derived value reactive, automatically updating whenever the source Chunk changes.

import { chunk } from "stunk";
import { useDerive } from "stunk/react";

const count = chunk(0);

const DoubledCount = () => {
  const double = useDerive(count, (value) => value * 2);

  return 

Double: {double}

;
};

👉 See full explanation in docs

React via useComputed

Hook that derives a computed value from one or more Chunks. It automatically re-evaluates whenever any of its dependencies change, ensuring efficient and reactive updates.

import { chunk } from "stunk";
import { useComputed } from "stunk/react";

const count = chunk(2);
const multiplier = chunk(3);

const ComputedExample = () => {
  const product = useComputed([count, multiplier], (c, m) => c * m);

  return 

Product: {product}

;
};

👉 See full explanation in docs

React via useAsyncChunk

Hook that manages that manages asynchronous state. It offers built-in reactivity, handling loading, error, and data states, ensuring the UI stays in sync with asynchronous operations.

import { asyncChunk } from "stunk";
import { useAsyncChunk } from "stunk/react";

const fetchUser = asyncChunk(async () => {
  const res = await fetch("https://jsonplaceholder.typicode.com/users/1");
  return res.json();
});

const UserProfile = () => {
  const { data, loading, error, reload } = useAsyncChunk(fetchUser);

  if (loading) return 

Loading...

;
  if (error) return 

Error: {error.message}

;

  return (



      <h2>{data.name}</h2>


{data.email}


      <button onClick={reload}>Reload</button>



  );
};

👉 See full explanation in docs

React via useChunkValue

Hook that subscribes to a Chunk and returns its current value. It is useful for read-only components that don’t need to modify the state.

import { chunk } from "stunk";
import { useChunkValue } from "stunk/react";

const count = chunk(0);

const CounterDisplay = () => {
  const value = useChunkValue(count);

  return 

Count: {value}

;
};

👉 See full explanation in docs

Live Examples:

👉 Visit

Coding Examples:

👉 Visit

Further Examples:

👉 Visit

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Pull Request

License

This is licence under MIT

Extension points exported contracts — how you extend this code

ChunkWithHistory (Interface)
(no doc)
src/middleware/history.ts
SelectOptions (Interface)
(no doc)
src/core/selector.ts
UseAsyncChunkResult (Interface)
(no doc)
src/use-react/hooks/useAsyncChunk.ts
User (Interface)
(no doc)
tests/async-chunk.test.ts
User (Interface)
(no doc)
tests/chunk.test.ts
PersistOptions (Interface)
(no doc)
src/middleware/persistence.ts
Computed (Interface)
(no doc)
src/core/computed.ts
UseAsyncChunkResultWithParams (Interface)
(no doc)
src/use-react/hooks/useAsyncChunk.ts

Core symbols most depended-on inside this repo

chunk
called by 92
src/core/core.ts
asyncChunk
called by 29
src/core/asyncChunk.ts
computed
called by 25
src/core/computed.ts
select
called by 18
src/core/selector.ts
batch
called by 12
src/core/core.ts
fetchData
called by 11
src/core/asyncChunk.ts
withHistory
called by 6
src/middleware/history.ts
withPersistence
called by 4
src/middleware/persistence.ts

Shape

Function 47
Interface 24

Languages

TypeScript100%

Modules by API surface

src/core/asyncChunk.ts15 symbols
src/core/core.ts11 symbols
tests/async-chunk.test.ts9 symbols
src/utils.ts8 symbols
src/use-react/hooks/useAsyncChunk.ts8 symbols
src/core/selector.ts3 symbols
src/core/computed.ts3 symbols
src/middleware/persistence.ts2 symbols
src/middleware/history.ts2 symbols
tests/computed.test.ts1 symbols
tests/chunk.test.ts1 symbols
src/use-react/hooks/useDerive.ts1 symbols

For agents

$ claude mcp add stunk \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page