Modular Javascript #5 – PubSub Implementation



Let's take the pubsub pattern that we learned from the last video and integrate it with a few other JS modules. The result will be 2 modules that are very loosely coupled to other modules.

This loose coupling will allow the application to grow significantly larger without encountering problems.

Again, here's the pubsub code I'm using here: https://gist.github.com/learncodeacademy/777349747d8382bfb722

And here's all the HTML/CSS/JS on CodePen:
http://codepen.io/anon/pen/LVXrao

code source

  • you are a real hero.

    View Comment
  • Since you had been using jQuery in previous videos, I think it would have been great to have used jQuery custom events to show how to pub/sub through different modules on an application .. beginners would love it …

    View Comment
  • Big thanks for Great Video.
    Could you please clarify me, How the setPeople() and render methods getting triggered from events object, even though execution stack of setPeople popped off.

    View Comment
  • Just a question, we should link the modules.js file at the bottom of the index.html… otherwise it couldn't work… is it a good practice?

    View Comment
  • great series ;)

    View Comment
  • Another Great Video ! =) Big thanks

    View Comment
  • Considering this line: events.on('peopleChanged, setPeople); what are the mechanics behind how the emit function can actually call the setPeople method inside the stats module, since it has been wrapped in an IIFE; rendering everything inside private.

    Could the answer be that what this line of code actually does is to pass a reference i.e a pointer to its internal scope to the events object, where it is stored and that how it can execute and be called in the right context. Is any of this correct?

    View Comment
  • more than awesome teaching style, loved it, so far it was too difficult for me to understand js pattern, u made it peace of cake. thank you so much, looking for almost anything you going to post

    View Comment
  • Is there any way that you can share the html and css code? Well, never mind, I just saw the description about your css and html code.

    View Comment
  • This is so helpful. Thank you. Please do another pattern!

    View Comment
  • Any interest in diving into Angular 2 in the near future? Would love to hear your thoughts on it.

    View Comment
  • I really like this series. Good work!

    View Comment
  • Hi! I'm a new computer science student at UT Austin, and I just want to say thank you for making these videos. I've never programmed before but following your videos have taught me a lot. Please keep it up!

    View Comment
  • Isn't this the Observer Pattern?

    View Comment
  • Great videos!!! I love your series on this. Hopefully, in the future, you will cover more JS design patterns.

    View Comment
  • Hey, I love these videos and surely hope you continue this Modular JS series!!
    I have one small question though…
    In the first implementation – when you call stats.setpeople directly from people and not via the pubsub – you use stats inside of the people module.
    Is it important to have you stats.js included before people.js in your html or how does people.js know the stats variable exists??

    View Comment
  • Great videos LearnCode.academy. I really like the way you explain minor things in details with examples. Could you please make some videos for JavaScript Unit testing using KarmaJS, JasmineJS for Angular applications?

    View Comment
  • Please add more pattern.

    View Comment
  • Also I've had trouble with emmet on PC any help?

    View Comment
  • Hi code.academy
    I was wonder what skill level you think someone should be at before applying for a job? Also does country location matter? Can you work for a place half way across the world?
    

    View Comment
  • These 5 videos are great. If I could make a request, it would be a follow up on how to test these functions. TDD has come up so often for me, and to be honest, I'm always at a loss on what to test, how to test for it, etc. 

    View Comment
  • Thanks to your series I realized my JS sucks, where can I learn more about advanced JS stuff?

    View Comment
  • Like the the idea of pubsub pattern. I'm just curious that if our app's growing bigger and bigger, would it be hard to find where the event's emitted from? Would it be harder to debug the app?

    View Comment