1 | const Chainable = require('./Chainable');
|
2 |
|
3 | module.exports = class extends Chainable {
|
4 | constructor(parent) {
|
5 | super(parent);
|
6 | this.store = new Set();
|
7 | }
|
8 |
|
9 | add(value) {
|
10 | this.store.add(value);
|
11 | return this;
|
12 | }
|
13 |
|
14 | prepend(value) {
|
15 | this.store = new Set([value, ...this.store]);
|
16 | return this;
|
17 | }
|
18 |
|
19 | clear() {
|
20 | this.store.clear();
|
21 | return this;
|
22 | }
|
23 |
|
24 | delete(value) {
|
25 | this.store.delete(value);
|
26 | return this;
|
27 | }
|
28 |
|
29 | values() {
|
30 | return [...this.store];
|
31 | }
|
32 |
|
33 | has(value) {
|
34 | return this.store.has(value);
|
35 | }
|
36 |
|
37 | merge(arr) {
|
38 | this.store = new Set([...this.store, ...arr]);
|
39 | return this;
|
40 | }
|
41 |
|
42 | when(
|
43 | condition,
|
44 | whenTruthy = Function.prototype,
|
45 | whenFalsy = Function.prototype
|
46 | ) {
|
47 | if (condition) {
|
48 | whenTruthy(this);
|
49 | } else {
|
50 | whenFalsy(this);
|
51 | }
|
52 |
|
53 | return this;
|
54 | }
|
55 | };
|