A lightweight library to create reactive objects

Overview

Reactivity

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

Get started

NPM:

npm install @darudlingilien/reactivity 

Then...

import Reactivity from '@darudlingilien/reactivity'

CDN:

<script src="https://unpkg.com/@darudlingilien/[email protected]/cdn/reactivity.min.js"></script>

Usage

First, Reactivity must be instantiated

const Reactive = new Reactivity();

The Reactivity constructor receives one paramater, an options parameter, which needs to receive all the data, middlewares and callbacks. For example...

new Reactivity({
    data: {
        msg: {
            type: String,
        }
    },
    beforeUpdating({ msg }) {
        console.log(msg);
    },
    updated({ msg }) {
        console.log(msg);
    },
    middlewares: {
        setters: {
            isEqualToHelloWorld(_, __, value) {
                return value === "Hello world";
            }
        },
        getters: //...
    }
});

About options properties...

  1. data is required, each of its properties must have two sub-properties, type and value. This last one is optional, but type is required, it must be a build-in object constructor, like String, Boolean, Array...
  2. beforeUpdating/updated, could be functions or objects (with functions of course), the parameter is the current state of the data
  3. middlewares property has two sub-properties, setters and getters, each function defined in both properties receives the same parameters of a Proxy get and set traps and must return a boolean, otherwise it will fail

Actions

For set a property...

Reactive.data.msg = "Hello world";

For get a property...

console.log(Reactive.data.msg);

All these actions will trigger all callbacks, either beforeUpdating/updated and middlewares

That's it, I hope you enjoy these package!

You might also like...
A lightweight reactivity API for other UI libraries to be built on top of.
A lightweight reactivity API for other UI libraries to be built on top of.

This is a tiny (~850B minzipped) library for creating reactive observables via functions. You can use observables to store state, create computed properties (y = mx + b), and subscribe to updates as its value changes.

A minimum and lightweight external store for React and React Native application

Reactive store - a minimum and lightweight external store for React and React Native application Table of contents Features Installation Usage 3.1 Cre

Simple and elegant component-based UI library
Simple and elegant component-based UI library

Simple and elegant component-based UI library Custom components • Concise syntax • Simple API • Tiny Size Riot brings custom components to all modern

A tiny ( 1KB) reactivity library

influer A tiny ( 1KB) reactivity library yarn add influer Introduction influer is a tiny reactivity library. Exported in ESM, CJS, and IIFE, all 1K

React library for ux4iot for easily building IoT web applications

React library for ux4iot for easily building IoT web applications

Fire7 is a small library that implements real-time data binding between Firebase Cloud Firestore and your Framework7 app.

Fire7 is a small library that implements real-time data binding between Firebase Cloud Firestore and your Framework7 app.

react-pdf-highlighter is a React library that provides annotation experience for PDF documents on web.

☕️ Buy me a coffee react-pdf-highlighter react-pdf-highlighter is a React library that provides annotation experience for PDF documents on web. It is

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.

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

A tiny library aims to parse HTML to Figma Layer Notation and do it well.

TSDX User Guide Congrats! You just saved yourself hours of work by bootstrapping this project with TSDX. Let’s get you oriented with what’s here and h

Owner
David Linarez
I like to program videogames and web
David Linarez
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

Adam Hill 20 Feb 25, 2023
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 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
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
A single-file <1kb min+gzip simplified implementation of the reactive core of Solid, optimized for clean code

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

Fabio Spampinato 116 Dec 19, 2022
Lightweight react-like library. Support for asynchronous rendering and hooks.

Recept · Lightweight react-like library. Like the name, this project is mainly based on the architectural idea of react, which can feel react more int

RuiLin Dong 52 Sep 17, 2022