A single-file <1kb min+gzip simplified implementation of the reactive core of Solid, optimized for clean code

Overview

Flimsy

A single-file <1kb min+gzip simplified implementation of the reactive core of Solid, optimized for clean code.

Check out the annotated source, if you'd like to more in depth understand how Solid works, or if you'd like to write something similar yourself, this should be a good starting point for you.

Comparison

Compared to how Solid's reactivity system actually works there are the following (known) differences:

  • "Only" these functions are implemented: createSignal, createEffect, createMemo, createRoot, createContext, useContext, onCleanup, onError, batch and untrack.
  • createSignal's setter doesn't give you the current updated value inside a batch, but instead gives you the same value that the getter would give you.
  • createEffect doesn't schedule effects, they are executed immediately just like memos. In Solid they are scheduled if they exist inside a root.
  • createEffect and createMemo don't pass the previous execution's return value to your function, just put the value in a variable outside of the function yourself to remember it, if you need that.
  • createContext gives you get/set functions instead of a Provider component, as the Provider component only really makes sense in a UI context and Solid doesn't expose a lower-level context primitive.
  • createContext's set function will register the context value with the parent observer, so you need to create a custom parent observer yourself (which is basically what Provider does), if you need that.
  • Flimsy uses a MobX-like propagation algorithm, where computations in the reactive graph are marked stale/ready, Solid should work similarly, but I don't understand it well enough to know what the differences may be.
  • Flimsy doesn't care about performance nor memory usage, it instead optimizes for clean code.
  • Flimsy is probably buggier, hence the name, though if you'd like to use this in production please open an issue, I'll wire it with oby's extensive test suite.
  • Solid's reactivity system doesn't do anything on the server by default, you'll have to explicitly use the browser build to make it work, Flimsy is isomorphic.

Install

npm install --save flimsy

Usage

You should be able to use these functions pretty much just like you would use Solid's, for example:

import {createSignal, createEffect, createMemo} from 'flimsy';

// Make a counter, a memo from the counter, and log both in an effect

const [count, setCount] = createSignal ( 0 );

const double = createMemo ( () => count () * 2 );

createEffect ( () => {

  console.log ( 'count', count () );
  console.log ( 'double', double () );

});

License

MIT © Fabio Spampinato

You might also like...
A tiny, blazing fast view library that creates reactive Web Components

dlite A tiny, blazing fast view library that creates reactive Web Components 📖 Complete documentation https://dlitejs.com 🧐 Introduction dlite creat

The next open source file uploader for web browsers :dog:
The next open source file uploader for web browsers :dog:

Uppy Tests Deploys Uppy is a sleek, modular JavaScript file uploader that integrates seamlessly with any application. It’s fast, easy to use and lets

Modern file uploading - components & hooks for React
Modern file uploading - components & hooks for React

Modern file-upload components & hooks for React. Contents Intro Documentation Installation Packages Examples Important Concepts Resumable Uploads UMD

basic implementation of the Vue 3 reactivity engine - from scratch

Vue 3 Reactivity This material was created by Marc Backes in order to show how reactivity is solved in Vue 3. It contains a basic implementation of th

Tiny React.js notification library (1kb gzip).

Simple-React-Notifications Tiny library (only 1kb gzip) that allows you to add notifications to your app. We don't want to blow up our bundle size bec

Code Surfer adds code highlighting, code zooming, code scrolling, code focusing, code morphing, and fun to MDX Deck slides.
Code Surfer adds code highlighting, code zooming, code scrolling, code focusing, code morphing, and fun to MDX Deck slides.

Code Surfer Help to keep this project alive with your support ❤️ Code Surfer adds code highlighting, code zooming, code scrolling, code focusing, code

⚡️The Fullstack React Framework — built on Next.js
⚡️The Fullstack React Framework — built on Next.js

⚡️The Fullstack React Framework — built on Next.js

⚡️The Fullstack React Framework — built on Next.js — Inspired by Ruby on Rails
⚡️The Fullstack React Framework — built on Next.js — Inspired by Ruby on Rails

⚡️The Fullstack React Framework — built on Next.js — Inspired by Ruby on Rails

Dapp-core-components - A library that holds the core logic of a dapp on the Elrond Network with an example to get started easily

A library that holds the core logic of a dapp on the Elrond Network with an example to get started easily

A small ~1kb, Hook-based library for creating Reactive-UI in Vanilla.

Vanic A small, Hook-based library for creating Reactive-UI in Vanilla. Features Reactive-UI. Hooks. No compiler and build-tool required. Jsx & literal

Solid-spring is a spring-physics first animation library for SolidJS based on react-spring/core.
Solid-spring is a spring-physics first animation library for SolidJS based on react-spring/core.

solid-spring A port of react-spring, for SolidJS solid-spring is a spring-physics first animation library for SolidJS based on react-spring/core. This

A blend of @preact/signals-core and solid-js basic reactivity API
A blend of @preact/signals-core and solid-js basic reactivity API

A blend of @preact/signals-core and solid-js basic reactivity API, with API and DX mostly identical to @preact/signals-core but extra goodness inspired by solid-js, 726 bytes minified with brotli.

Sistema em ReactJs usando Hooks, Typescript, TDD, Clean Architecture, Design Patterns e SOLID principles
Sistema em ReactJs usando Hooks, Typescript, TDD, Clean Architecture, Design Patterns e SOLID principles

4Dev React - Enquetes para Programadores Link para o curso completo Essa sistema faz parte do treinamento do professor Rodrigo Manguinho (Mango) na Ud

Starter project with full stack BigQuery. Allows to overcome customisation restrictions imposed by pre-built dashboards and control data usage. Deploy your own cloud website hydrated by sample BigQuery data in 15 min without installing any development software. React-compress - This compress library was made with Brotli and Gzip help, for React users who want to make website more performance and reduce JS bundle code
React-compress - This compress library was made with Brotli and Gzip help, for React users who want to make website more performance and reduce JS bundle code

React-compress - This compress library was made with Brotli and Gzip help, for React users who want to make website more performance and reduce JS bundle code

Solid SimpleTable is a blazing fast reactive table component that gives you freedom.
Solid SimpleTable is a blazing fast reactive table component that gives you freedom.

Solid SimpleTable Solid SimpleTable is a blazing fast reactive table component that gives you freedom. Features Very fast as it is compiled down to Va

A simplified Jira clone built with React/Babel (Client), and Node/TypeScript (API). Auto formatted with Prettier, tested with Cypress.
A simplified Jira clone built with React/Babel (Client), and Node/TypeScript (API). Auto formatted with Prettier, tested with Cypress.

A simplified Jira clone built with React and Node Auto formatted with Prettier, tested with Cypress 🎗 Visit the live app | View client | View API Wha

This project is a simplified a full stack clone of Stackoverflow.

Stackoverflow Clone Live: http://clone-of-stackoverflow.vercel.app/ This project is a simplified a full stack clone of Stackoverflow. I wrote it to le

A simplified Trello clone built with React, Redux, Node, Express and MongoDB.
A simplified Trello clone built with React, Redux, Node, Express and MongoDB.

Trellis A Trello Clone - Built with React, Redux, Express, and MongoDB. 📢 : I'm looking for maintainers, feel free to reach out to me on [email protected]

Comments
  • fix file path in package.json

    fix file path in package.json

    the error:

    1. go to https://bundlejs.com/?q=flimsy
    2. press build
    image

    for https://unpkg.com/flimsy wrong url: https://unpkg.com/[email protected]/flimsy.js right url: https://unpkg.com/[email protected]/src/flimsy.js

    opened by JLarky 2
  • add .gitignore

    add .gitignore

    this is just the stuff that was clearly wrong :) try to search for templates or use mine :) https://github.com/JLarky/react-lazily/blob/main/.gitignore

    opened by JLarky 1
  • Address TS errors

    Address TS errors

    Thank you so much for your great job.

    I found 3 issues in flimsy.annotated.ts file

    Function lacks ending return statement and return type does not include 'undefined'.ts(2366) 3

    Argument of type 'this' is not assignable to parameter of type 'Signal'. Type 'Signal' is not assignable to type 'Signal'. 2

    Argument of type 'this' is not assignable to parameter of type 'Computation'. Type 'Observer' is missing the following properties from type 'Computation': fn, signal, waiting, fresh, and 3 more.ts(2345) 1

    Is it possible to check them? becuase I cannot build the source code.

    bug 
    opened by HamedFathi 2
Owner
Fabio Spampinato
Full-stack developer passionate about open source and empowering people.
Fabio Spampinato
A blazing fast, dependency free, 1kb runtime type-checking library written entirely in typescript, meant to be used with it.

A blazing fast, dependency free, 1kb runtime type-checking library written entirely in typescript, meant to be used with it.

Gabriel Vaquer 90 Dec 9, 2022
Harness the power of reactive programming to supercharge your components

Handle your component effects and side-effects in a clear and declarative fashion by using asynchronous data streams (reactive programming). Why? · In

FanDuel OSS 810 Jan 7, 2023
A minisize vue2/3 reactive clipboard

vue-reactive-clipboard A minisize vue2/3 reactive clipboard Install Install with yarn: $ yarn add vue-reactive-clipboard Install with npm: $ npm i vue

Cinob 3 Aug 3, 2021
A lightweight library to create reactive objects

Reactivity As the name says, Reactivity is a lightweight javascript library to create simple reactive objects. Inspired in Redux and Vuex Get started

David Linarez 2 Oct 28, 2021
A reactive filesystem interface based on Vue 3 reactivity system.

A reactive filesystem interface based on Vue 3 reactivity system.

Guillaume Chau 37 Oct 8, 2022
micro reactive state management - just for fun

effectus micro reactive state management - just for fun Install $ yarn add effectus Usage import { effect, signal } from 'effectus' const [name, set

Hector Zarco 1 Dec 7, 2021
A tiny, reactive JavaScript library for structured state and tabular data.

A JavaScript library for structured state. Using plain old JavaScript objects to manage data gets old very quickly. It's error-prone, tricky to track

tinyplex 1.4k Dec 30, 2022
Subscribe to any reactive source, weakly

sube Subscribe weakly to any reactive source import sub from './sube.js' unsub = sub(source, onnext, onerror?, oncomplete?) // ...unsubscribe unsub(

Spect 7 Oct 21, 2022
A reactive store that is fine, really. It works with React.

trashly A reactive store that is fine, really. It works with React. Note: These docs assume you're using the trashly-react library. The vanilla trashl

Steve Ruiz 52 Sep 19, 2022
A reactive store that is fine, really. It works with React.

A reactive store that is fine, really. It works with React.

Steve Ruiz 109 Dec 17, 2022