Modular Javascript #4 - PubSub Javascript Design Pattern

preview_player
Показать описание
Last video, we covered the revealing module pattern - where we expose an API allowing modules to talk to each other. This works well for smaller amounts of modules, but can have issues when many modules need to talk to each other.

In this video, we'll cover the pubsub design pattern (publish/subscribe), which allows us to decouple our modules. Once integrated with our pubsub module, they can emit events and not have to worry about which modules depend on them. Modules can subscribe to events and be notified when any module publishes.

-~-~~-~~~-~~-~-
Also watch: "Responsive Design Tutorial - Tips for making web sites look great on any device"
-~-~~-~~~-~~-~-
Рекомендации по теме
Комментарии
Автор

You teach me stuff I didn't even know I wanted to learn.

MarcelRobitaille
Автор

Not many people teach stuff like JS patterns in real life example, others just teach its concept, that's it!.
This is so helpful, and I can easily implement in my own project.

tea
Автор

Holy smoke I wish I had learned all of this before learning any javascript framework. Still love React, but now everything just make more sense.

willyboy
Автор

as a starting web developer I really learned a lot from your videos that even aren't taught at my college. easy to learn and pretty straightforward! thank you! now I'm really loving JavaScript!

edwardsimonvaldez
Автор

That is awesome... really great, simplest and non-confusing tutorial ever I have seen over pub-sub pattern.. ! :)

AmanGupta_Dev
Автор

Very well delivered, intriguing to follow. Casual at the same time. Thank you.

KoeneesKaras
Автор

So you're saying that we basically set people to fire whenever they changed? Awesome!

fire_g
Автор

I already pay for Laracasts, TreeHouse and CodeCourse. I guess I'm going to have to give you my money too. I'll support your channel but if you have a website, which I didn't see anywhere (so I'm possibly blind) I will buy you lunch each month for videos like this. Really great job man.

tmanley
Автор

That was an amazingly clear description of that pattern/usage.

CliffStamp
Автор

Thank you so much for the tutorial, JS suddenly makes a lot of sense to me. I can now say good bye to spaghetti codes! Thank you, you're awesome!

winnieyoong
Автор

im starting to see the need for frameworks like react with all these modules wanting to know what the other module is doing and when to update etc. interesting stuff!

whiskey
Автор

Yes! Was just digging into this pattern last night. Perfect timing. Thank you!

arbitraryCharacters
Автор

Thought id have to wait a bit longer for these! Nice little Thursday afternoon surprise! Cheers Will!

GifCoDigital
Автор

Here is my like, and here is my 'Thank You Sr.'

carlosbenavides
Автор

I came up with a slight variation on the revealing module pattern that allows you to raise and handle events that doesn't require a separate pubsub module. Rather than returning your api from the module as an anonymous object if you declare it as a variable you can trigger events on it that can be listened for externally (or internally if you need).

var controller = (function()
{
function doAThing()
{

}

var interface = {
doAThing: doAThing
};
return interface;
})();

$(controller).on("complete", function() { console.log("Thing Done"); });
controller.doAThing();

Zombieskelper
Автор

Wow didn't know about this pattern! Definitely gonna use. P.S. pro tip: don't use === when checking typeof :)

dice
Автор

Oh, sorry -- I see that you have the code in the next video. Thank you, super helpful!!!

mariaklachko
Автор

So powerful and yet so simple tool, very cool.

marioua
Автор

On your people.js file, how does *pubsub.publish("peopleChanged", people.length);* accomplish anything if the pubsub.js file actually has no instance of 'pubsub' anywhere?

AtacamaHumanoid
Автор

is this necessary if you use parcel or webpack?

thebrain
welcome to shbcf.ru