Hacker News new | ask | show | jobs
by mandeepj 4143 days ago
Looks like you know what you are doing. Good.

>With my session example, we use the session object to display the user's name in various places. It's easy to use the session object to do this; I can just stick it in the view.

Correct. No need for pub\sub here since data is coming from server and we are not manipulating it. Pub\sub is required in scenarios where actions are taking place on client side like user registration, forgot pwd or ordering a product etc

> A session is a global thing, isn't it? Why wouldn't it belong in the global context?

Absolutely. Session is more of a read-only object after once set on the server. I know some people use it to store objects and that is not right.

A bad example of a global object would be

var settings =

{ showCheckoutbutton: false, Ordertotal: 200, calculatedtax: false, showOffers: true, ShowTopbar: false }

I constructed this hypothetical object just to give an idea about an evil entity. Some developers would set certain properties in certain functions. It would definitely show zombie behaviour at certain times.

I enjoyed our conversation. Thanks for being so nice with your response.