I have two separate GUIs that are part of the same system. One at the top of the screen (navEditor) and one on the side (routeEditor).
They need two update each other frequently, and call each others functions.
Each has service that holds most of that systems functions. I ran into an issue when I tried to call functions from both A->B and B->A. It, of course, created a circular dependency because I had to include them in each other to gain access.
I looked into several solutions including using $rootScope.$broadcast. However, one common suggestion (found here: angular JS - communicate between non-dependend services) suggested a "subscriber/publisher" method that wired the two together.
This avoids the circular dependency by using a 3rd service and having the other services attach events and handlers to it.
I took this a step further and simply had this parent service return an object with a place holder object for each of my two systems:
//BRIDGE SERVICE
myApp.service('$trafficSys', function(){
this.sys = {
navEditor: {}, //poulated by $routeEditor service
routeEditor: {} ////poulated by $navEditor service
}
});
//ROUTE-EDITOR
myApp.service('$routeEditor', ['$trafficSys',function($trafficSys) {
var routeSystem = {
//entire route editor system goes in here
}
$trafficSys.sys.routeEditor = routeSystem;
}]);
//NAV-EDITOR (Same Process as Route Editor)
I then simply had my "navEditor" & " routeEditor" services include $trafficSys and then apply all of thier funcitons to either the navEditor or routeEditor objects.
What I would like to know is if this is considered an Anti-Pattern, and if I am being more imperative rather than declarative.
I am not very experienced with large applications. I'm learning angular so I can push myself to think more about architecture. However, I am finding my lack of foresight is leading me to doubt if i'm doing things the best way.
Any advice would be appreciated.