ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

Ionic Beta: Changing Controllers/Delegates .. again!

Open ajoslin opened this issue 12 years ago • 38 comments

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

ajoslin avatar Mar 24 '14 16:03 ajoslin

Great idea with multiple handles of same name, will implement it :-)

ajoslin avatar Mar 24 '14 23:03 ajoslin

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.

rvanbaalen avatar Mar 25 '14 01:03 rvanbaalen

@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.

ajoslin avatar Mar 25 '14 01:03 ajoslin

+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:

rvanbaalen avatar Mar 25 '14 01:03 rvanbaalen

Agreed +1 for getByHandle

mhartington avatar Mar 25 '14 01:03 mhartington

Makes good sense to me.

mbuster avatar Mar 25 '14 01:03 mbuster

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!'

ajoslin avatar Mar 25 '14 01:03 ajoslin

I like the way forHandle reads in the client code. :-)

keithdmoore avatar Mar 25 '14 01:03 keithdmoore

All delegates added to master, and docs updated! http://ajoslin.github.io/docs/nightly

ajoslin avatar Mar 25 '14 02:03 ajoslin

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())

ajoslin avatar Mar 25 '14 02:03 ajoslin

You mean : $ionicNavBarDelegate.$getByHandle()) , right?

calendee avatar Mar 25 '14 11:03 calendee

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?

rvanbaalen avatar Mar 25 '14 11:03 rvanbaalen

@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 :-)

ajoslin avatar Mar 25 '14 13:03 ajoslin

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 avatar Mar 25 '14 13:03 rvanbaalen

@rvanbaalen Please let us know any problems with how your app works! We're ramping up testing for hopefully a release today.

ajoslin avatar Mar 25 '14 13:03 ajoslin

@ajoslin In that case, please take a look at https://github.com/driftyco/ionic/issues/879

rvanbaalen avatar Mar 25 '14 13:03 rvanbaalen

Landed

ajoslin avatar Mar 27 '14 01:03 ajoslin

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.

ionitron-bot[bot] avatar Sep 06 '18 06:09 ionitron-bot[bot]