All Projects → luwes → Sinuous

luwes / Sinuous

🧬 Light, fast, reactive UI library

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Sinuous

Anglesharp
👼 The ultimate angle brackets parser library parsing HTML5, MathML, SVG and CSS to construct a DOM based on the official W3C specifications.
Stars: ✭ 4,018 (+442.97%)
Mutual labels:  hacktoberfest, dom
Bubbletea
A powerful little TUI framework 🏗
Stars: ✭ 7,886 (+965.68%)
Mutual labels:  hacktoberfest, functional
Ava
Node.js test runner that lets you develop with confidence 🚀
Stars: ✭ 19,458 (+2529.46%)
Mutual labels:  hacktoberfest, performance
Predator
A powerful open-source platform for load testing APIs.
Stars: ✭ 356 (-51.89%)
Mutual labels:  hacktoberfest, performance
React Esi
React ESI: Blazing-fast Server-Side Rendering for React and Next.js
Stars: ✭ 537 (-27.43%)
Mutual labels:  hacktoberfest, performance
Akka Grpc
Akka gRPC
Stars: ✭ 361 (-51.22%)
Mutual labels:  hacktoberfest, reactive
Cloe
Cloe programming language
Stars: ✭ 398 (-46.22%)
Mutual labels:  reactive, functional
Hint
💡 A hinting engine for the web
Stars: ✭ 3,280 (+343.24%)
Mutual labels:  hacktoberfest, performance
Bigcache
Efficient cache for gigabytes of data written in Go.
Stars: ✭ 5,304 (+616.76%)
Mutual labels:  hacktoberfest, performance
Alembic
⚗️ A Jekyll boilerplate theme designed to be a starting point for any Jekyll website
Stars: ✭ 501 (-32.3%)
Mutual labels:  hacktoberfest, jamstack
Observable
The easiest way to observe values in Swift.
Stars: ✭ 346 (-53.24%)
Mutual labels:  reactive, functional
Vertx Sql Client
High performance reactive SQL Client written in Java
Stars: ✭ 690 (-6.76%)
Mutual labels:  reactive, performance
Ghost Cli
CLI Tool for installing & updating Ghost
Stars: ✭ 313 (-57.7%)
Mutual labels:  hacktoberfest, jamstack
Plain Draggable
The simple and high performance library to allow HTML/SVG element to be dragged.
Stars: ✭ 362 (-51.08%)
Mutual labels:  performance, dom
Wipe Modules
🗑️ Easily remove the node_modules folder of non-active projects
Stars: ✭ 304 (-58.92%)
Mutual labels:  hacktoberfest, performance
Guider
Performance Analyzer
Stars: ✭ 393 (-46.89%)
Mutual labels:  hacktoberfest, performance
Htmlparser2
The fast & forgiving HTML and XML parser
Stars: ✭ 3,299 (+345.81%)
Mutual labels:  hacktoberfest, dom
Kubectl Flame
Kubectl plugin for effortless profiling on kubernetes
Stars: ✭ 297 (-59.86%)
Mutual labels:  hacktoberfest, performance
Rxswift
Reactive Programming in Swift
Stars: ✭ 21,163 (+2759.86%)
Mutual labels:  reactive, functional
Solid
A declarative, efficient, and flexible JavaScript library for building user interfaces.
Stars: ✭ 13,115 (+1672.3%)
Mutual labels:  reactive, performance

Sinuous

Version Badge size codecov Financial Contributors on Open Collective

npm: npm i sinuous
cdn: https://unpkg.com/sinuous
module: https://unpkg.com/sinuous?module


  • Small. hello world at ~1.4kB gzip.
  • Fast. top ranked of 80+ UI libs.
  • Truly reactive. automatically derived from the app state.
  • DevEx. no compile step needed, choose your view syntax.

Add-ons

Size Name Description
Badge size sinuous/observable Tiny observable (included by default)
Badge size sinuous/map Fast list renderer
Badge size sinuous/hydrate Hydrate static HTML
Badge size sinuous/template Pre-rendered Template
Badge size sinuous/data Enrich plain HTML with data in JS

All-in-one

Size Name Description
Badge size sinuous/all All modules in one bundle for easy use with a <script> tag

cdn: https://unpkg.com/sinuous/dist/all
module: https://unpkg.com/sinuous/module/all

Community

Examples


See complete docs, or in a nutshell...

View syntax

A goal Sinuous strives for is to have good interoperability. Sinuous creates DOM elements via hyperscript h calls. This allows the developer more freedom in the choice of the view syntax.

Hyperscript directly call h(type: string, props: object, ...children).

Tagged templates transform the HTML to h calls at runtime w/ the html`` tag or, at build time with sinuous/babel-plugin-htm.

JSX transforms at build time like React does via @babel/plugin-transform-react-jsx. See @heyheyhello/sinuous-tsx-example for JSX and TSX examples.

Handlebars/Mustache is possible with Hyperstache. See issue #49.


Counter Example (1.4kB gzip) (Codesandbox)

Tagged template (recommended)

import { observable, html } from 'sinuous';

const counter = observable(0);
const view = () => html` <div>Counter ${counter}</div> `;

document.body.append(view());
setInterval(() => counter(counter() + 1), 1000);

JSX

import { h, observable } from 'sinuous';

const counter = observable(0);
const view = () => <div>Counter {counter}</div>;

document.body.append(view());
setInterval(() => counter(counter() + 1), 1000);

Hyperscript

import { h, observable } from 'sinuous';

const counter = observable(0);
const view = () => h('div', 'Counter ', counter);

document.body.append(view());
setInterval(() => counter(counter() + 1), 1000);

Reactivity

The Sinuous observable module provides a mechanism to store and update the application state in a reactive way. If you're familiar with S.js or Mobx some functions will look very familiar, in under 1kB Sinuous observable is not as extensive but offers a distilled version of the same functionality. It works under this philosophy:

Anything that can be derived from the application state, should be derived. Automatically.

import { observable, computed, subscribe } from 'sinuous/observable';

const length = observable(0);
const squared = computed(() => Math.pow(length(), 2));

subscribe(() => console.log(squared()));
length(4); // => logs 16

Use a custom reactive library

Sinuous can work with different observable libraries; S.js, MobX, hyperactiv. See the wiki for more info.

Hydration

Sinuous hydrate is a small add-on that provides fast hydration of static HTML. It's used for adding event listeners, adding dynamic attributes or content to existing DOM elements.

In terms of performance nothing beats statically generated HTML, both in serving and rendering on the client.

You could say using hydrate is a bit like using jQuery, you'll definitely write less JavaScript and do more. Additional benefits with Sinuous is that the syntax will be more declarative and reactivity is built-in.

import { observable } from 'sinuous';
import { hydrate, dhtml } from 'sinuous/hydrate';

const isActive = observable('');

hydrate(
  dhtml`<a class="navbar-burger burger${isActive}"
    onclick=${() => isActive(isActive() ? '' : ' is-active')} />`
);

hydrate(dhtml`<a class="navbar-menu${isActive}" />`);

Internal API

Sinuous exposes an internal API which can be overridden for fun and profit. For example sinuous-context uses it to implement a React like context API.

As of 0.27.4 the internal API should be used to make Sinuous work with a 3rd party reactive library like Mobx. This can be done by overriding subscribe, root, sample and cleanup.

Example

import { api } from 'sinuous';

const oldH = api.h;
api.h = (...args) => {
  console.log(args);
  return oldH(...args);
};

Methods

These are defined in sinuous/src and sinuous/h.

  • h(type: string, props: object, ...children)
  • hs(type: string, props: object, ...children)
  • insert<T>(el: Node, value: T, endMark?: Node, current?: T | Frag, startNode?: Node): T | Frag;
  • property(el: Node, value: unknown, name: string, isAttr?: boolean, isCss?: boolean): void;
  • add(parent: Node, value: Value | Value[], endMark?: Node): Node | Frag;
  • rm(parent: Node, startNode: Node, endMark: Node): void;
  • subscribe<T>(observer: () => T): () => void;
  • root<T>(fn: () => T): T;
  • sample<T>(fn: () => T): T;
  • cleanup<T extends () => unknown>(fn: T): T;

Note that some observable methods are imported into the internal API from sinuous-observable because they're used in Sinuous' core. To access all observable methods, import from sinuous/observable directly.

Motivation

The motivation for Sinuous was to create a very lightweight UI library to use in our video player at Vimeo. The view layer in the player is rendered by innerHTML and native DOM operations which is probably the best in terms of performance and bundle size. However the need for a more declarative way of doing things is starting to creep up. Even if it's just for ergonomics.

The basic requirements are a small library size, small application size growth, fast TTI, not crucial but good render performance (creating & updating of DOM nodes).

More importantly, the developer experience. Working close to the metal with as few specialized syntaxes as possible is a key goal for Sinuous. The html`` tag returns a native Node instance and the components are nothing more than simple function calls in the view.

Another essential aspect is modularity, Sinuous is structured in a way that you only pay for what you use.

Concept

Sinuous started as a little experiment to get similar behavior as Surplus but with template literals instead of JSX. HTM compiles to an h tag. Adapted code from Ryan Solid's dom expressions + a Reactive library provides the reactivity.

Sinuous returns a hyperscript function which is armed to handle the callback functions from the reactive library and updates the DOM accordingly.

Browser Support

Sinuous supports modern browsers and IE11+ (requires Array.from polyfill if using sinuous/map, sinuous/render, sinuous/template, or sinuous/data).

Sauce Test Status

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

Big Thanks

Cross-browser Testing Platform and Open Source ❤ Provided by Sauce Labs

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].