@farsoc/atlas
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

Documentation

You can find documenation (work is still in progress) in required part of following wiki.

About

ATLAS stands for Abstract Tree-Like Adaptive State. This state management system was designed to give you freedom of organizing your state in required way in simple manner. So, ATLAS does not have:

  • required boilerplate code
  • unnecessary layers of abstraction
  • "golden hammer"-like principles in its core

Instead of it Atlas offers:

  • compact and intuitive syntax
  • opportunity to write easily reusable state logic modules
  • simple and scalable design

Bindings

ATLAS has simple and flexible events system which makes easy to bind it to diffirent systems. You might be interested in React bindings for ATLAS.

Main concept

We treat state as collection of nodes in ATLAS. So, every state operation basically becomes an operation with node. ATLAS provides multiple manners of updating data (including mutations, immutable updates and plain rewrites). Let's take a look at simple example:

import { readAll, write, mutate } from "@farsoc/atlas";

type Greeter = { name: string };
const greeter: Greeter = { name: "P1" };

write("test", 1);
write("hello.world", greeter);

// {test: 1, hello: { world: { name: "P1" }}}
const currentState = readAll();

/*
 * Let's make this example more complex and 
 * change some existing data!
 */

mutate<Greeter>("hello.world", (x) => (x.name += " mutated"));

// { name: "P1 mutated" }
const worldGreeter = read<Greeter>("hello.world");

This approach is flexible, but not very reliable, because we have to duplicate node pathes when we work with same nodes. So, there is a solution for this trouble - we can treat nodes isolated with help of @farsoc/entity-atlas-nodes package. It contains very useful node abstractions you can use right out of the box! Let's take a look at this approach:

import { MutableObjectNode } from "@farsoc/entity-atlas-nodes";
import { readAll } from "@farsoc/atlas";

type Greeter = { name: string };

const worldGreeter = new MutableObjectNode<Greeter>({
    initialValue: { name: "P1" },
    nodePath: "hello.world"
});

worldGreeter.mutate((x) => (x.name += " mutated"));

// { name: "P1 mutated" }
const greeter = worldGreeter.value;

// { hello: { world: { name: "P1 mutated" }}}
const state = readAll();

Package Sidebar

Install

npm i @farsoc/atlas

Weekly Downloads

0

Version

1.0.5

License

MIT

Unpacked Size

30.6 kB

Total Files

16

Last publish

Collaborators

  • fearnor
  • revrulb