shelving 1.55.0 → 1.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.55.0",
14
+ "version": "1.56.0",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -9,26 +9,26 @@ export class ArrayState extends State {
9
9
  }
10
10
  /** Get the length of the current value of this state. */
11
11
  get length() {
12
- return this.value.length;
12
+ return this._value.length;
13
13
  }
14
14
  /** Add an item to this array. */
15
15
  add(item) {
16
- this.next(withItem(this.value, item));
16
+ this.next(withItem(this._value, item));
17
17
  }
18
18
  /** Remove an item from this array. */
19
19
  delete(item) {
20
- this.next(withoutItem(this.value, item));
20
+ this.next(withoutItem(this._value, item));
21
21
  }
22
22
  /** Swap an item in this array with a different item. */
23
23
  swap(oldItem, newItem) {
24
- this.next(swapItem(this.value, oldItem, newItem));
24
+ this.next(swapItem(this._value, oldItem, newItem));
25
25
  }
26
26
  /** Toggle an item in this array. */
27
27
  toggle(item) {
28
- this.next(toggleItem(this.value, item));
28
+ this.next(toggleItem(this._value, item));
29
29
  }
30
30
  /** Iterate over the items. */
31
31
  [Symbol.iterator]() {
32
- return this.value.values();
32
+ return this._value.values();
33
33
  }
34
34
  }
@@ -0,0 +1,7 @@
1
+ import { State } from "./State.js";
2
+ /** State that stores a boolean and has additional methods to help with that. */
3
+ export declare class BooleanState extends State<boolean> {
4
+ _value: boolean;
5
+ /** Toggle the current boolean value. */
6
+ toggle(): void;
7
+ }
@@ -0,0 +1,13 @@
1
+ import { State } from "./State.js";
2
+ /** State that stores a boolean and has additional methods to help with that. */
3
+ export class BooleanState extends State {
4
+ constructor() {
5
+ super(...arguments);
6
+ // Set default value to be false.
7
+ this._value = false;
8
+ }
9
+ /** Toggle the current boolean value. */
10
+ toggle() {
11
+ this.next(this._value ? false : true);
12
+ }
13
+ }
@@ -0,0 +1,14 @@
1
+ import { Entry, ImmutableObject } from "../util/index.js";
2
+ import { State } from "./State.js";
3
+ /** State that stores a map-like object and has additional methods to help with that. */
4
+ export declare class ObjectState<T> extends State<ImmutableObject<T>> implements Iterable<Entry<T>> {
5
+ _value: {};
6
+ /** Get the length of the current value of this state. */
7
+ get length(): number;
8
+ /** Remove a named entry from this object. */
9
+ delete(key: string): void;
10
+ /** Set a named entry in this object with a different value. */
11
+ set(key: string, value: T): void;
12
+ /** Iterate over the items. */
13
+ [Symbol.iterator](): Iterator<Entry<T>, void>;
14
+ }
@@ -0,0 +1,26 @@
1
+ import { withEntry, withoutEntry } from "../util/index.js";
2
+ import { State } from "./State.js";
3
+ /** State that stores a map-like object and has additional methods to help with that. */
4
+ export class ObjectState extends State {
5
+ constructor() {
6
+ super(...arguments);
7
+ // Set default value to be empty object.
8
+ this._value = {};
9
+ }
10
+ /** Get the length of the current value of this state. */
11
+ get length() {
12
+ return Object.keys(this._value).length;
13
+ }
14
+ /** Remove a named entry from this object. */
15
+ delete(key) {
16
+ this.next(withoutEntry(this._value, key));
17
+ }
18
+ /** Set a named entry in this object with a different value. */
19
+ set(key, value) {
20
+ this.next(withEntry(this._value, key, value));
21
+ }
22
+ /** Iterate over the items. */
23
+ [Symbol.iterator]() {
24
+ return Object.entries(this._value)[Symbol.iterator]();
25
+ }
26
+ }
package/stream/index.d.ts CHANGED
@@ -3,5 +3,7 @@ export * from "./LazyStream.js";
3
3
  export * from "./LastStream.js";
4
4
  export * from "./State.js";
5
5
  export * from "./LazyState.js";
6
+ export * from "./BooleanState.js";
6
7
  export * from "./ArrayState.js";
8
+ export * from "./ObjectState.js";
7
9
  export * from "./DataState.js";
package/stream/index.js CHANGED
@@ -3,5 +3,7 @@ export * from "./LazyStream.js";
3
3
  export * from "./LastStream.js";
4
4
  export * from "./State.js";
5
5
  export * from "./LazyState.js";
6
+ export * from "./BooleanState.js";
6
7
  export * from "./ArrayState.js";
8
+ export * from "./ObjectState.js";
7
9
  export * from "./DataState.js";