JavaScript publish-subscribe pattern with dependencies.