Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal for API design #9

Open
nverinaud opened this issue Jun 25, 2015 · 3 comments
Open

Proposal for API design #9

nverinaud opened this issue Jun 25, 2015 · 3 comments

Comments

@nverinaud
Copy link

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 ?

@chriseidhof
Copy link
Owner

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

@nverinaud
Copy link
Author

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.

@chriseidhof
Copy link
Owner

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
#9 (comment)
.

Chris Eidhof

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants