-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
TodoMVC in Mithril v2 or Where did controller() view(ctrl) go? #18
Comments
@space88man Could you link to the problematic example? |
Here: https://github.com/tastejs/todomvc/tree/master/examples/mithril Especially this file: https://github.com/tastejs/todomvc/blob/master/examples/mithril/js/controllers/todo.js which uses the controller() pattern. The Component here https://github.com/tastejs/todomvc/blob/master/examples/mithril/js/views/main-view.js uses This code seems to still work so speaks to the backward compatibility of Mithril! It would be great to have an up to date repo under the MithrilJS org. |
Better would be to rewrite their example and send them a pull request to do it. It's been outdated since at least Mithril v1 was released and we just hadn't updated it yet. I do appreciate bringing it to our attention! Edit: Marked this accordingly as a bug. |
Great - thanks to your v1 comment I managed to find the migration guide (controller->oninit) at the v1.0 Change log. Guess this will be my weekend homework... |
@space88man There's similar for v0.2 → v2, if you want a shortcut. |
@isiahmeadows - thanks. I have done minimally invasive changes to the todomvc example here: https://github.com/space88man/todomvc-mithril2. RFC for improvements and incorrect use of Mithril 2 patterns. Original example is linked further up in this issue.
|
Noticed the following:
As for the rest, I'm not sure if (this is not comprehensive)
All in all, I didn't check what the TodoMVC dictates wrt. patterns or code provided, but the whole implementation could probably be made more concise with writing things from scratch. |
@space88man I agree with @orbitbot's "... the whole implementation could probably be made more concise with writing things from scratch." Edit: I think the coding style has changed quite a bit since 0.2, so if you'd want to create an example using the latest coding ideas, then starting from scratch would be the best way, IMHO. |
[UPDATE] Refactored, incorporating the comments, and converting components to closures. Thanks for the comments: I'll refactor taking the tutorial as a guide rather than my too literal port of the 0.2 example. Question:
|
Implement improvements from GH https://github.com/MithrilJS/mithril.js/issues/2499#issuecomment-521182524.
@space88man we (@orbitbot, @StephanHoyer, and I) have been code golfing on the channel a bit, and my implementation (everything in one file) is this. A standalone working version is here. If you want to use the code you'll have to separate the code in modules and such (according the the MVC setup rules). Let me know if you have questions or comments 🙂 Edit: Of course you might find it more fun to write your own code instead of using (part of) mine, so do what you think is best 🙂 To answer your questions (didn't see them until now, sorry): |
Couldn't resist making a split version 😉 |
Awesome!! 😄 🙇♂️ 🙇♂️ @isiahmeadows please feel free to close - maybe add @osban( + others) work to https://mithril.js.org/examples.html? Thank you. |
I'll leave it open until TodoMVC itself is updated with a v2 implementation. |
@space88man I'll leave the honors of adding it to TodoMVC to you (you can also wait until @orbitbot and/or @StephanHoyer is ready with his version, and see if you like that one better). |
@space88man Found some bugs: some actions weren't saved properly. Here's the corrected version (only actions can modify model): flems. |
Filed tastejs/todomvc#2263 to try to fix this. Since there's nothing that can realistically be done in this repo (and this repo's independent TodoMVC clone differs wildly from the official repo's), I'm closing this issue. |
Requesting for TodoMVC guide for v2. Currently, the example uses
and
However this pattern isn't documented (last was in v0.2.5). The Simple application tutorial uses either
view: function(){...}
orview: function(vnode){...}
.The view receives
accepted
or 'completed
from the URL capture '/:filter' as thefilter
property on thectrl
argument populated bycontroller()
.In modern mithril (>=v2)/Simple application tutorial it comes in by vnode.attrs.filter? The TodoMVC example still works on v2, how did the view function know it was receiving (old-style) ctrl or vnode?
in
view: function(vnode){}
I would expect the URL capture/:filter
(filter = "active" or "completed"
) to appear asvnode.attrs.filter
. However the received argumentctrl
does not seem to be polymorphic (it does not have anattrs
property).The text was updated successfully, but these errors were encountered: