github-issues icon indicating copy to clipboard operation
github-issues copied to clipboard

Proposal for API design

Open nverinaud opened this issue 10 years ago • 3 comments

First of all, thanks for your work, it's very promising !

I thought about this earlier this week and I came up with an API I'd like to see in the future, so, seeing your enthusiasm on the subject, here it is.

let flow = root(screen1)
>>> push(screen2) // here it would be great to model a choice, using an other adapter function ?
>>> presentModally(screen3)
>>> dismiss()
>>> pushAndReplaceAll(screen4)
>>> pushAndReplaceLast(screen5)

The idea is to asbtract the act of pushing, presenting, dismissing, etc. into functions. Navigation Controller could be one provider of these functions. The functions root, push, etc. acts as adapters like what you see in map or filter.

What do you think ?

nverinaud avatar Jun 25 '15 18:06 nverinaud

I'm not sure exactly what the semantics are...

push means that the view controller will eventually be pushed? What does dismiss do? Currently, dismissing is very much implicit (which is not necessarily a good thing).

chriseidhof avatar Jun 26 '15 05:06 chriseidhof

push means continuing the flow normally (for NavigationController this means pushing a new vc on the stack). What I have in mind is that this function (and the others) are adapters for the custom >>> operator which permits composition. The need is to decouple the custom operator >>> from NavigationController and have it accepts adapters.

Here are 2 other examples:

// NavigationController module
let navController = NavigationController.root(screen1)
let flow = navController
>>> navController.push(screen2)
>>> navController.push(screen3)
// SplitViewController module
let splitViewController = SplitViewController.root(NavigationController.root(screen1), screen2)
let flow = splitViewController
>>> splitViewController.leftController.push(screen3)
>>> splitViewController.replaceDetailOnRight(screen4)

The idea is to have mondules with their own semantics, and make them >>> friendly.

In the example I provided in the first post, presentModally may alter the next possible transitions so that only a dismissal is possible to continue the normal flow. A custom flow may be injected though to perform a modal presentation of a navigation flow, then at the end of this flow, perform the dismissal. It could be designed like this :

let modalFlow = root(screen10)
>>> push(screen11)
>>> push(screen12)

let flow = root(screen1)
>>> presentModally(modalFlow) // dismiss remains implicit and occurs at the end of the modal flow
>>> push(screen2)

You agree that the idea behind all of this is : view controllers act as (pure) functions and navigation is just functions composition. >>> composes functions and push, presentModally, etc, wraps screens to play well in this composition.

nverinaud avatar Jun 26 '15 07:06 nverinaud

Cool! I'm currently on a long trip, but will look at this when I'm back in august. I'm all for making this entire thing not navigation-controller dependent...

On Fri, Jun 26, 2015 at 9:26 AM, Nicolas VERINAUD [email protected] wrote:

push means continuing the flow normally (for NavigationController this means pushing a new vc on the stack). What I have in mind is that this function (and the others) are adapter for the custom >>> operator which permits composition. The need is to decouple the custom operator >>> from NavigationController and have it accepts adapters.

Here are 2 other examples:

// NavigationController modulelet flow = NavigationController.root(screen1)

NavigationController.push(screen2) NavigationController.push(screen3)

// SplitViewController modulelet flow = SplitViewController.root(NavigationController.root(screen1), screen2)

SplitViewController.LeftController.push(screen3) SplitViewController.replaceDetailOnRight(screen4)

The idea is to have mondules with their own sementics, and make them >>> friendly.

In the example I provided in the first post, presentModally may alter the next possible transitions so that only a dismissal is possible to continue the normal flow. A custom flow may be injected though to perform a modal presentation of a navigation flow, then at the end of this flow, perform the dismissal. It could be designed like this :

let modalFlow = root(screen10)

push(screen11) push(screen12) let flow = root(screen1) presentModally(modalFlow) dismiss() push(screen2)

You agree that the idea behind all of this is : view controllers act as (pure) functions and navigation is just functions composition. >>> composes functions and push wraps screens to play well in this composition.

— Reply to this email directly or view it on GitHub https://github.com/chriseidhof/github-issues/issues/9#issuecomment-115560589 .

Chris Eidhof

chriseidhof avatar Jun 27 '15 17:06 chriseidhof