- Notifications
You must be signed in to change notification settings - Fork 8
Messenger API
supermax edited this page Jun 28, 2020
·
3 revisions
// Messenger InterfacepublicinterfaceIMessenger{// Subscribe callback to receive a payload// Predicate to filter the payload (optional)IMessengerSubscribe<T>(Action<T>callback,Predicate<T>predicate=null);// Unsubscribe the callback from receiving the payload IMessengerUnsubscribe<T>(Action<T>callback);// Publish the payload to its subscribersIMessengerPublish<T>(Tpayload);}Access to default Messenger instance via:
SuperMaxim.Messaging.Messenger.Default.[function]// Generic Parameter <T> - here is a <Payload> that will be published to subscribers of this typeMessenger.Default.Publish<Payload>(newPayload{/* payload params */});// In most cases there is no need in specifying Generic Parameter <T>Messenger.Default.Publish(newPayload{/* payload params */});// Generic Parameter <T> - here is a <IPayload> that will be published to subscribers of this typeMessenger.Default.Publish<IPayload>(newPayload{/* payload params */});classPayload:IPayload{}// Payload – the type of Callback parameter// Callback – delegate (Action<T>) that will receive the payloadMessenger.Default.Subscribe<Payload>(Callback);privatestaticvoidCallback(Payloadpayload){// Callback logic}// Predicate – delegate (Predicate<T>) that will receive payload to filterMessenger.Default.Subscribe<Payload>(Callback,Predicate);privatestaticboolPredicate(Payloadpayload){// Predicate filter logic// if function will return ‘false’ value, the Callback will not be invokedreturnaccepted;}// Payload – the type of Callback parameter that was subscribed// Callback – delegate (Action<Payload>) that was subscribedMessenger.Default.Unsubscribe<Payload>(Callback);privatestaticvoidCallback(Payloadpayload){// Callback logic}// IPayload – the type of Callback parameter that was subscribed// Callback – delegate (Action<Payload>) that was subscribedMessenger.Default.Unsubscribe<IPayload>(Callback);// Payload class implements IPayload interfaceprivatestaticvoidCallback(Payloadpayload){// Callback logic}