0.1.21 • Published 1 year ago

cagibi v0.1.21

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

Cagibi Illustration

Addition-only asynchronous state based on static data stitching
import { make } from 'cagibi';

// Create a stitchable copy of your object
const profile = make({ name: 'Joe', posts: [] });

// Use your object as a reference to stitch a sub-object
const post = make({ title: 'A new post' }, profile.posts);

// Stitch them all to get the final object
const stitched = stitch(profile, post);

// => { name: 'Joe', posts: [{ title: 'A new post' }] }

npm i cagibi / yarn add cagibi

Version Downloads

Cagibi's name comes from the french word used to call a small storeroom. Pronounced /kä'jēbē/.

What is cagibi?

  • Two main methods to use it: make and stitch.
  • Two more methods to use it with persisted state or through remote channels: write and read.
  • Some utilities like protect(target, ...keys) to forbid changes on keys.
  • And a Patches array-based class to help handling all patches to be stitched back into one object.
  • No store.
  • No complex API.
  • Fully extendable.
  • Intends to work with all native objects.

When would cagibi come in handy?

Merging nested data structure through async channels (API, parallel threads or job queues) without willing to maintain a key-value store with primary keys linking records.

Create a stitchable copy of your object

import { make } from 'cagibi';

const profile = make({ name: 'Joe', posts: [] });
// => { name: 'Joe', posts: [] }

Use your object as a reference to stitch a sub-object

const post = make({ title: 'A new post' }, profile.posts);

Stitch them all to get the final object

import { stitch } from 'cagibi';

const stitched = stitch(profile, post);

Returns stitched state:

{
    "name": "Joe",
    "posts": [{ "title": "A new post" }]
}

Need to re-use it asynchronously or later?

import { make, stitch, write, read } from 'cagibi';

const stack = [];

const profile = make({ name: 'Joe', posts: [] });
const post = make({ title: 'A new post' }, profile.posts);

stack.push(write(profile));
stack.push(write(post));

// ...
// And only later on or in another environment
const profile = read(profileWritten);
const post = read(postWritten);
const stitched = stitch(profile, post);

Returns stitched state:

{
    "name": "Joe",
    "posts": [{ "title": "A new post" }]
}

Need help managing all patches?

import { make, stitch, write, read, Patches } from 'cagibi';

const patches = new Patches();

const profile = make({ name: 'Joe', posts: [] });
const post = make({ title: 'A new post' }, profile.posts);

patches.push(profile, post);

const savedPatches = patches.write();

// ...
// And only later on or in another environment

const importedPatches = new Patches();
importedPatches.read(savedPatches);

const stitched = importedPatches.stitch();

Returns stitched state:

{
    "name": "Joe",
    "posts": [{ "title": "A new post" }]
}
0.1.21

1 year ago

0.1.2

1 year ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.30

2 years ago

0.0.29

2 years ago

0.0.28

2 years ago

0.0.27

2 years ago

0.0.26

2 years ago

0.0.25

2 years ago

0.0.24

2 years ago

0.0.23

2 years ago

0.0.22

2 years ago

0.0.21

2 years ago

0.0.20

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.1

2 years ago