このコミットが含まれているのは:
2025-06-15 14:24:41 +09:00
コミット fe8739b290
8個のファイルの変更144行の追加11行の削除
+35
ファイルの表示
@@ -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)
}
}
}