DEV Community

Matthieu Lux
Matthieu Lux

Posted on • Originally published at Medium on

Announcing: compo

馃幖 Compo路sing Web Compo路nents

compo is a new JavaScript Web UI library based on pure Web Components providing a modern API using function composition to easily define and enrich them.

Yes! It鈥檚 yet another new JavaScript Web UI library! Sorry for the 鈥淛avaScript fatigue鈥 people still I thought there was some good ideas in this project and it deserved to be at least published.


It鈥檚 inspired by many populars library such React, Redux, Recompose or styled-components, applying the modern concepts and API to the Custom Element standard.

The Virtual Dom concept introduced by React some time ago has been used to free the user to manage DOM transitions. The concept can be applied to standard Web Component world, each component diffs its template evaluation to the own Shadow DOM.

Recompose introduced a full function composition API allowing to enhance a component feature by feature as needed. Once again it could perfectly match Custom Elements by extending the definition class with the features needed.

Finally, using CSS in JS with styled-components for a while pushes to consider CSS as an integrant part of a UI library and treat it the same way as the markup. Shadow DOM CSS scoping does perfectly the job.


What I regret in all the previous inspirations was the complexity of using a lot of different libraries to finally get a strange monster full of good ideas but with complex non homogeneous APIs.

So compo is a fully featured library presenting a single coherent API to manage all aspects of a component: state management, markup, style.

As said in the title, the chosen interface is function composition. You define a component with the component function, first parameter for the name, all others for enhancing functions like withStore , withMarkup or withStyle.


The whole process was driven by minimalism for both simplicity and bundle weight. What鈥檚 best for minimalism than taking as much as you can from your browser directly?

The point of compo is to present a powerful API by doing the less possible using as much as possible the standards. As such, it鈥檚 heavily built upon Custom Elements, Shadow DOM, ES2015 template strings. Even the Virtual DOM parser is in reality the native browser DOM parser.

Also, one of the guidelines was to use the power of new browsers. Not to ignore Web history or compatibility but to imagine what could be modern APIs without limitations. For example, compo is not (at all) transpiled. It鈥檚 written and published in modern ES2017. In fact, it works already in the vast majority of browsers and everyone can transpile it in its application if needed.


compo is not yet, production ready. To be honest, it only really works on Chrome out of the box and Firefox with a flag. There is a compatibility example using Web Component polyfills to use it on every browsers.

In terms of performances, concepts should not be blocking but at this point don鈥檛 try aggressive benchmarks compared to an industry framework, it could not end up well. Still it鈥檚 powerful enough to build 鈥渟tandard size鈥 application without have real issues.

To be perfectly honest, compo is also some kind of child dream. 鈥淚 published my own JavaScript library 馃槂鈥. We鈥檒l see how far it goes but I do think there is some good stuff in the library. If it only influence a bit the community, it will already be a huge success.

Top comments (0)