using System;
using R3;
using UnityEngine;

namespace KitsuneCafe.SOAP
{

    public class ReactiveEvent<T> : ReactiveSource<T>, IEvent<T>
    {
        protected readonly ISubject<T> onRaise = new Subject<T>();

        public override Observable<T> AsObservable() => (Observable<T>)onRaise;

        public virtual void Raise(T value)
        {
            onRaise.OnNext(value);
        }

        private void OnDestroy()
        {
            onRaise.OnCompleted();
            ((IDisposable)onRaise).Dispose();
        }
    }
}
