theater-core
v0.0.2
Published
A simple library for building immutable data structure
Downloads
4
Maintainers
Readme
theatre-core
Theatre core is a tiny small library used to provide basics and standard immutable data structures for all theatre library.
Installation
# Using npm
npm install theater-core
# Using yarn
yarn add theater-core
# Using bun
bun add theater-coreFeatures
- Mutable Values: Safe encapsulation of mutable state
- Reactive Values: Observable values with change notifications
- Event System: Simple pub/sub event handling
- Immutable by Design: Promotes immutable data patterns
Usage
Mutable Values
import { mutable, read, write } from "theater-core";
const count = mutable(0);
read(count); // => 0
write(count, 1);
read(count); // => 1Reactive Values
import { reactive, listen, write } from "theater-core";
const counter = reactive(0);
// Listen to changes
listen(counter, (newValue) => {
console.log("Counter changed:", newValue);
});
// Update value
write(counter, 1); // Will trigger the listenerEvents
import { event, emit, listen } from "theater-core";
const onClick = event<string>();
// Subscribe to events
listen(onClick, (message) => {
console.log("Clicked:", message);
});
// Emit events
emit(onClick, "Hello!");API Reference
Core Types
Mutable<T>: Container for mutable valuesReactive<T>: Observable container with change notificationsEvent<T>: Type-safe event emitter
Operations
read(value): Read from mutable or reactive valueswrite(value, newValue): Write to mutable or reactive valueslisten(target, callback): Subscribe to events or reactive changesemit(target, value?): Emit events or trigger reactive updates
License
MIT © David Jegat
