Using revealing module pattern and using sub modules for implementing library. For providing async notifications to the application from the library, using observer pattern.
myApp.utils = (function(){
var init = function(){
console.info('myApp:utils initialised');
};
return {
init: init
};
}());
myApp = window.myApp4 = (function(mA){
var initMessage = 'myApp initialised';
var subscribers = [];
var init = function () {
console.info(initMessage);
};
var subscribe = function (fn) {
subscribers.push(fn);
}
var publish = function () {
// loop thru subscriber array and call the callback fn
}
return {
init: init,
subscribe: subscribe
};
}(myApp || {}));
The problem here is how to publish events from the sub modules (myApp.utils) without making the notifier method public in the main module code. Is this something that could be done with the revealing module pattern?
Aucun commentaire:
Enregistrer un commentaire