4

Composable by design, sensible by default

 2 years ago
source link: https://dev.to/aidenybai/composable-by-design-sensible-by-default-2nij
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Plug: I help develop million: <1kb virtual DOM - it's fast!

Introduction

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK