News for hackers. Stuff that matters.
Re:Show HN: My new JavaScript MVC framework by ulisesrmzroche on Tuesday March 18, 2014 @12:45PM (#7423018)
Have you successfully tried this out in a real app? Why would you want to structure your dom inside an array? Seem pretty crazy, my dude.

todo.view = function(ctrl) { return m("html", [ m("body", [ m("input"), m("button", "Add"), m("table", [ m("tr", [ m("td", [ m("input[type=checkbox]") ]), m("td", "task description"), ]) ]) ]) ]); };

Re:Show HN: My new JavaScript MVC framework by chc on Tuesday March 18, 2014 @01:52PM (#7423634)
I think the idea is that it's simple — it's just a basic data structure in the language and can be generated or manipulated with just simple JavaScript. This is similar to why Lisp programs being Lisp data structures is interesting. Intriguingly, it looks like the API is compatible with React's JSX. With that, you could write this as:

  @jsx m
  todo.view = function(ctrl) {
      return (
        <html>
          <body>
            <input/>
            <button>Add</button>
            <table>
              <tr>
                <td><input type="checkbox"/></td>
                <td>Desk description</td>
              </tr>
            </table>
          </body>
        </html>
      );
  }
Re:Show HN: My new JavaScript MVC framework by ulisesrmzroche on Tuesday March 18, 2014 @02:47PM (#7424066)
Adding some more css declarations, id, data-hooks, etc., and make it span 100+ lines, like in real life. Scares me just thinking about it.
Re:Show HN: My new JavaScript MVC framework by chc on Tuesday March 18, 2014 @03:07PM (#7424229)
Are those things you wouldn't have to do under any other system, or which would be significantly simpler there? Because I'm not seeing it. You seem to be saying "This involves building a web page" — which is true, but would be regardless.
Re:Show HN: My new JavaScript MVC framework by ulisesrmzroche on Tuesday March 18, 2014 @05:05PM (#7424966)
Yes, it would be simplificantly simpler to edit html if it wasn't stuck in between two strings, for one, let alone inside an array.

todo.view = function(ctrl) { return m("html", [ m("body class='application", [ m("input class='add input input-sm input-md"), m("button class='btn btn-success button-green", "Add"), m("table class='table table-strped table-row", [ m("tr class='tr'", [ m("td", [ m("input[type=checkbox] class='checkbox input input-sm' id=firstName name=firstName") ]), m("td class='td", "task description"), ]) ]) ]) ]); };

I honestly can't tell you what the hell that is supposed to be anymore. Also, you guys are using invalid html for everything. Your example is not going to validate on anything.

Re:Show HN: My new JavaScript MVC framework by lhorie on Tuesday March 18, 2014 @09:31PM (#7426303)
I think you're too caught up on syntax and missing the big picture. The m() method is simply a helper utility that returns a POJO. You can write the code in coffeescript if js syntax bother you, or you can go nuclear and implement a frontend or a preprocessor that take some popular templating syntax and spit out the appropriate data structure. The conversion tool I provide is a small step in that direction, but, with Mithril being at a mere v0.1, it still needs more work done to be fully automated.

Also, just FYI, the selector syntax follows CSS rules, so you'd write m("body.application"), not m("body class='application'")

Re:Show HN: My new JavaScript MVC framework by ulisesrmzroche on Wednesday March 19, 2014 @10:23AM (#7428769)
Programs are for humans to read and only incidentally for computers to execute. Syntax is the whole picture.
Re:Show HN: My new JavaScript MVC framework by lhorie on Wednesday March 19, 2014 @10:47AM (#7428928)
Well, I already told you which directions Mithril can go in terms of making syntax more to your liking. If you're too put off by js templates and not willing to spend time helping push the project in a direction you like, you can always try other frameworks or come back later when I have a more HTMLy frontend option available.
Re:Show HN: My new JavaScript MVC framework by danneu on Tuesday March 18, 2014 @05:53PM (#7425288)

    > Yes, it would be simplificantly simpler to edit html 
    > if it wasn't stuck in between two strings
    > ...
    > m("body class='application", ...
You would put attributes in an object.

    m("body", {class: "application"}, [ ... ])
Sure, it's no Lisp, but to me it's just Javascript's commas that suck the thunder out of it.
Re:Show HN: My new JavaScript MVC framework by insin on Tuesday March 18, 2014 @06:27PM (#7425494)
This is exactly why JSX is such a big win for this method of creating content - it's just sugar for the same function calls, but expressed in a form we're already used to multiply-nesting, with closing tags to help keep context and no need for commas when you need to break a line.

Quite neat that you can use it for non-React stuff just by tweaking the pragma comment the JSX transformer requires.

Here's an actual example of a Bootstrap table in a React component using JSX: https://github.com/insin/lifequote/blob/master/src/component...

There's not much display logic in it, so it doesn't exhibit the usual progression I've seen when writing React components so far, in which most display logic happens up-front in a component's render() and often gets moved into another method and called directly from where it's going to go in the structure being returned from render(), so you generally don't end up with huge whacks of JSX in components which are doing more work.

Re:Show HN: My new JavaScript MVC framework by chc on Tuesday March 18, 2014 @06:55PM (#7425634)
To be clear, my example wouldn't actually work. I had a brain fart about JSX's output format. Sorry about that. I do think it would be pretty easy to adapt it to this format, though (it looks like you'd just need to change one line in the visitReactTag() function).
Re:Show HN: My new JavaScript MVC framework by zpao on Tuesday March 18, 2014 @09:34PM (#7426312)
You could actually do this without a single change to the JSX transform, and instead just make a simple object that calls m() with the right params. Then you just change the @jsx pragma to point at that object. With a complete array of elements this should mostly work.

```js / @jsx m.dom */

function m(type, props, children) { // assuming m() looks something like this. return { type: type, props: props, children: children}; } m.render = function(lwDOM){ console.log(lwDOM)}; m.dom = {};

// React hard codes this array so we can do something like this to build the mapping ['a', 'span'].forEach((el) => { m.dom[el] = function(props, ...args) { return m.call(null, el, props, args); } });

m.render( <a href={"google.com"}> <span>hello</span> <span>world</span> </a> ); ```

Re:Show HN: My new JavaScript MVC framework by Bahamut on Tuesday March 18, 2014 @11:55PM (#7426740)
That is ugly as heck - for some of the complaints that some people have with Angular's templating, it doesn't force you into tying your view so heavily to JS. That is far more of a travesty.
Re:Show HN: My new JavaScript MVC framework by jonahx on Tuesday March 18, 2014 @03:40PM (#7424467)
While I admit I'm somewhat sympathetic to this reaction, it really is a cosmetic complaint. It's hardly uglier or more complex than ordinary html -- we're just used to html. Ofc there's some benefit to the technologies we're used to all things being equal, but I think architectural benefits trump concerns like this. I'm not making a case for or against Mithril, btw, just noting that this objection is a fairly surface one.
Re:Show HN: My new JavaScript MVC framework by ulisesrmzroche on Tuesday March 18, 2014 @05:08PM (#7424987)
How many times have you messed up a comma inside an array? And just for looping, this is literally constructing a web page out of it. There is no architectural benefit to this, all that's going to happen is that your going to fat finger some shit, and the compiler will complain to no end.

Guys, rule of thumb, architecture === directory names. Performance is an implementation detail.

Frameworks live and die by their APIs. The easier it is to work with, to read and write and reason with, the better it is.

But you know what, this can be easily proved. Someone take a stab at todomvc with this and let me know if it hurt or not.

Re:Show HN: My new JavaScript MVC framework by jpmonette on Tuesday March 18, 2014 @11:11PM (#7426599)
There's a sample TodoMVC posted here - https://github.com/jpmonette/todomvc-mithril. If you have any idea to improve, feel free to send a pull request!
Re:Show HN: My new JavaScript MVC framework by lhorie on Wednesday March 19, 2014 @11:19AM (#7429200)
Looks roughly how I'd expect. Personally I don't find it unreadable, except for the 8-spaces-in-a-tab thing (which is not really relevant anyhow). Anyways, few things I see:

- I'm not sure why you're doing `return m("#todo-app"), [...]` on line 15 of the view, it looks like a typo

- I would probably have written a keyboard utility function similar to m.withAttr to keep the e.keyCode stuff out of the controller and remove the anonymous function in the view

- I generally prefer inline ternary syntax instead of a if statement at the top for the "clear" button.

- the pluralize snippet can also be pulled out into a utility method

- I also tend to favor this syntax: m("input#new-todo[placeholder='What needs to be done?']") if the value of the attribute is static (line 18)

Re:Show HN: My new JavaScript MVC framework by thefreeman on Wednesday March 19, 2014 @01:30AM (#7426986)
https://github.com/jpmonette/todomvc-mithril/blob/master/js/...

Looks pretty painful, but I do think adapting JSX could be a pretty painless solution so I don't look at it as a deal breaker. I am still yet to find a javascript templating solution that I don't have at least 1 or 2 issues with.

Re:Show HN: My new JavaScript MVC framework by insin on Wednesday March 19, 2014 @07:39AM (#7427937)
Here's a JSXified version which assumes the existence of an "mshim" object which adapts tag calls and arguments to what m() expects:

https://gist.github.com/insin/9639918

Re:Show HN: My new JavaScript MVC framework by ulisesrmzroche on Wednesday March 19, 2014 @10:21AM (#7428764)
Honestly, that looks worse than I thought it would. Are you guys familiar with the whole, programs are for humans to read it, and incidentally for computers to execute?