Import Statement: | import . |
AppListener is a helper class to listen dispatched signal from AppDispatcher. It provides an alternative solution other then using Connections component. Moreover, it offers a way to control the order of signal delivery through waitFor property.
Example:
// Only listen for specific message AppListener { filter: "messageType1"; onDispatched: { // Your code here } } // Listen for multiple messages. AppListener { onDispatched: { switch (type) { case "messageType1": // ... break; case "messageType2": // ... break; } } } // Alternative method to listen for multiple messages AppListener { Component.onComponented: { on("messageType1",function() { /// Your code here. }); on("messageType2",function() { /// Your code here. }); } }
This property holds a value to indicate if the listener should remain listening message when it is not enabled.
This property holds whether the listener receives message. If it is false, it won't emit "dispatched" signal and trigger callback registered via "on" function. By default this is true.
The value can be controlled by parent component. Setting this property directly affects the enabled value of child items. When set to false, the enabled values of all child items also become false. When set to true, the enabled values of child items are returned to true, unless they have explicitly been set to false.
Set a filter to incoming messages. Only message with type matched with the filter will emit "dispatched" signal. If it is not set, it will dispatch every message.
Set a list of filter to incoming messages. Only message with type matched by the filters will emit "dispatched" signal. If it is not set, it will dispatch every message.
The listener ID of this component. It could be used with AppListener::waitFor / AppDispatcher::waitFor to control the order of message delivery.
If it is set, it will block the emission of dispatched signal until all the specificed listeners has been invoked.
Example code:
AppListener { id: listener1 } AppListener { id: listener2 waitFor: [listener1.listenerId] }
It is a proxy of AppDispatcher.dispatched signal. If the enabled property is set to false, this signal will not be emitted.
Add a listener to the end of the listeners array for the specified type of message. Multiple calls passing the same combination of event and listener will result in the listener being added multiple times.
Remove all the listeners for a message with type. If type is empty, it will remove all the listeners.
Remove a listener from the listener array for the specified message.