|
|
The EventManagerObserver is a ES6 class. It's main purpose is to handle any changes occured to the EventManager collection.
|
|
|
To achieve this the EMO instance is created by the IronRouter before the page gets loaded. Any Meteor method call will push the name of the method and a few variables required to find the changed document in the respective collection.
|
|
|
|
|
|
It is possible to assign multiple callbacks to the onChanged function of the EMO. Each callback will be inserted if it was not inserted previously. Any changes which the EMO detects will trigger only those callbacks for the currently active route and which selector parameters are matching the Meteor method name.
|
|
|
|
|
|
So for example a onChange callback looks as following:
|
|
|
```
|
|
|
import {globalEventStackObserver} from '/client/plugins/event_stack_observer/scripts/lib.js';
|
|
|
|
|
|
globalEventStackObserver.onChange([
|
|
|
"EventManagerCollection.setSessionStatus",
|
|
|
"EventManagerCollection.reset"
|
|
|
], function (key, value) {
|
|
|
if (!isNaN(value.sessionStatus)) {
|
|
|
if (value.sessionStatus < 2) {
|
|
|
if (!localData.containsHashtag(Router.current().params.quizName)) {
|
|
|
new ErrorSplashscreen({
|
|
|
autostart: true,
|
|
|
errorMessage: TAPi18n.__("plugins.splashscreen.error.error_messages.session_closed")
|
|
|
});
|
|
|
}
|
|
|
Router.go("/" + Router.current().params.quizName + "/resetToHome");
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
```
|
|
|
First of all the globalEventStackObserver variable has to be imported.
|
|
|
Now we can call the onChange method of the observer. This method requires two parameters: An array containing the names of the Meteor methods where the observer shall trigger the callback and secondly the callback which will receive a key (the corresponding Meteor method name) and a value (which is an object containing the relevant document keys to find the specific changed document in the collection).
|
|
|
|
|
|
The callback should do some validation checks (for example if the passed value member is a number or an array).
|
|
|
|
|
|
Please note that is not required to delete any callbacks. Since they get only called while in their specific scope (the current route) there is no need to save the callback in a variable and delete it when the template gets destroyed. |
|
|
\ No newline at end of file |