zenangst / Spots

:bamboo: Spots is a cross-platform view controller framework for building component-based UIs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve didSelect method

zenangst opened this issue · comments

When we implemented willDisplay and endDisplay, we included the view into the delegate method.
I think there is potential to include the view that was tapped in didSelect(item: Item, in spot: Spotable) as well.

So it would end up looking something like this:

func spotsDidSelect(view: SpotView, item: Item, in spot: Spotable) {

This would kind of make the method into a trio instead of having one of them standout for being less "cool".

What do you think? @hyperoslo/ios

Updated

I updated the example to include the framework name.

commented

@zenangst yeah we could do that. For now I think we can use ui method to retrieve the View?

This is correct :)

Would be a nice addition 👍

I propose that the version 6.0.0 version would look something like this;

func spotsDidSelect(view: SpotView, item: Item, in spot: Spotable) {

@JohnSundell mentioned a variation of this that can also be very interesting (sorry mate, forgot about that).

It would end up looking something like this:

func spot(view: SpotView, _ spot: Spotable, itemSelected item: Item)

I just thought about another variant.

func spotsDid(selectView view: SpotView, itemSelected item: Item, in spot: Spotable)

The way I would name the above method is:

func spotable(_ spot: Spotable, itemSelected item: Item, view: SpotView)

Reasoning: The first argument should always match the object that you're the delegate for. This is both in line with Apple's naming convention, but also improves API discoverability and makes for an easier grouping of methods (and better auto complete). _ is used because it's clear from the method name that the first argument is going to be a Spotable. The verb is not formulated as didSelect because in this case the Spot itself didn't select the item - the user did. This would be different if it was (for example) an image loader that itself downloaded an image (func imageLoader(_ imageLoader: ImageLoader, didLoadImage image: UIImage)).

Oh, I don't think I'm torn anymore 😁
I like this suggestion, it would of course have implications for the other delegate proposals that I've made but I think this would be a good way to go.

What do you guys think @hyperoslo/ios ?

I like @JohnSundell's suggestion, the only thing I' not sure about is spotable in the name.

I think it makes sense in the context, however... I don't know if I would make that connection straight away as the intention on what happened is located later in the signature. But it would be easily scoped into spot.. which would make it super easy to discover the methods. Also like @JohnSundell described, if you imply it in the method name, you can drop the first label.