// dispatch function for handling filtered message response callbacks private bool dispatchResponse(string eventLabel, params object[] arguments) { var data = arguments; if (this.listeners.ContainsKey(eventLabel)) { List <object> listenersForEvent = listeners[eventLabel]; foreach (object listenerForEvent in listenersForEvent) { if (listenerForEvent.GetType() == typeof(JObjectWithActions)) { JObjectWithActions listenerObj = (JObjectWithActions)listenerForEvent; if (listenerObj["filters"] != null) { { JObject filtersObj = (JObject)listenerObj["filters"]; JObject dataObj = (JObject)data[0]; if (Symple.match(filtersObj, dataObj)) { Action <object> fn = listenerObj.actions["fn"]; fn(data); if (listenerObj["after"] != null) { Action <object> after = listenerObj.actions["after"]; after(data); } return(true); } } } } } } return(false); }
private void onResponse(string eventLabel, JObject filters, Action <object> fn, Action <object> after) { if (!this.listeners.ContainsKey(eventLabel)) { this.listeners[eventLabel] = new List <object>(); } if (fn != null) { JObjectWithActions listener = new JObjectWithActions(); listener.actions["fn"] = fn; listener.actions["after"] = after; listener["filters"] = filters; this.listeners[eventLabel].Add(listener); } }