0.0.12 • Published 6 years ago

@nuuf/chink v0.0.12

Weekly downloads
12
License
MIT
Repository
-
Last release
6 years ago

chink

Chain objects together parent>child style

//#import
import { 
    create,
    add,
    remove,
    swap,
    bindList,
    stringifiedFind,
    stringifiedReplace,
    stringifyList,
    parseList
} from '@nuuf/chink';

//#example
const list = [];
bindList(list);

/**
 * Hugo
 *  Stina
 *   Carl
 *  Bob
 *   Henry
 *   Josie
 * 
 * Anna
 *  Jacob
 */

add(create(null, 'Hugo'));
add(create(null, 'Anna'));
add(create('any data', 'Stina'), {id: 'Hugo'});
add(create(null, 'Bob'), {id: 'Hugo'});
add(create(null, 'Jacob'), {id: 'Anna'});
add(create(null, 'Henry'), {id: 'Bob'});
add(create(null, 'Josie'), {id: 'Bob'});
add(create({name: 'Carl'}, 'Carl'), {id: 'Stina'});
swap({id: 'Stina'}, {id: 'Anna'});
swap({id: 'Jacob'}, {id: 'Henry'});
// DO NOT swap({id: 'Stina'}, {'Hugo'}) as Stina is a child of Hugo
remove({id: 'Stina'}); // To be crunched
// remove({id: 'Carl'}); ERROR: NOT IN LIST, Carl was a child of Stina

/**
 * Hugo
 *  Anna
 *   Henry
 *  Bob
 *   Jacob
 *   Josie
 * null
 */
// Delete null values
crunchNull();

/**
 * Find the entity using find or stringifiedFind if the list is stringified
 * Update the data
 * stringifiedReplace(entity)
 */

// This
let Josie = find({id: 'Josie'});

// (before stringifiedFind/stringifiedReplace)
stringifyList();

// Or
Josie = stringifiedFind(Josie);

Josie.data = {
    name: 'Josie'
};

stringifiedReplace(Josie);

parseList();

console.log(JSON.stringify(list, null, 2));
0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago