A reactive programming library, including signals, event emitters, and streams observer.
let condition = state(true)
let count = state(1)let value = condition.get()count.set(10)let off_condition = effect(() => println("Condition changed: \{condition.get()}"))
condition.set(false)
off_condition()let result = computed(() => {
if condition.get() {
a.get() * 2
} else {
b.get() * 3
}
})let value = result.get()let off_result = result.on(value => println("Result changed: \{value}"))
off_result()effect(() => println("Condition changed: \{condition.get()}"))let my_observable = Observable::new(observer => {
observer.next(10)
()
})let my_subscription = my_observable.on_from_next(value => println("Received value: \{value}"))
my_subscription.off()let my_subject = Subject::new(observer => {
observer.next(5)
()
})my_subject.next(10)
my_subject.complete()let my_events = Events::new()my_events.emit("user.login", { username: "john_doe" })let off_login = my_events.on("user.login", data => println("User logged in: \{data.username}"))
off_login()my_events.once("user.login", data => println("User logged in once: \{data.username}"))pub struct Computed[T] {
// private fields
}pub struct Counter {
// private fields
}pub struct Events[N, T] {
// private fields
}pub struct Observable[T, E] {
// private fields
}pub struct Observer[T, E] {
next : (T) -> Unit?
error : (E) -> Unit?
complete : () -> Unit?
// private fields
}pub struct State[T] {
// private fields
}pub struct Subject[T, E] {
// private fields
}pub struct Subscription {
// private fields
}fn effect(callback : () -> Unit) -> (() -> Unit)A reactive programming library, including signals, event emitters, and streams observer.