Modules + Fascade + Mediator Combination in JavaScript

I ended up reading an excellent article on http://addyosmani.com/largescalejavascript/

This article explains how to combine modules, facade, and pick together for a JavaScript application.

I can indicate what the article explains, but I don’t understand why I need to use the facade to access the intermediary.

I think that I can access the intermediary directly from my modules.

Please advise me ..

PS: Is that the right question?

+5
source share
2 answers

, Pro Javascript Design Patterns, , :

. . ; , .

+3

Thedric Walker...

, , :

- (), (), - (). ( , ) , - (Application Architect) . , , , . , , , .

, ?

Addy - Facade , , , . . , , :

var node = getNode('#errorPanel'); node.innerHTML = 'Field is invalid!';

- :

notifyUser.error('Field is invalid!');

, , , mediator.fire('error:Validation', 'Field is invalid!').

Addy, , . , - , , , , , . .

- (.. ) , - "" Core, Facade. , . mediator.fire('ready://Core') mediator.fire('updated://ToDos/task', taskId). facade 'updated://ToDos/task' core - :

var thus = mediator.installTo(this);
this.on('updated://ToDos/task', function(id){
    thus.fire('request://Core/save/todo', id);
    thus.fire('user://Core/notify/task/added', id);
});
this.on('response://Core/save/todo', function(err, id){
    if(!err){
        // ... success -- notify module!
    } else {
        // ... notify for failure :(
    }
});

! !

, , ;)

0

All Articles