@ceil-dev/microenv v0.1.11
Microenv
Minimalistic state management with simple interface
Table of Contents
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/microenvUsage
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.
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago