0

One of the most convenient things about AngularJS was the two-way binding. Would it be advisable to replicate that with a much smaller library like PubSubJS and not use AngularJS? Or, would that create many more events that PubSubJS is intended to handle?

For example, imagine a form app where you type a first name into an input and that publishes the firstName event. There is a subscriber for the name that add that to the page title and an <h2/> at the top of the page. Then you select an option in the "Level of Education" select and it publishes "Masters Degree". Then a subscriber displays other inputs based on the value.

So that is a fairly simple example of course but could PubSubJS be used like that to build a more complex single-page app with might have been $scope.firstName in AngularJS now just being the firstName event with the value as a param? The benefits being that is a much small library and you have a much more fault-tolerant decoupling of the code but that would also mean that a lot of events are being fired. Another benefit of it would be that you could go back and later write something like a page interaction analytics module that tracks events without ever having to touch the original code.

Rozgonyi
  • 1,027
  • 13
  • 27

1 Answers1

0

I don't know about PubSub (I'm not familiar) but the pattern used by angularjs is basically the same thing as MVVM (Model-View View-Model) or any other two-way binding mechanisms. So I think yes it could be duplicated.

EDIT: Sorry, you were asking if was advisable. I'd say no, other emerging functional approaches are better suited.

Stradosphere
  • 1,285
  • 3
  • 14
  • 40