This commit is contained in:
2025-06-15 14:24:41 +09:00
parent 50a9313525
commit fe8739b290
8 changed files with 144 additions and 11 deletions
+35
View File
@@ -0,0 +1,35 @@
export class EventBus<T>
{
private value: T
private subscribers: ((val: T) => void)[] = []
constructor (
initialValue: T)
{
this.value = initialValue
}
get ()
: T
{
return this.value
}
set (
val: T)
: void
{
this.value = val
this.subscribers.forEach (f => f (val))
}
subscribe (
func: (val: T) => void)
: () => void
{
this.subscribers.push (func)
return () => {
this.subscribers = this.subscribers.filter (sub => sub !== func)
}
}
}
+3
View File
@@ -0,0 +1,3 @@
import { EventBus } from './EventBus'
export const WikiIdBus = new EventBus<number | null> (null)