2.0.1 • Published 12 months ago

@proc7ts/delta-set v2.0.1

Weekly downloads
20
License
MIT
Repository
github
Last release
12 months ago

DeltaSet

NPM Build Status Code Quality Coverage GitHub Project API Documentation

JavaScript Set keeping delta of changes made to it

A DeltaSet class inherits ES2015 Set. In addition, it keeps changes made to it and has methods to deal with these changes' delta.

import { DeltaSet } from '@proc7ts/delta-set';

// Construct a delta set containing specified elements
// and record their addition.
const deltaSet = new DeltaSet([1, 2, 3]); // [1, 2, 3]

// Remove element and record its removal
deltaSet.delete(2); // [1, 3]

// Add element and record its addition
deltaSet.add(4); // [1, 3, 4]

const otherSet = new Set<number>();

// Replay changes in another set
deltaSet.redelta(otherSet); // otherSet: [1, 3, 4]

// Changes may be reported to receiver function
deltaSet.redelta((add, remove) => console.log('added:', ...add, '; removed:', ...remove));
// Logs: added: 1 3 4 ; removed: 2

// Forget about changes made to delta set
deltaSet.undelta();

// Apply more changes
deltaSet.delta(/* add */ [11, 12], /* remove */ [4]); // [1, 3, 11, 12]

// Replay last changes in another set
deltaSet.redelta(otherSet); // otherSet: [1, 3, 11, 12]

// Remove all elements and record their removal
deltaSet.clear();

deltaSet.redelta((add, remove) => console.log('added:', ...add, '; removed:', ...remove));
// Logs: added: ; removed: 4 1 3 11 12
2.0.1

12 months ago

2.0.0

1 year ago

1.5.0

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago