Lightweight library for creating reactive objects.


Keywords
snar, reactivity, vanilla
License
MIT
Install
npm install snar@2.1.5

Documentation

Snar

Reactive Object made simple.

Published on npm

Snar is a tiny library that helps creating simple yet efficient reactive objects.

import {ReactiveObject, state} from 'snar';

class MyObject extends ReactiveObject {
  @state() value;

  updated() {
    // Every time `value` changes,
    // this function is called as a reaction.
    // Do something...
  }
}

const obj = new MyObject();
obj.value = 'foo'; // <- makes the object reacts.

Installation

npm i -D snar

or

yarn add -D snar

Relation with Lit

Snar base class ReactiveObject was made by pruning ReactiveElement base class from @lit/reactive-element package of the Lit framework, and only keep the reactivity feature.
This implies:

  • You don't need Lit as a dependency to use this library. In fact Snar has no dependencies.
  • You can use it in both Node and Browser environment.
  • If you've used Lit before, you'll feel yourself at home because it shares the same syntax.