Cleanup send functions

This commit is contained in:
Frank A. Krueger 2017-06-14 23:27:28 -07:00
parent 592b7e4bc2
commit 0683cf91ed
1 changed files with 8 additions and 21 deletions

View File

@ -22,7 +22,12 @@ namespace Ooui
protected EventTarget (string tagName) protected EventTarget (string tagName)
{ {
TagName = tagName; TagName = tagName;
SendCreate ();
Send (new Message {
MessageType = MessageType.Create,
TargetId = Id,
Key = TagName,
});
} }
public void AddEventListener (string eventType, EventHandler handler) public void AddEventListener (string eventType, EventHandler handler)
@ -41,7 +46,7 @@ namespace Ooui
handlers.Add (handler); handlers.Add (handler);
if (sendListen) if (sendListen)
SendListen (eventType); Send (Message.Listen (Id, eventType));
} }
public void RemoveEventListener (string eventType, EventHandler handler) public void RemoveEventListener (string eventType, EventHandler handler)
@ -74,19 +79,10 @@ namespace Ooui
public virtual void Send (Message message) public virtual void Send (Message message)
{ {
SaveStateMessage (message); SaveStateMessageIfNeeded (message);
MessageSent?.Invoke (message); MessageSent?.Invoke (message);
} }
protected void SendCreate ()
{
Send (new Message {
MessageType = MessageType.Create,
TargetId = Id,
Key = TagName,
});
}
protected void SendCall (string methodName, params object[] args) protected void SendCall (string methodName, params object[] args)
{ {
Send (new Message { Send (new Message {
@ -107,15 +103,6 @@ namespace Ooui
}); });
} }
protected void SendListen (string eventType)
{
Send (new Message {
MessageType = MessageType.Listen,
TargetId = Id,
Key = eventType,
});
}
public virtual void Receive (Message message) public virtual void Receive (Message message)
{ {
if (message == null) if (message == null)