mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2025-08-16 12:31:43 +02:00
.config
.run
.workdir
Agent
Common
Controller
Docker
Utils
Phantom.Utils
Phantom.Utils.Actor
Phantom.Utils.Events
EventSubscribers.cs
ObservableState.cs
Phantom.Utils.Events.csproj
SimpleObservableState.cs
Phantom.Utils.Logging
Phantom.Utils.Rpc
Phantom.Utils.Tests
Web
.dockerignore
.gitattributes
.gitignore
AddMigration.bat
AddMigration.sh
Directory.Build.props
Directory.Build.targets
Dockerfile
LICENSE
Packages.props
PhantomPanel.sln
README.md
global.json
35 lines
783 B
C#
35 lines
783 B
C#
using Serilog;
|
|
|
|
namespace Phantom.Utils.Events;
|
|
|
|
public abstract class ObservableState<T> {
|
|
public EventSubscribers<T> Subs { get; }
|
|
|
|
protected ObservableState(ILogger logger) {
|
|
Subs = new Subscribers(logger, this);
|
|
}
|
|
|
|
protected void Update() {
|
|
Subs.Publish(GetData());
|
|
}
|
|
|
|
protected void Update(object? sender, EventArgs e) {
|
|
Subs.Publish(GetData());
|
|
}
|
|
|
|
protected abstract T GetData();
|
|
|
|
private sealed class Subscribers : EventSubscribers<T> {
|
|
private readonly ObservableState<T> observer;
|
|
|
|
public Subscribers(ILogger logger, ObservableState<T> observer) : base(logger) {
|
|
this.observer = observer;
|
|
}
|
|
|
|
public override void Subscribe(object owner, Action<T> subscriber) {
|
|
base.Subscribe(owner, subscriber);
|
|
subscriber(observer.GetData());
|
|
}
|
|
}
|
|
}
|