Miss any of our Open RFC calls?Watch the recordings here! »

manatea

0.3.6 • Public • Published

TL;DR

Predictable micro state manager.

This package has no dependencies and weights less than 1kB (and less than 500B gzipped).

How to use

Create cup

import { createCup } from 'manatea';
 
// Defining a cup
const timer = createCup(0);
 
// Defining a named cup
const counter = createCup(0, 'counter');

Read cup's tea

// Accessing the tea
counter(); // 2;

Update cup's tea

counter(1);
 
counter(tea => tea + 1);
 
// Supports async functions
counter(async tea => {
  await sleep(1);
  return tea + 5;
});
 
timer((tea, namedStores) => {
  const counterTea = namedStores.counter();
  // "counter" is in the cup because it was previously named
  // on the opposite, "timer" won't ever be in the cup.
  return tea + counterTea;
});
 
// Every update functions return promises
counter(tea => tea + 1).then(tea => console.log(tea));

Store's listeners

// Add listener
const listener = counter.on(tea => console.log(tea));

Remove cup's listener

listener.listening; // true
listener();
listener.listening; // false
 
// OR
 
listener.listening; // true
counter.clear();
listener.listening; // false

Immutability

Every stores' tea are immutable:

const cup = createCup([]);
cup(tea => tea.push(1)); // Throws an error
cup(tea => [...tea, 1]); // OKAY

Install

npm i manatea

DownloadsWeekly Downloads

22

Version

0.3.6

License

MIT

Unpacked Size

13.8 kB

Total Files

11

Last publish

Collaborators

  • avatar