When comparing Mithril vs Ractive.js, the Slant community recommends Mithril for most people. In the question“What are the best Angular.js alternatives?” Mithril is ranked 4th while Ractive.js is ranked 15th. The most important reason people chose Mithril is:
Most other frameworks either offer a huge API to deal with model and view synchronization, or defer to other libraries & plugins to cater for relatively simple use cases. Mithril's API is tiny but complete. The natural reaction is to assume something is missing, but as you build you realise you incredibly fast, powerful and rich applications can be built using nothing but Mithril.
Specs
Ranked in these QuestionsQuestion Ranking
Pros
Pro Small, easy to learn API
Most other frameworks either offer a huge API to deal with model and view synchronization, or defer to other libraries & plugins to cater for relatively simple use cases. Mithril's API is tiny but complete. The natural reaction is to assume something is missing, but as you build you realise you incredibly fast, powerful and rich applications can be built using nothing but Mithril.
Pro Fast rendering
Mithril's loading times are very fast. This is because it's templates are compiled first and then served to the browser and because it uses a virtual DOM. The virtual DOM is a virtual tree containing all the nodes of the real DOM, every time anything changes in the virtual DOM, Mithril does not re-render the entire (real) DOM, instead it just searches and applies the differences.
Pro No need to learn another syntax to write views
Most MVC frameworks use HTML templates to render their views. They are good and useful because they are easy to read and understand. But they add more complication to an app because it's practically a new language and syntax that needs to be learned.
Mithril argues that separating markup from logic is just a separation of technologies and not concerns, so you can write Mithril views in JavaScript. Writing them in JavaScript also makes it easier to debug them (HTML templates can't be debugged).
Pro Familiar to people used to MVC
Doesn't lock you into any complicated conventions or structures, only one function is required to create either a Controller or a View. You're free to implement your architecture exactly as you want, so you can focus on the purpose of MVC, making connections between computer data and stuff in the end user's head.
Pro Small size
Weights just 8Kb gzipped and has no dependencies. A reactive stream module can be added for one extra Kb.
Pro Great documentation
Mithril has a large and expansive documentation despite it's relatively small API. Mithril's GitHub repo has more documentation than actual source code. None of that documentation is auto-generated
Pro Allows a smooth transition from other UI frameworks
One thing you need to start using Mithril is just a DOM node. With Mithril a developer is able to introduce the library step by step.
Pro Allows you to choose which JavaScript libraries to integrate in your project
Mithril gives to the developer the flexibility to chose the best JavaScript library to use for a specific task.
A huge framework like Angular instead forces you to use their API, which does not necessarily evolve as fast as the JavaScript ecosystem. Therefore you may end up in case when you are stuck using an API which is just not the best in terms of performance
Pro Can be used without build systems
It's plain old JavaScript, can be used without webpack, gulp or grunt, just include it into your HTML and start writing your app.
Pro Does not force you into a predefined structure
Mithril's API is pretty small compared to other frameworks. It forces developers to solve problems in JavaScript rather than in Mithril. Other frameworks with massive APIs force you to think in a way that suits the framework. Mithril doesn't do that.
Pro Supports a true templating language
Ractive fully supports a templating language. To be more precise, views are written with a variant of Mustache, which is also extended to support inline JavaScript expressions. Soon it will be able to support other templating languages.
Pro Makes it possible to handle user interaction in a readable, declarative fashion
Ractive has a concept of proxy events, which translate a user action (e.g. a mouseclick) defined via an event directive into an intention (e.g. 'select this option'). This allows you to handle user interaction in a readable, declarative fashion.on-click='activate'
with arguments:on-click = 'activate: {{a}}, {{b}}'
It's activate
(and not click
, nor your function name) that is the name of the handler event that will be fired for any registered handlers created viaractive.on('activate', your_handler)
ractive.on('activate', your_another_handler)
Of course, Ractive also supports method calls like on-click='toggle(foo
)'
Pro Two-way binding configuration
Two-way binding can be turned off by those that are concerned it may be a source of bugs.
Pro Step by step tutorial
They have a great interactive tutorial which makes the learning process easy peasy. You will get into it within a couple of minutes.
Pro Virtual DOM
Instead of relying on the DOM, Ractive implements a virtual DOM from scratch, allowing it to calculate precisely what needs to be patched during the next screen refresh. This is orders of magnitude faster than fiddling with the DOM itself.
Cons
Con Small API can make it unsuitable for larger more complex projects
Mithril's small API and small number of functions while helpful for small projects and applications where speed is needed, can add another layer of complexity in larger more complex applications where a more extensive API is needed out of the box.
Con Ractive's two way binding can be a source of bugs
Two-way data-binding means that a HTML element in the view and an Ractive model are binded, and when one of them is changed so is the other. One-way data-binding for example does not change the model when the HTML element is changed.
This is a rather controversial subject and many developers consider two-way data binding an anti-pattern and something that is useless in complex applications because it's very easy to create complex situations by using it and being unable to debug them easily or understand what's happening by just looking at the code.
However, this is the default behaviour which can be changed to have one-way data binding.