PubSub / Loosely Coupled and MVC templates in Javascript

Ok, I'm new to this, I tried to learn about MVC templates and Javascript / jQuery publish / subscribe templates, however I believe that I did not fully understand the concept.

Since I am doing this alone, I humbly come here to ask for an opinion on a small training exercise that I tried to do after these templates

http://jsfiddle.net/Couto/R62V8/

Well, the exercise is basically a login form, where the values ​​are stored in localStorage, again purely training, now I'm not sure about the security and should not be used in production.

Could you tell me your opinion about the templates used, have I been able to achieve the correct use of the templates? Please hurt me if necessary, I just want to study, but I'm not sure that I am doing it right.

+6
javascript jquery design-patterns model-view-controller publish-subscribe
source share
1 answer

jQuery event delegation system is a form of pub / sub. Actually check this out, http://bugs.jquery.com/ticket/7547 . You will see under the hood that it uses an event system and really only changes the naming scheme and works in a "global" context.

I have nothing against pub / sub, but you feel that you are adding a layer that should not exist in certain cases. Would you release the correct function immediately after the event delegation occurs, and not the pub launch is really worse? If you delete the subscription and the publication, you will get almost the same code without additional "complexity".

In other cases, publishing / subscribing makes a lot of sense. Your display / hash and set / login make a lot of sense, as they are not part of a traditional event that may be signed by other code.

It could be argued that, using everywhere in pub / sub, including when delegating events, you abstract away from your dependence on external code from the need to create your own event delegates, which eliminates their concern about which element the delegate is bound to. If you write large complex applications, go ahead and abstract them to this level. If you are not planning to write large applications, consider the benefits that YAGNI can take here.

+2
source share

All Articles