Composable by design, sensible by default

Plug: I help develop million: <1kb virtual DOM – it’s fast!


Lately, there’s been a paradigm shift in API design in the JavaScript Framework ecosystem. For instance, Vue 3 has released the new Composition API alongside the existing Options API, allowing for creation of significantly more reusable code and greater customization by the developer.

This is in contrast to the previous API in Vue 2. Although it provided functionality to a degree, it is fundamentally a black box and when greater complexities arise, plugins or escape hatches must be utilized to solve these issues. This can result in subpar code quality, performance, and maintainability.

Composability by design

Composability is awesome, but what exactly is composability?

Instead of a boring definition, let’s illustrate with a graphic:

Lego pyramid made of Lego blocks

We can imagine Legos as components of our API — we can use those legos to build complex logic. If we want to change the color or length of the pyramid, we can swap out legos for legos of our desired attributes. When applied to APIs, we can use components to compose more complex logic, and we can swap out components to change the logic.

For example, with Million, logic is composed with drivers, which are functions that enable nested composition. This is especially useful for libraries that are made to create other libraries, as it allows for greater extensibility and complex functionality.

Sensible by default

While having a super composable API is great, it can be too much effort just to get some simple functionality working. That’s why we need to offer a sensible API by default. A sensible API is one which covers the general case and uses best practices, and is dead simple to use.

Source link

Latest articles

Related articles

Leave a reply

Please enter your comment!
Please enter your name here