Bubble up child messages

This commit is contained in:
Frank A. Krueger 2017-06-16 17:07:30 -07:00
parent 952611dcdf
commit bfaf883c76
2 changed files with 19 additions and 6 deletions

View File

@ -100,9 +100,12 @@ namespace Ooui
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);
}
@ -121,7 +124,7 @@ namespace Ooui
});
}
public virtual void Receive (Message message)
public void Receive (Message message)
{
if (message == null)
return;
@ -194,7 +197,7 @@ namespace Ooui
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)

View File

@ -43,13 +43,15 @@ namespace Ooui
public Node InsertBefore (Node newChild, Node referenceChild)
{
if (referenceChild == null) {
newChild.MessageSent += HandleChildMessageSent;
children.Add (newChild);
}
else {
var index = children.IndexOf (referenceChild);
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);
}
SendCall ("insertBefore", newChild, referenceChild);
@ -58,9 +60,12 @@ namespace Ooui
public Node RemoveChild (Node child)
{
if (child == null)
return null;
if (!children.Remove (child)) {
throw new ArgumentException ("Child not contained in this element", nameof(child));
}
child.MessageSent -= HandleChildMessageSent;
SendCall ("removeChild", child);
return child;
}
@ -73,6 +78,11 @@ namespace Ooui
InsertBefore (newNode, null);
}
void HandleChildMessageSent (Message message)
{
Send (message);
}
protected override void SaveStateMessageIfNeeded (Message message)
{
switch (message.MessageType) {