Created
March 16, 2018 20:00
-
-
Save mfeineis/4aa417d21c7976ae81a2bbcbab455380 to your computer and use it in GitHub Desktop.
A copy of the discussion that lead to the `ElmFxAndCmds.elm` snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
norpan [1:21 PM] | |
Hey, I was just thinking about the `Cmd` being returned from the `init` and `update` functions. I’ve never really liked that, so I was just wondering if anybody else has toyed with the idea to instead return a `List Command` or similar where you’d define your `Command`s just like you define your `Msg`s and then only at the last moment convert them to `Cmd`s? | |
ilias [1:25 PM] | |
Luke is doing something like that, or experimenting with it | |
opsb [1:25 PM] | |
@norpan I have an `AppCmd msg` which only gets converted to `Cmd`s as late as possible. It implements the same API as Cmd, `AppCmd.batch, AppCmd.none etc.` but it allows me to have a lot more control when testing for instance. (edited) | |
norpan [1:25 PM] | |
exactly, that’s my thinking too | |
opsb [1:26 PM] | |
It also makes it easier to have commands like `AppCmd.logout` | |
norpan [1:28 PM] | |
Ah, yes, since you don’t need any context to produce that | |
opsb [1:29 PM] | |
`AppCmd.setModal` was another handy one, anything that interacts with the top level app, independently of the current page etc. | |
norpan [1:30 PM] | |
An added benefit, I was thinking more in terms of gathering all your communication with the outside world in a more controlled way | |
A more explicit way | |
At least I know it’s probably not a crazy thought | |
opsb [1:32 PM] | |
I think there's a few projects that have used the same pattern | |
Generally people working on larger SPAs | |
ilias [1:32 PM] | |
I'm trying to find the conversation but can't atm - I asked Luke if he'd be willing to write up a blogpost around that, and I think he mentioned he wants to do a talk on it | |
So that would be cool | |
opsb [1:34 PM] | |
Pretty sure Mark Hamburg has talked about it before on the old elm-discuss group | |
norpan [1:35 PM] | |
Right now I’m passing stuff like post urls etc down to the functions, but that would no longer be needed | |
opsb [1:36 PM] | |
ah yep, it's a good pattern for decoupling information like that | |
norpan [1:36 PM] | |
Also, testing that a message will generate a post request is easier | |
opsb [1:36 PM] | |
yeah, Cmds are pretty unwieldy for testing | |
norpan [1:37 PM] | |
I’m convinced, time to refactor :slightly_smiling_face: | |
opsb [1:37 PM] | |
I know there's libs to help with that, but I always felt like they should really be data I can inspect | |
mfeineis [2:53 PM] | |
@norpan I just had the same idea, do you mean something like this? https://ellie-app.com/SZCJ3rJ3a1/3 | |
norpan [2:54 PM] | |
@mfeineis exactly | |
luke [2:54 PM] | |
Here’s where I’m at with it https://github.com/lukewestby/ellie/blob/server-purs/client/src/Pages/Editor/Effects/Outbound.elm | |
norpan [2:56 PM] | |
Why batch and none? Aren’t plain lists enough? | |
mfeineis [2:57 PM] | |
yeah I kind of like the plain lists, at least for the `update` function it's very nice, I don't know about `evalFx` yet that would interpret the effect | |
norpan [2:59 PM] | |
Sounds like new names for `concat` and `[]` :slightly_smiling_face: | |
justin [2:59 PM] | |
I need more coffee, I am struggling to understand this concept entirely, but it seems very straight forward. I think I need to use it. | |
norpan [3:00 PM] | |
My refactor went great. Just using plain lists. | |
I could remove my taco stuff | |
luke [3:01 PM] | |
I started off with plain lists and I didn’t like them but I actually can’t remember why | |
norpan [3:02 PM] | |
well, maybe I will see soon :slightly_smiling_face: | |
luke [3:02 PM] | |
It might have been that I found mapping to be cumbersome | |
norpan [3:03 PM] | |
ah you have a type parameter | |
I send the tagger to my sub updates so they all return the same type | |
mfeineis [4:05 PM] | |
this separation feels more like CQRS where the `read`s and `write`s a segregated, it's nice this way because the update just replays the messages that work like CQRS Events a.k.a. Facts to get to the current state while the `evalFx` or however one might call them only works on CQRS Commands a.k.a. intentions to change the state. I like that very much | |
bonus: the type system ensures that your readmodel can't directly work on intentions to change the state | |
might be overkill, though | |
mfeineis [4:23 PM] | |
a big shout-out to @luke Ellie is so super useful for experimentation, I could probably do it on my phone - if I had a 100+ key keyboard for that ^.^ | |
luke [4:28 PM] | |
i want to do a phone layout! about 2 projects out from the current one | |
luke [4:28 PM] | |
i've no idea what people need from it so if you have ideas send'em my way | |
mfeineis [4:34 PM] | |
I don't have a good idea how that would work. I mean screen real-estate is extremely precious for that form factor so having a good view of the code AND a somehow usable keyboard is gonna be challenge. Maybe it'd have to be more like a repl, or you could do something crazy like scratch and drag the control structures in place, that would probably work on a phone, now that I think about it | |
mfeineis [4:35 PM] | |
uploaded this image: scratch | |
scratch | |
mfeineis [4:39 PM] | |
thinking more about it, this visual approach would be cool, the types can be used as shapes for the pieces and Elm is probably better suited for something like this than Smalltalk, just pure functions and constants | |
mfeineis [4:40 PM] | |
and a handful of control structures... the pattern matching and destructuring could be problematic | |
passiomatic [4:43 PM] | |
Also check http://www.luna-lang.org It has some representation for data filtering | |
mfeineis [4:44 PM] | |
Thanks @kofi @passiomatic, I remember seeing this | |
sch [4:44 PM] | |
replied to a thread: | |
i've no idea what people need from it so if you have ideas send'em my way | |
I was just thinking about this the other day when I wanted to check out an ellie link coming from the slack client on my phone.I think thinking about the context behind a phone layout could help inform the layout and functionality.When on a phone, I don’t feel like I have enough screen real estate or a good enough keyboard/control to actually edit the document. Therefore, I’d propose a simplified view where I can see and scroll through the code, as well as a tab to switch to the running app | |
mfeineis [5:53 PM] | |
@norpan @luke I think I have found a nice and pure CQRS `Program` setup. https://ellie-app.com/zjzxp3cwa1/2 One function for applying facts to the current model, one function to interpret the `Intent` of the user which itself produces a list of `Fact`s as well as a list of `Effect`s that are then produced as commands for the runtime via another function. Seems like overkill for a small example but I might try that approach on a larger app. The only wart I couldn't remove is that you need an `Intent` to state `Fact`s or Elm wouldn't know what to do with a `Cmd Fact` as opposed to a `Cmd Intent` that is necessary because the `Intent` is the user interaction and the view needs to produce only these kinds of messages. This setup even preserves that you can't accidentally treat user interaction as actual facts. That was fun :aussie_revconga_parrot: (edited) | |
norpan [5:58 PM] | |
I’m starting to regret this :slightly_smiling_face: | |
szabba [7:44 PM] | |
@norpan why? | |
norpan [9:21 AM] | |
@szabba not really, I like it, but it’s getting a bit out of hand | |
szabba [7:23 PM] | |
The data -> commands function is growing? | |
marcc [10:50 PM] | |
Hey! What will happen with elm-phoenix with elm 0.19? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment