-
Notifications
You must be signed in to change notification settings - Fork 14
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
Discussion: DSL syntax #75
Comments
Personally I think that if |
@Zhuinden I agree |
I think you raised a few very interesting points here!
Exactly, this will work but won't bundle those instructions to a single which might break animations.
This will lead to the wanted behavior of bundling those two instructions to a single ✅
This one will ignore the result of the Let me address your questions by clarifying the underlying architecture of the router a little more: A The So that being said: When opening the Regarding the infix function: Theoretically one could use them just as normal functions, but I guess people tend not doing it then? But as from now, I think they are one of the major sources of confusion and we should rather remove them? Also we might want to make sure, that results are check inside a router instruction. Mabye |
🤔 That's totally not expected. I believe that block should be a "instruction chain builder". |
Ah yes, number 3 tricked me too! The clarification on the architecture was useful, I was obviously misunderstanding things a little bit. What would you think if we made |
You mean like
? 🤔 |
Or would you propose that the following syntax:
|
Haha I get it 👍 @Zhuinden @isaac-udy What are your thoughts on this one? At least, I am sure there would be no way of building this syntax while keeping the whole thing immutable. Maybe the underlying concept would then more look like a |
You make a good point with the I would suggest the following: class Router {
...
@CheckResult(...)
fun pushTransaction(val transaction: (List<Route>) -> List<Route) { ... }
operator fun invoke(val transaction: MutableList<Route>.() -> Unit) {
pushTransaction { it ->
return@pushTransaction mutableListOf(it).transaction().toList()
}
}
} I think this is the best of both worlds - it gives the "easier" interface as the default |
Exactly! That was also what I had in mind, but I am not quite sure about it. Maybe one of my colleagues can contribute its thoughts on this tomorrow. I honestly think the The problem with the |
I think this is a good idea, but I think that we should also consider changing the signature of the invoke function - currently it's |
That at that point there is no reason to have it passed as a lambda. |
Another idea:
Whoever wants to do custom routing with the What are your thoughts on that? |
I think the simple function chaining is the easiest to understand and fulfills the basic needs when using this lib. I also see how the lambda gives you more flexibility. So why not keep both? Having 2 ways to do the same thing can be a cause of confusion and this should be clearly stated in the docs. |
I will now build two branches:
Let's decide afterwards based on both working branches! |
I'd like to start a bit of a discussion around the DSL syntax.
Multiple paths to one goal:
router.clear() router.push(Route())
router { clear() push Route() }
router { clear() push(Route()) }
There are several ways to perform similar actions. The first way isn't correct, as it won't bundle up the actions as a single item, but my understanding is the last two ways are essentially the same. ̛I think it would be a better idea to have a single syntax, even if it means that a single "push" needs to be performed as:
Builder syntax:
The builder continuation syntax that allows a user to push a series of routes like this is inconsistent with the use of infix functions, as a user is unable to split these onto different lines. The following code will not compile:
I have two questions:
infix
be removed, so a user can split the continuation over multple lines?The text was updated successfully, but these errors were encountered: