Ionic Beta: Changing Controllers/Delegates .. again!
Old Delegate System (0.9.x)
Was very easy-to-use, but not powerful.
If you wanted to target a specific instance of something, for example only make one specific ion-content scroll to top, it was not possible.
New Controller System (nightly)
Very powerful, but hard to use for some common cases. For example, if I have a "MainCtrl" on the body, then two scopes down an ion-content, the MainCtrl's scope can't reach the $ionicScrollController on the ion-content. Also, the new solution is very hard to write tests for.
Fixing both problems: Delegates plus Unique IDs (idea for 1.0)
The easiest way to explain is within the example in this short gist: https://gist.github.com/ajoslin/c1bed34eb83aeffdba4b
What do you guys think?
/cc @calendee @rvanbaalen @mhartington @mlynch @adamdbradley and everyone else who wants to input
Great idea with multiple handles of same name, will implement it :-)
I agree with @mbuster's forHandle approach. But you must be careful here since in programming terms, for means something completely different than what we're trying to achieve. set would in that case be more appropriate to the current action; We're getting a scroll delegate object and setting a handler for it with setHandler: $ionicScrollDelegate.setHandle('daddy');
That's just a formality of course. Good job on the documentation @ajoslin.
@adamdbradley made me realize forHandle makes people think of a for loop! @rvanbaalen you think same.
So I think we decided $ionicScrollDelegate.getByHandle is good.
+1 Best of all proposed solutions. Makes a lot more sense than my last comment about 'setting' the handle. It's actually geting the handle of course :smile:
Agreed +1 for getByHandle
Makes good sense to me.
In the words of Adam ... 'man, can you imagine what it must be like to debate what ES6 should be like....for years and years!'
I like the way forHandle reads in the client code. :-)
All delegates added to master, and docs updated! http://ajoslin.github.io/docs/nightly
Also, renamed getByHandle to $getByHandle ($-prefix) so it would look different than the other methods on the delegate (eg $ionicNavBarDelegate.getTitle() was looking too alike to $ionicNavBarDelegate.getByHandle())
You mean : $ionicNavBarDelegate.$getByHandle()) , right?
So, let me get this straight. All $scope.$ionicControllerName controllers are now rewritten to $ionicControllerNameDelegates? With a matching $getByHandle().
For instance, I'm using the $scope.$ionicSideMenusController to toggle my left and right side menus. Should I refactor this to the new delegate way?
@calendee that's right!
@rvanbaalen yes, except we used the old name for side menus - $ionicSideMenuDelegate.
It's all up at http://ajoslin.github.io/docs/nightly now.
So after all the craziness, we've finally arrived back at delegates - the improved version.
And it was because of all of you nightly users that we realized the problems. So thank you :-)
Thank god it was so awkward using $ionicSideMenu_s_ ;-) Well.. I better suit up for a new round of refactoring and update with bower.
@rvanbaalen Please let us know any problems with how your app works! We're ramping up testing for hopefully a release today.
@ajoslin In that case, please take a look at https://github.com/driftyco/ionic/issues/879
Landed
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.