Skip to content

Commit 4753634

Browse files
committed
Move Widgets.Mediator to its own file
1 parent 2e05e81 commit 4753634

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

OpenRA.Game/Widgets/Mediator.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#region Copyright & License Information
2+
/*
3+
* Copyright (c) The OpenRA Developers and Contributors
4+
* This file is part of OpenRA, which is free software. It is made
5+
* available to you under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation, either version 3 of
7+
* the License, or (at your option) any later version. For more
8+
* information, see COPYING.
9+
*/
10+
#endregion
11+
12+
using OpenRA.Primitives;
13+
14+
namespace OpenRA.Widgets
15+
{
16+
public sealed class Mediator
17+
{
18+
readonly TypeDictionary types = new();
19+
20+
public void Subscribe<T>(T instance)
21+
{
22+
types.Add(instance);
23+
}
24+
25+
public void Unsubscribe<T>(T instance)
26+
{
27+
types.Remove(instance);
28+
}
29+
30+
public void Send<T>(T notification)
31+
{
32+
var handlers = types.WithInterface<INotificationHandler<T>>();
33+
34+
foreach (var handler in handlers)
35+
handler.Handle(notification);
36+
}
37+
}
38+
39+
public interface INotificationHandler<T>
40+
{
41+
void Handle(T notification);
42+
}
43+
}

OpenRA.Game/Widgets/Widget.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -441,32 +441,4 @@ public WidgetArgs(Dictionary<string, object> args)
441441
: base(args) { }
442442
public void Add(string key, Action val) { base.Add(key, val); }
443443
}
444-
445-
public sealed class Mediator
446-
{
447-
readonly TypeDictionary types = new();
448-
449-
public void Subscribe<T>(T instance)
450-
{
451-
types.Add(instance);
452-
}
453-
454-
public void Unsubscribe<T>(T instance)
455-
{
456-
types.Remove(instance);
457-
}
458-
459-
public void Send<T>(T notification)
460-
{
461-
var handlers = types.WithInterface<INotificationHandler<T>>();
462-
463-
foreach (var handler in handlers)
464-
handler.Handle(notification);
465-
}
466-
}
467-
468-
public interface INotificationHandler<T>
469-
{
470-
void Handle(T notification);
471-
}
472444
}

0 commit comments

Comments
 (0)