0.0.43 • Published 1 year ago

dylanjs v0.0.43

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

stallone

Fine grained reactive UI Library

Version License: MIT Build Status Badge size

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


  • Small. hello world at ~3kB gzip.
  • Truly reactive and fine grained. automatically derived from the app state.
  • Rich ecosystem. From router to graphQL integration.
  • DevEx. no compile step needed, choose your view syntax: h or <JSX/>.

Example

Counter - Codesandbox

/** @jsx h **/

import { component, h, render } from "stallone";

export const HomePage = component<{ name: string }>(
    "HomePage",
    (props, { signal, wire }) => {
        const count = signal(0);
        return (
            <div id="home">
                <p>Hey, {props.name}</p>
                <button
                    onclick={() => {
                        count(count() + 1);
                    }}
                >
                    Increment to {wire(count)}
                </button>
            </div>
        );
    }
);

render(<HomePage name="John Doe" />, document.body);

Motivation

The state part of this library is based on haptic specially the concept of aptly named Signals and Wires. Like haptic it also favours manual subscription model instead of automatic subscriptions model.

It's also influenced by Sinuous, Solid, & S.js

Signals

These are reactive read/write variables who notify subscribers when they've been written to. They are the only dispatchers in the reactive system.

const state = signal({
    name: "Deciduous Willow",
    age: 85,
});

state.name; // [Function: signal|0{name}]
state.name(); // 'Deciduous Willow'
state.name("Willow");
state.name(); // 'Willow'

The subscribers to signals are wires, which will be introduced next. They subscribe by read-subscribing the signal. This is an important distinction - signals have two types of reads!

state.name(); // Passive read (read-pass)
state.name($); // Subscribed read (read-subscribe)

This is unlike other reactive libraries, but it'll save us a lot of debugging. Separating the reads it makes subscribed reads an explicit and visually distinct action from passive reads. This makes Haptic an opt-in design, and it doesn't need the sample() function seen in other libraries. This is explained later when introducing wires, which is also where the $ value comes from.

Wires

These are task runners who subscribe to signals and react to signal writes. They hold a function (the task) and manage its subscriptions, nested wires, run count, and other metadata. The wire provides a $ token to the function call that, at your discretion as the developer, can use to read-subscribe to signals.

wire(($) => {
    // Explicitly subscribe to state.name using the subtoken "$"
    const name = state.name($);
    console.log("Update to state.name:", name);
    return name;
});

API

  • signal
  • wire
  • getContext
  • setContext

Ecosystem

0.0.41

1 year ago

0.0.42

1 year ago

0.0.43

1 year ago

0.0.39

1 year ago

0.0.29

1 year ago

0.0.27

1 year ago

0.0.26

1 year ago

0.0.25

1 year ago

0.0.23

1 year ago

0.0.22

1 year ago

0.0.21

1 year ago

0.0.20

1 year ago

0.0.19

1 year ago

0.0.18

1 year ago

0.0.17

1 year ago

0.0.16

1 year ago

0.0.15

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago