ランキングに戻る

luwes/sinuous

JavaScriptsinuous.netlify.app

🧬 Light, fast, reactive UI library

reactivehyperscriptdomjavascriptuifunctionalsinuous
スター成長
スター
1.1k
フォーク
34
週間成長
Issue
11
5001k
2019年4月2021年9月2024年2月2026年7月
成果物npmnpm install sinuous
README

Sinuous

Version Badge size codecov

npm: npm i sinuous
cdn: https://cdn.jsdelivr.net/npm/sinuous/+esm


  • 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

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 needs to be transformed at build time first with babel-plugin-transform-jsx-to-htm and after with sinuous/babel-plugin-htm.


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.

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.

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]

関連リポジトリ
solidjs/solid

A declarative, efficient, and flexible JavaScript library for building user interfaces.

TypeScriptnpmMIT Licensejavascriptperformance
solidjs.com
35.8k1.1k
ReactiveX/RxSwift

Reactive Programming in Swift

SwiftMIT Licenseswiftreactivex
24.6k4.2k
marimo-team/marimo

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

PythonPyPIApache License 2.0notebookspython
marimo.io
21.9k1.2k
leptos-rs/leptos

Build fast web applications with Rust.

Rustcrates.ioMIT Licensedomfine-grained
leptos.dev
21.1k878
JetBrains/compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.

KotlinApache License 2.0kotlinui
jetbrains.com/lp/compose-multiplatform
19.2k1.4k
quarkusio/quarkus

Quarkus: Supersonic Subatomic Java.

JavaMavenApache License 2.0kubernetesjava
quarkus.io
15.8k3.2k
eclipse-vertx/vert.x

Vert.x is a tool-kit for building reactive applications on the JVM

JavaMavenOthervertxjava
vertx.io
14.7k2.1k
akka/akka-core

A platform to build and run apps that are elastic, agile, and resilient. SDK, libraries, and hosted environments.

ScalaOtherreactivedistributed-systems
doc.akka.io/libraries/
13.3k3.5k
akka/akka

A platform to build and run apps that are elastic, agile, and resilient. SDK, libraries, and hosted environments.

ScalaOtherreactivedistributed-systems
doc.akka.io
13.1k3.6k
playframework/playframework

The Community Maintained High Velocity Web Framework For Java and Scala.

ScalaApache License 2.0scalajava
playframework.com
12.6k4k
alibaba/formily

📱🚀 🧩 Cross Device & High Performance Normal Form/Dynamic(JSON Schema) Form/Form Builder -- Support React/React Native/Vue 2/Vue 3

TypeScriptnpmMIT Licensereactjson-schema
formilyjs.org
12.6k1.6k
Nozbe/WatermelonDB

🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️

JavaScriptnpmMIT Licensereact-nativereact
watermelondb.dev
11.8k652