Bubble up child messages
This commit is contained in:
parent
952611dcdf
commit
bfaf883c76
|
@ -100,9 +100,12 @@ namespace Ooui
|
||||||
return $"{IdPrefix}{id}";
|
return $"{IdPrefix}{id}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Send (Message message)
|
public void Send (Message message)
|
||||||
{
|
{
|
||||||
SaveStateMessageIfNeeded (message);
|
if (message == null)
|
||||||
|
return;
|
||||||
|
if (message.TargetId == Id)
|
||||||
|
SaveStateMessageIfNeeded (message);
|
||||||
MessageSent?.Invoke (message);
|
MessageSent?.Invoke (message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +124,7 @@ namespace Ooui
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Receive (Message message)
|
public void Receive (Message message)
|
||||||
{
|
{
|
||||||
if (message == null)
|
if (message == null)
|
||||||
return;
|
return;
|
||||||
|
@ -194,7 +197,7 @@ namespace Ooui
|
||||||
|
|
||||||
public override object ReadJson (Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
|
public override object ReadJson (Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException ();
|
throw new NotSupportedException ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanConvert (Type objectType)
|
public override bool CanConvert (Type objectType)
|
||||||
|
|
12
Ooui/Node.cs
12
Ooui/Node.cs
|
@ -43,13 +43,15 @@ namespace Ooui
|
||||||
public Node InsertBefore (Node newChild, Node referenceChild)
|
public Node InsertBefore (Node newChild, Node referenceChild)
|
||||||
{
|
{
|
||||||
if (referenceChild == null) {
|
if (referenceChild == null) {
|
||||||
|
newChild.MessageSent += HandleChildMessageSent;
|
||||||
children.Add (newChild);
|
children.Add (newChild);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var index = children.IndexOf (referenceChild);
|
var index = children.IndexOf (referenceChild);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
throw new ArgumentException ("Reference must be a child of this element", nameof(referenceChild));
|
throw new ArgumentException ("Reference must be a child of this element", nameof (referenceChild));
|
||||||
}
|
}
|
||||||
|
newChild.MessageSent += HandleChildMessageSent;
|
||||||
children.Insert (index, newChild);
|
children.Insert (index, newChild);
|
||||||
}
|
}
|
||||||
SendCall ("insertBefore", newChild, referenceChild);
|
SendCall ("insertBefore", newChild, referenceChild);
|
||||||
|
@ -58,9 +60,12 @@ namespace Ooui
|
||||||
|
|
||||||
public Node RemoveChild (Node child)
|
public Node RemoveChild (Node child)
|
||||||
{
|
{
|
||||||
|
if (child == null)
|
||||||
|
return null;
|
||||||
if (!children.Remove (child)) {
|
if (!children.Remove (child)) {
|
||||||
throw new ArgumentException ("Child not contained in this element", nameof(child));
|
throw new ArgumentException ("Child not contained in this element", nameof(child));
|
||||||
}
|
}
|
||||||
|
child.MessageSent -= HandleChildMessageSent;
|
||||||
SendCall ("removeChild", child);
|
SendCall ("removeChild", child);
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
@ -73,6 +78,11 @@ namespace Ooui
|
||||||
InsertBefore (newNode, null);
|
InsertBefore (newNode, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HandleChildMessageSent (Message message)
|
||||||
|
{
|
||||||
|
Send (message);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void SaveStateMessageIfNeeded (Message message)
|
protected override void SaveStateMessageIfNeeded (Message message)
|
||||||
{
|
{
|
||||||
switch (message.MessageType) {
|
switch (message.MessageType) {
|
||||||
|
|
Loading…
Reference in New Issue