I'm creating a sort of library based on the mediator for my work. We create lots of applications so I wanted something that can easily be taken and modified on a per app basis. I also want it to be easy enough to create "widgets" (for lack of a better term) and easy to remove them without worrying about breaking anything. Many of these apps we make are also extendable by outside developers making apps or widgets for the apps.
That's how I came across the mediator pattern. I wrote up something that works something like this:
//Extend
Core.extend('widget',function(params){
alert(params.message);
});
//Load it
Core.load('widget',{message:'Hello World'});
//Remove it
Core.remove('widget');
I have 3 questions tho:
How do/should you deal with DOM manipulation in this pattern with JavaScript? I don't want developers messing with the DOM outside of their widget.
How do/should you deal with AJAX requests. Should you do anything at all? Should you just offer a AJAX/JSONP call in the library (
Core
in this example).My biggest question, how do you actually interact with other widgets? I don't want to tight couple (obviously), but I don't get how you'd interact with another widget. For example, let's say you have a text box and on submit it sends it to a DB. How can another widget, lets call it the "timeline" widget, now when it was submitted and then update the timeline with the text from the text box widget?
===UPDATE===
I ended up writing this: