@iniz/core
TypeScript icon, indicating that this package has built-in type declarations

0.8.0 • Public • Published

Iniz

Iniz is a reactive state library. Try it out on our website!

npm i @iniz/core

Build Status Test Coverage Build Size Version Downloads

Guide

Getting started

Create an atom

Atom is the smallets unit of reactive state.

import { atom } from "@iniz/core";

const timer$ = atom(new Date());

// It can be a complex nested object/array as well...
const nestedCounter$ = atom({
  obj: {
    array: [{ count: 3 }],
    message: "Hello World",
  },
});

Mutate the atom value

Call the atom to read/write it.

timer$(); // Returns latest value e.g. `2019-08-31T00:00:00.000Z`

setInterval(() => {
  nestedCounter$().obj.array[0].count++;
  timer$(new Date());
  // Calling it as function also sets `value`
}, 1000);

// Later on...
timer$(); // Returns latest value e.g. `2022-08-31T00:00:00.000Z`
nestedCouner$().obj.array[0].count;

Subscribe to atom

Use effect() to subscribe to value change.

const dispose = effect(() => {
  console.log("Updated timer: ", timer$());
});

// Execute `dispose` to stop effect
dispose();

Use computed() to get calculated value from multiple atoms.

const timerAndCounter$ = computed(
  () => `Computed: '${nestedCounter$().obj.array[0]}' '${timer$()}'`
);

timerAndCounter$(); // Returns "Computed: 2022-08-31T00:00:00.000Z 4"

Readme

Keywords

none

Package Sidebar

Install

npm i @iniz/core

Weekly Downloads

0

Version

0.8.0

License

MIT

Unpacked Size

132 kB

Total Files

96

Last publish

Collaborators

  • inizio