Inpsect this page and copy the script tag, found in head tag, that ends in "main.js"
At the beginning of the head tag.
Inpsect this page and copy the script tag, found in head tag, that ends in "main.js"
At the beginning of the head tag.
The main purpose of this library is to mediate communication between different apps. The Library is nothing more than a messenger.
At the beginning of the head tag.
Considering the following app example. The methods ObserverReady and DetachingApp should be part of the app instance or else the app will not know when it's attached or detached from the observer mechanism.
function MyApp() {var self = this;selfdoSomething = function () {consolelog(arguments);}selfObserverReady = function(appReference observerReference) {appReferenceattachListener('myevent' selfdoSomethingbind(self));}selfDetachingApp = function (appReference observerReference) {appReferencedetachListener('myevent');}}var appInstance = new ();
We can use a predefined object to initialize:
windowObservables = windowObservables || {apps: [{instance: appInstancename: 'test'}]};
We can push the app in order to subscribe it:
windowObservablesappspush({instance: appInstancename: 'test'});// we can even subscribe various apps in the observer at oncewindowObservablesappspush({instance: appInstancename: 'test'} {instance: myOtherAppname: 'test2'});
Or we can subscribe it to the instance directly:
windowObservablesobserverInstancesubscribe('test' appInstance);
//the callback could be async if wanted.const callbackFunction = async (data) => {//do something with the eventreturn null; //something if you want}appReferenceattachListener('myevent' callbackFunction);appReferencedetachListener('myevent');
const myData = {test: true}// could be anything you want to pass as paramobserverReferencesubscribe('appName' appInstance);observerReferencetriggerCallback('eventName' myData (returns) => {// returns is an array of return values provided by all// the listeners of this event, or the first one if we// enable stop at first} {stopAtFirst: false //by default});const returns = await observerReferencetrigger('eventName' myData)//same like the triggerCallback but with promiseobserverReferenceisAppReady('appName')// returns a boolean stating whether a specific app is// ready or not (useful if our app initializes after,// we can easily check if that app is ready)