GithubHelp home page GithubHelp logo

fabiospampinato / flimsy Goto Github PK

View Code? Open in Web Editor NEW
177.0 4.0 6.0 54 KB

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

License: MIT License

TypeScript 81.72% JavaScript 18.28%
reactivity simple solid tiny

flimsy's Introduction

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, getOwner, runWithOwner, 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 report a bug I'll look into it.
  • 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

flimsy's People

Contributors

apollo79 avatar fabiospampinato avatar jlarky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

flimsy's Issues

Typescript type error during compilation

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.

Recommend Projects

  • React photo React

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

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.