0.1.11 • Published 1 year ago

@ceil-dev/microenv v0.1.11

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Microenv

Minimalistic state management with simple interface


Table of Contents

  1. Overview
  2. Installation
  3. Usage
  4. Example
  5. License

Overview

MicroEnv is a simple and lightweight state management library designed to handle application state with minimal complexity. It operates using three core methods: "get", "set", and "call", allowing you to easily retrieve, update, and manipulate state. The "get" method can also return a promise when used with a "next" flag, which enables asynchronous subscription to state changes and simplifies reactivity.


Installation

# Clone the repository
npm install @ceil-dev/microenv

Usage

import {microEnv} from '@ceil-dev/microenv';

Example

import {microEnv} from '@ceil-dev/microenv';

const run = async () => {
  // Create a new microEnv instance
  const myEnv = microEnv(
    {
      propA: 1,
      propB: "two",
      propC: (payload, caller) => {
        return { message: `Hello ${payload}`, caller };
      },
    },
    { id: "myEnv" },
  );

  // This will log the initial value of propA
  console.log("myEnv propA value:", myEnv.get("propA"));

  // Awaiting the future value of propB by using flag `next: true`
  (async () => {
    console.log(
      "myEnv new propB value:",
      await myEnv.get("propB", "someCallerId", true),
    );
  })().catch(console.warn);

  // Log initial value of propC (the log will be called before the propB value)
  console.log("myEnv propC call result:", myEnv.face.propC("World"));

  // Update propB value
  setTimeout(() => {
    myEnv.face.propB = 68;
  }, 2000);
};

run().catch(console.warn);

License

This project is licensed under the MIT License - see the LICENSE file for details.

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.19

1 year ago

0.0.18

1 year ago

0.0.15

2 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago