If we find that there is still a need to send the scope in that can’t be 
reasonably worked around, then the action services could be changed to be a 
factory. The injected action factory should have a factory function called by 
the controller which creates an instance of the action in each controller.  
Then the init scope could be called on the instance of that action. This also 
would then allow actions to have state that is retained for the lifetime of the 
controller, while not worrying about sharing action state with other 
controllers.

-Travis
From: Richard Jones <r1chardj0...@gmail.com>
Reply-To: OpenStack List <openstack-dev@lists.openstack.org>
Date: Friday, July 15, 2016 at 2:28 PM
To: OpenStack List <openstack-dev@lists.openstack.org>
Subject: [openstack-dev] [Horizon] Angular action services and initScope

Hi folks,

Something that's been bothering me for a while is that the action services 
break the encapsulation model of Angular Services - that they are singletons, 
and consumable by multiple simultaneous consumers without those consumers 
affecting each other through their use of the Service.

At the moment the initScope() functionality we've included in the action 
services breaks that model - at a minimum it is possible for multiple consumers 
to initScope() with different scopes simultaneously. This is the reason why 
I've been arguing (ok, "debating" :-) for the cessation of using scopes in this 
way.

I think we need to do two things reasonably soon (before patterns become more 
ingrained):

1. Stop passing in $scope to initScope in all cases - the new 
ActionResult-enabled pattern should hopefully replace all those
2. Remove all initScope methods altogether. The only other use of initScope 
that I see is the pre-loading of data used during the execution of action 
allowed() methods. We should move that preloading/caching either into the 
creation of the Service object itself, or into the allowed method.

If there is a use-case of initScope that I've missed (something that needs to 
be execute *after* the Service is created, not something that needs to tie the 
Service to a particular consumer of the service) then please let me know :-)


     Richard

__________________________________________________________________________
OpenStack Development Mailing List (not for usage questions)
Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev

Reply via email to