mana-ts
v1.0.7
Published
A high-performance, O(1) reactive state engine and type-governance ecosystem for deeply nested trees.
Readme
⚡ mana-ts
Fine-grained, $\mathcal{O}(1)$ reactivity loops built directly inside standard React.
mana-ts is a high-performance state and rendering engine that brings SolidJS-style, surgical DOM updates straight into your React application. It completely cuts out the Virtual DOM bottleneck for high-frequency state updates (60Hz telemetry, real-time tracking, mouse dragging vectors, canvas data feeds) while allowing your parent components to remain completely static.
🛑 The Problem with Standard React
When a state value changes in standard React, it forces a top-down virtual DOM reconciliation loop. If you are updating a telemetry coordinate 60 times a second, React diffs your entire component tree. This results in dropped frames, visual stuttering, UI lag, and massive garbage collection strain.
Putting high-frequency streams into global state managers like Redux or Zustand only spreads this lag across your whole layout.
🚀 The Mana Solution
mana-ts implements a low-level, type-safe pub-sub dependency graph. Your parent dashboard container renders exactly once and remains completely frozen.
When a sub-property shifts, it bypasses React's virtual DOM reconciliation entirely and updates only the specific HTML text nodes, styles, or canvas pixels tied to that exact key.
💻 Quick Start
1. Installation
npm install mana-ts2. Instantiate Your Mapped State Container
Create state objects using ObjectState or ArrayState. These act as fine-grained data envelopes that do not trigger React re-renders automatically.
import { Manager } from 'mana-ts';
import ObjectState = Manager.ObjectState;
interface Aircraft {
id: string;
lat: number;
lon: number;
altitude: number;
}
// Instantiate an isolated state manager
const flightTracker = new ObjectState<Aircraft>({
id: "flight-777",
lat: 32.7767,
lon: -96.7970,
altitude: 35000
});3. Surgical Rendering via <MultiDyn />
Wrap your performance-critical UI elements inside <MultiDyn />. Pass it an array of dependencies using .dep(). The component accepts a render prop function (val) that stays completely dormant until the observed keys change.
import React, { useId } from 'react';
import { MultiDyn } from 'mana-ts';
export function RadarScreen() {
const uniqueId = useId();
return (
<div className="radar-container">
{/* The parent container never re-renders when the flight moves! */}
<h1>Live Radar Feed</h1>
<MultiDyn
dep={[flightTracker.dep("lat"), flightTracker.dep("lon"), flightTracker.dep("altitude")]}
val={(lat, lon, altitude) => (
<div
className="aircraft-blip"
style={{ transform: `translate(${lon * 10}px, ${lat * 10}px)` }}
>
✈️ Flight 777 ({altitude} ft)
</div>
)}
eventKey={uniqueId}
/>
</div>
);
}4. Push High-Frequency Updates Seamlessly
Update the state properties natively at 60Hz. Updates run in strict constant $\mathcal{O}(1)$ time execution loops.
// Bypasses React's Virtual DOM loop entirely.
// Fires localized DOM node mutations instantly.
setInterval(() => {
const currentAlt = flightTracker.getValue("altitude");
flightTracker.set("altitude", currentAlt + 10);
}, 16); // ~60 FPS animation loop🎯 Advanced Features
⚡ <CondMemo /> — Visual Layout Buffering
When dealing with massive datasets, you might want to skip UI refreshes unless structural layout parameters change. <CondMemo /> adds an inline validation barrier to your rendering loops:
import { CondMemo } from 'mana-ts';
import _ from 'lodash';
<CondMemo
dep={[mapData.dep("tiles")]}
diff={(next, prev) => !_.isEqual(next, prev)} // Skip frames if values remain functionally identical
val={(tiles) => <BackgroundGrid maps={tiles} />}
/>🔒 Built-in Memory Leak Protection
Manual pub-sub architectures are highly vulnerable to memory leaks if a developer forgets to unsubscribe a dead layout element. mana-ts handles this automatically.
Hooks like useDep, useMultiVal, and useRawDepMonitor tie subscription lifecycles directly into React's component mounting trees. The exact millisecond an element unmounts or leaves the screen, its internal callbacks trigger automatic un-subscription routines, instantly cleaning up your application's memory footprint.
⚙️ Core Architecture Blueprint
┌─────────────────────────────────┐
│ Your Standard React App │
│ (Renders exactly once: Static) │
└────────────────┬────────────────┘
│
Mounts dynamic leaf boundaries
▼
┌─────────────────────────────────┐
│ mana-ts <MultiDyn /> │
│ (Isolated Local Hook Handlers) │
└────────────────┬────────────────┘
│
Intercepts high-frequency raw updates
▼
┌───────────────────────────────────────────────────────┐
│ Surgical Browser DOM In-Place Mutation │
│ (Updates only the affected innerText / style nodes) │
└───────────────────────────────────────────────────────┘⚖️ License
MIT © Bryce Gredig (The64bitdude)
