Skip to content

Commit

Permalink
Implemented a bunch of base message types with static instances store…
Browse files Browse the repository at this point in the history
…d to avoid useless allocations and make code more fluent
  • Loading branch information
bustedbunny committed Apr 8, 2023
1 parent dd168e6 commit 4e5835d
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Runtime/Messaging/Messages/BaseTagMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace MVVMToolkit.Messaging
{
public abstract class BaseTagMessage<TType> where TType : new()
{
private static readonly TType Instance = new();

public static TType Message() => Instance;
}
}
3 changes: 3 additions & 0 deletions Runtime/Messaging/Messages/BaseTagMessage.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Runtime/Messaging/Messages/BaseValueMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace MVVMToolkit.Messaging
{
public abstract class BaseValueMessage<TValue>
{
public TValue value;
}
}
3 changes: 3 additions & 0 deletions Runtime/Messaging/Messages/BaseValueMessage.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Runtime/Messaging/Messages/CloseViewsMessage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MVVMToolkit.Messaging
{
public class CloseViewsMessage { }
public class CloseViewsMessage : BaseTagMessage<CloseViewsMessage> { }
}
14 changes: 14 additions & 0 deletions Runtime/Messaging/Messages/ValueMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace MVVMToolkit.Messaging
{
public abstract class ValueMessage<TType, TValue> : BaseValueMessage<TValue>
where TType : BaseValueMessage<TValue>, new()
{
private static readonly TType Instance = new();

public static TType Message(TValue value)
{
Instance.value = value;
return Instance;
}
}
}
3 changes: 3 additions & 0 deletions Runtime/Messaging/Messages/ValueMessage.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4e5835d

Please sign in to comment.