Great work guys, but correct me if I am wrong but it seems the reasons you decided to build Deku (if I am understanding what you have written) did not seem to be anything other than you were not a fan of how React doesn't take a completely functional approach to building components. Is that an appropriate assumption to make based on what you have written in your article?
I feel a little disappointed to be honest. Because as I was reading, I was expecting to read that you somehow had created a dom-diffing algorithm and matching library that was more performant than React.js, but really it just came down to the fact you didn't like how React.js looks. I was rooting for you from the beginning, expecting to see someone had created something superior to the much hyped React, but it didn't happen.
I don't want to hate on what you've done, looking through the code reveals that you put some considerable effort into Deku, but it makes me wonder if that effort could have been spent on perhaps learning the inner-workings of React.js and adapting it to your needs in its own fork. But having said that, Deku to me only has a few slight differences to React.js, the way components are built in Deku in comparison to React.js doesn't appear to be that dramatically different.
I don't want this comment to come across as yet another cynical HN commenter, but I just cannot see anything comprehensively different to existing solutions. I hate seeing talented development hours going to waste that could have been used to make an already existing project better.
> I hate seeing talented development hours going to waste that could have been used to make an already existing project better.
They didn't go to waste. They made Deku and learned a lot along the way. Just because something exists, doesn't mean you can't build your own. And not everything has an immediate, positive outcome.
I wrote my own MP3 Player back when Winamp really whipped the llama's ass. That got my name in a local newspaper in India, which ended up being the small boost I needed for the Consul General to grant me a Student Visa to come to the US. A few years later, a fan of my MP3 Player messaged me and we became good friends. I interviewed for a job in Florida and ended up staying at his place for the weekend. A few years later, while I continued to work at the job in Florida, my friend and I built a scheduling webapp that made it to the front page of Wired during SXSW.
An incredibly long list of positive things that happened in my life, I can track back to spending a week or two writing that MP3 player in my youth. If you ask me, I'd do it all over again. So I'm glad they build Deku, regardless of how it compares to React.
Excellent work. I just went through the source code; lean and neat. I am going to offer this as an alternative to React in something I'm building.
To the new-to-JS programmers out here, I'd recommend waiting until a framework reaches a certain level of maturity. React is not just about the core library itself, it is also about the tooling and ecosystem. For example, you can use React dev tools in Chrome. You are more likely to find how-tos and documentation if you're using React. React Native might help with sharing code if native mobile is in your plans.
Like the documentation says, what this framework really gives you is the ability to skip the OO-style coding that React mandates, and use just functions and modules.
> So we looked for smaller alternatives, like virtual-dom and mercury. The documentation for virtual-dom was slim and we didn’t think the API for mercury was very user friendly.
Really? You found that it was better to write everything from scratch instead of modifying mercury for your use (thus making use of the very good virtual-dom library)? Do you know that the whole mercury source code[1] is only 126 lines of code?
Perhaps you should also know that your library usage examples, in the end, look just like mercury usage examples.
I think that you are pointing at the wrong file, it looks like the library is actually around 4k lines. The point may still be valid, but it was not a trivial codebase to fork and they seem to have some architectural goals that they didn't think any of the current libraries were well suited to work with.
We're still using it on some of our projects, but we've found that no matter how simple we make data-binding it still leads to a mess of event bindings and state management.
The original plan was to make a virtual dom plugin for ripple but it wasn't really possible with the way the worked behind the scenes.
Those were exactlY my grievances with react as well i was practically hoping somebody builds a smaller sane version of react. It could be cool if this would use html / shadowdom components instead of jsx, but i havent checked out the src yet (is there a link?)
This seems very much like mercuryjs except less modular as per a quick glance. What are the differences between mercuryjs and deku besides the need to compile-to-dom in deku?
Mercury is a collection of libraries together which can be used as a framework. The most comparable subcomponent of mercury to deku is virtual-dom. Comparing virtual-dom and deku is pretty simple: v-d is not "component based" and has no internal state management.
Note that this isn't mixing just any JS, it's only presentational javascript. Either you're using some templating language like Handlebars or Jinja/Django's or Angular's HTML attribute data binding, or lots-of-jquery-selectors-tied-directly-to-the-html, you still need some sort of view logic to build your DOM.
Don't get me wrong, I've never really used React/JSX in depth enough, and I'm not overly enthusiastic about all these 'HTML' tags in my JS. But lets not pretend this is any worse than the current approach of $('.modal').append(document.createElement('button'))
I reflexively dislike the notion, but am trying to consider it with an open mind. The notion that a subtree of the DOM and some JavaScript that manipulates it, designed together to create a single functional component, represent a single concern and should be packaged together, is not unreasonable.
I think it is very different than the spaghetti pages found in jsps and php pages of yore, and the emphasis on component is a big part of why.
From a developer standpoint, I always felt HTML and JS to be extremely tight together. So whether or not they're in different files, they were linked to each others. Now, with JSX, it just feel like a more powerful html without all the crapy extremely limited template language..
Maybe for a static website, it doesn't feel right. But for a webapp it feels much better than before for me.
I hated it (a lot) before I tried it out. You could just put the render function in a separate file since it's just a function and then it's basically the same as a template anyway
JSX [1] is essentially a syntax fix for something people have been doing for a long time in JavaScript with DOM building libraries.
Having extensively used nested function call (like MochiKit.DOM [2]) and nested JSON-ML-ish array (like dombuilder [3]) variants of DOM builders in the past, JSX's syntax is a lot more friendly to write and maintain.
I'm sure this similarity has been pointed out before, but I think JSX is tangible for many of the same reasons PHP templating was. It only makes sense that a company that operates predominately in PHP would pass the baton of markup interpolation to JS as the web becomes more client oriented.
I personally lean towards logic interpolation (Handlebars, AngularJS), but both have their potentials for abuse. I don't know enough about JSX to say one way or the other what good practices are enforced and what bad practices are available.
1) export and let are part of ES6
2) <button> is JSX, which is uses by Facebook's React but can also be used with Deku.
If you run that through babel, it turns it into valid ES5 Javascript which will run in any modern browser:
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var Button = {
render: function render(_ref) {
var props = _ref.props;
var state = _ref.state;
return React.createElement(
"button",
null,
props.text
);
}
};
exports.Button = Button;
(Note: By default Babel translates JSX into React.createElement calls; the Deku docs cover the one line config changed needed to make it us Deku element calls instead.)
I wonder if they looked at riotjs[1] as an alternative. Deku is at ~10k, riotjs is at ~4k. They both seem to have similar goals: no legacy support, decent api, decent performance.
I'm curious about the decision to elide the synthetic event system. Does Segment only target modern browsers? What is the compatibility delta on including or eliding synthetic events?
" We also found that we kept fighting with function context all the time which is waste of brain energy. React has some functional aspects to it but it still feels very object-oriented. You’re always concerning yourself with implicit environment state thanks to this and the class system. If you don’t use classes you never need to worry about this, you never need decorators and you force people to think about their logic in a functional way."
Reading code is easier than writing code, but I guess some people don't like doing that. I hesitate to call anyone stupid as they did have their non-npm thing, but still.
[+] [-] DigitalSea|11 years ago|reply
I feel a little disappointed to be honest. Because as I was reading, I was expecting to read that you somehow had created a dom-diffing algorithm and matching library that was more performant than React.js, but really it just came down to the fact you didn't like how React.js looks. I was rooting for you from the beginning, expecting to see someone had created something superior to the much hyped React, but it didn't happen.
I don't want to hate on what you've done, looking through the code reveals that you put some considerable effort into Deku, but it makes me wonder if that effort could have been spent on perhaps learning the inner-workings of React.js and adapting it to your needs in its own fork. But having said that, Deku to me only has a few slight differences to React.js, the way components are built in Deku in comparison to React.js doesn't appear to be that dramatically different.
I don't want this comment to come across as yet another cynical HN commenter, but I just cannot see anything comprehensively different to existing solutions. I hate seeing talented development hours going to waste that could have been used to make an already existing project better.
[+] [-] chime|11 years ago|reply
They didn't go to waste. They made Deku and learned a lot along the way. Just because something exists, doesn't mean you can't build your own. And not everything has an immediate, positive outcome.
I wrote my own MP3 Player back when Winamp really whipped the llama's ass. That got my name in a local newspaper in India, which ended up being the small boost I needed for the Consul General to grant me a Student Visa to come to the US. A few years later, a fan of my MP3 Player messaged me and we became good friends. I interviewed for a job in Florida and ended up staying at his place for the weekend. A few years later, while I continued to work at the job in Florida, my friend and I built a scheduling webapp that made it to the front page of Wired during SXSW.
An incredibly long list of positive things that happened in my life, I can track back to spending a week or two writing that MP3 player in my youth. If you ask me, I'd do it all over again. So I'm glad they build Deku, regardless of how it compares to React.
[+] [-] jeswin|11 years ago|reply
To the new-to-JS programmers out here, I'd recommend waiting until a framework reaches a certain level of maturity. React is not just about the core library itself, it is also about the tooling and ecosystem. For example, you can use React dev tools in Chrome. You are more likely to find how-tos and documentation if you're using React. React Native might help with sharing code if native mobile is in your plans.
Like the documentation says, what this framework really gives you is the ability to skip the OO-style coding that React mandates, and use just functions and modules.
[+] [-] unknown|11 years ago|reply
[deleted]
[+] [-] fiatjaf|11 years ago|reply
Really? You found that it was better to write everything from scratch instead of modifying mercury for your use (thus making use of the very good virtual-dom library)? Do you know that the whole mercury source code[1] is only 126 lines of code?
Perhaps you should also know that your library usage examples, in the end, look just like mercury usage examples.
[1]: https://github.com/Raynos/mercury/blob/master/index.js
[+] [-] jaltekruse|11 years ago|reply
https://github.com/Raynos/mercury/blob/master/dist/mercury.j...
[+] [-] unknown|11 years ago|reply
[deleted]
[+] [-] jefftchan|11 years ago|reply
[1] https://ripplejs.github.io [2] https://news.ycombinator.com/item?id=7609816
[+] [-] anthonyshort|11 years ago|reply
The original plan was to make a virtual dom plugin for ripple but it wasn't really possible with the way the worked behind the scenes.
[+] [-] kansface|11 years ago|reply
The only cogent reason offered for writing yet another front end framework ...
[+] [-] Aeolun|11 years ago|reply
[+] [-] ryanisinallofus|11 years ago|reply
[+] [-] kuschku|11 years ago|reply
The best reason is: Not bound to Facebook License and Patents.
[+] [-] calcsam|11 years ago|reply
[+] [-] dustingetz|11 years ago|reply
[+] [-] platz|11 years ago|reply
[+] [-] tjallingt|11 years ago|reply
[+] [-] Meai|11 years ago|reply
[+] [-] droidist2|11 years ago|reply
[+] [-] nwmcsween|11 years ago|reply
[+] [-] Touche|11 years ago|reply
[+] [-] tel|11 years ago|reply
Mercury is a collection of libraries together which can be used as a framework. The most comparable subcomponent of mercury to deku is virtual-dom. Comparing virtual-dom and deku is pretty simple: v-d is not "component based" and has no internal state management.
[+] [-] davexunit|11 years ago|reply
[+] [-] madeofpalk|11 years ago|reply
Note that this isn't mixing just any JS, it's only presentational javascript. Either you're using some templating language like Handlebars or Jinja/Django's or Angular's HTML attribute data binding, or lots-of-jquery-selectors-tied-directly-to-the-html, you still need some sort of view logic to build your DOM.
Don't get me wrong, I've never really used React/JSX in depth enough, and I'm not overly enthusiastic about all these 'HTML' tags in my JS. But lets not pretend this is any worse than the current approach of $('.modal').append(document.createElement('button'))
[+] [-] sls|11 years ago|reply
I think it is very different than the spaghetti pages found in jsps and php pages of yore, and the emphasis on component is a big part of why.
[+] [-] aidenn0|11 years ago|reply
I personally find:
To be more elegant than: Of course react allows you to use whichever you prefer.[+] [-] d0m|11 years ago|reply
Maybe for a static website, it doesn't feel right. But for a webapp it feels much better than before for me.
[+] [-] anthonyshort|11 years ago|reply
I hated it (a lot) before I tried it out. You could just put the render function in a separate file since it's just a function and then it's basically the same as a template anyway
[+] [-] insin|11 years ago|reply
Having extensively used nested function call (like MochiKit.DOM [2]) and nested JSON-ML-ish array (like dombuilder [3]) variants of DOM builders in the past, JSX's syntax is a lot more friendly to write and maintain.
[1] http://facebook.github.io/jsx/ [2] http://mochi.github.io/mochikit/doc/html/MochiKit/DOM.html [3] https://github.com/creationix/dombuilder
[+] [-] Hytosys|11 years ago|reply
I personally lean towards logic interpolation (Handlebars, AngularJS), but both have their potentials for abuse. I don't know enough about JSX to say one way or the other what good practices are enforced and what bad practices are available.
[+] [-] hcarvalhoalves|11 years ago|reply
Unless you know LISP, then you understand code is data.
[+] [-] crudbug|11 years ago|reply
Introducing multiline string comments to ES6 (python syntax) would have been a better option.
""" <div> <p> {{ hello_world }} </p </div> """
[+] [-] albertoleal|11 years ago|reply
Because transpilers.
[+] [-] k__|11 years ago|reply
http://mithril.js.org/
[+] [-] tel|11 years ago|reply
https://gist.github.com/tel/a4b0980db350096afd53
[+] [-] coldcode|11 years ago|reply
[+] [-] Lazare|11 years ago|reply
1) export and let are part of ES6 2) <button> is JSX, which is uses by Facebook's React but can also be used with Deku.
If you run that through babel, it turns it into valid ES5 Javascript which will run in any modern browser:
(Note: By default Babel translates JSX into React.createElement calls; the Deku docs cover the one line config changed needed to make it us Deku element calls instead.)[+] [-] insin|11 years ago|reply
[+] [-] johnernaut|11 years ago|reply
[+] [-] fiatjaf|11 years ago|reply
[+] [-] dukerutledge|11 years ago|reply
[+] [-] e12e|11 years ago|reply
[1] https://github.com/muut/riotjs
[+] [-] e12e|11 years ago|reply
https://github.com/muut/riotjs/blob/master/demo/todo.js
vs
https://github.com/segmentio/deku/blob/master/examples/todo/...
Does look like riotjs might be re-factored in some interesting ways, if they move it to ES6 though.
[+] [-] tel|11 years ago|reply
[+] [-] _pmf_|11 years ago|reply
[+] [-] unknown|11 years ago|reply
[deleted]
[+] [-] ConAntonakos|11 years ago|reply
[+] [-] biggerbob|11 years ago|reply
[deleted]
[+] [-] tacone|11 years ago|reply
[+] [-] nutate|11 years ago|reply