shelving 1.89.6 → 1.90.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.89.6",
14
+ "version": "1.90.0",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -1,21 +1,33 @@
1
- import { Data, OptionalData } from "../util/data.js";
2
- import { Transformers } from "../util/transform.js";
1
+ import { Data, DataKey } from "../util/data.js";
2
+ import { Transformers, Transformer } from "../util/transform.js";
3
3
  import { State } from "./State.js";
4
4
  /** State that stores a data object and has additional methods to help with that. */
5
5
  export declare class DataState<T extends Data> extends State<T> {
6
6
  /** Get the data value of this state. */
7
7
  get data(): T;
8
+ /** Update a single named prop in this data. */
9
+ getProp<K extends DataKey<T>>(name: K): T[K];
10
+ /** Update a single named prop in this data. */
11
+ setProp<K extends DataKey<T>>(name: K, value: T[K]): void;
12
+ /** Update a single named prop in this data. */
13
+ updateProp<K extends DataKey<T>>(name: K, update: Transformer<T[K], T[K]>): void;
8
14
  /** Update several props in this data. */
9
15
  update(updates: Transformers<T>): void;
10
16
  }
11
17
  /** State that stores an optional data object and has additional methods to help with that. */
12
- export declare class OptionalDataState<T extends Data> extends State<OptionalData<T>> {
18
+ export declare class OptionalDataState<T extends Data> extends State<T | null> {
13
19
  /** Get current data value of this state (or throw `Promise` that resolves to the next required value). */
14
20
  get data(): T;
15
21
  /** Does the data exist or not? */
16
22
  get exists(): boolean;
17
23
  /** Update several props in this data. */
18
24
  update(updates: Transformers<T>): void;
25
+ /** Update a single named prop in this data. */
26
+ getProp<K extends DataKey<T>>(name: K): T[K];
27
+ /** Update a single named prop in this data. */
28
+ setProp<K extends DataKey<T>>(name: K, value: T[K]): void;
29
+ /** Update a single named prop in this data. */
30
+ updateProp<K extends DataKey<T>>(name: K, update: Transformer<T[K], T[K]>): void;
19
31
  /** Set the data to `null`. */
20
32
  unset(): void;
21
33
  }
@@ -1,5 +1,6 @@
1
+ import { withProp } from "../util/object.js";
1
2
  import { getData } from "../util/data.js";
2
- import { transformObject } from "../util/transform.js";
3
+ import { transform, transformObject } from "../util/transform.js";
3
4
  import { State } from "./State.js";
4
5
  /** State that stores a data object and has additional methods to help with that. */
5
6
  export class DataState extends State {
@@ -7,6 +8,19 @@ export class DataState extends State {
7
8
  get data() {
8
9
  return this.value;
9
10
  }
11
+ /** Update a single named prop in this data. */
12
+ getProp(name) {
13
+ return this.data[name];
14
+ }
15
+ /** Update a single named prop in this data. */
16
+ setProp(name, value) {
17
+ this.set(withProp(this.data, name, value));
18
+ }
19
+ /** Update a single named prop in this data. */
20
+ updateProp(name, update) {
21
+ const data = this.data;
22
+ this.set(withProp(data, name, transform(data[name], update)));
23
+ }
10
24
  /** Update several props in this data. */
11
25
  update(updates) {
12
26
  this.set(transformObject(this.data, updates));
@@ -26,6 +40,19 @@ export class OptionalDataState extends State {
26
40
  update(updates) {
27
41
  this.set(transformObject(this.data, updates));
28
42
  }
43
+ /** Update a single named prop in this data. */
44
+ getProp(name) {
45
+ return this.data[name];
46
+ }
47
+ /** Update a single named prop in this data. */
48
+ setProp(name, value) {
49
+ this.set(withProp(this.data, name, value));
50
+ }
51
+ /** Update a single named prop in this data. */
52
+ updateProp(name, update) {
53
+ const data = this.data;
54
+ this.set(withProp(data, name, transform(data[name], update)));
55
+ }
29
56
  /** Set the data to `null`. */
30
57
  unset() {
31
58
  this.set(null);
@@ -1,5 +1,5 @@
1
1
  import { DictionaryItem, ImmutableDictionary } from "../util/dictionary.js";
2
- import { Transformers } from "../util/transform.js";
2
+ import { Transformer, Transformers } from "../util/transform.js";
3
3
  import { State } from "./State.js";
4
4
  /** State that stores a dictionary object and has additional methods to help with that. */
5
5
  export declare class DictionaryState<T> extends State<ImmutableDictionary<T>> implements Iterable<DictionaryItem<T>> {
@@ -10,6 +10,12 @@ export declare class DictionaryState<T> extends State<ImmutableDictionary<T>> im
10
10
  update(updates: Transformers<ImmutableDictionary<T>>): void;
11
11
  /** Remove a named entry from this object. */
12
12
  delete(...keys: string[]): void;
13
+ /** Update a single named prop in this data. */
14
+ getItem(name: string): T | undefined;
15
+ /** Update a single named prop in this data. */
16
+ setItem(name: string, value: T): void;
17
+ /** Update a single named prop in this data. */
18
+ updateItem(name: string, update: Transformer<T | undefined, T>): void;
13
19
  /** Iterate over the entries of the object. */
14
20
  [Symbol.iterator](): Iterator<DictionaryItem<T>>;
15
21
  }
@@ -1,5 +1,6 @@
1
+ import { withProp } from "../util/object.js";
1
2
  import { omitDictionaryItems } from "../util/dictionary.js";
2
- import { transformDictionary } from "../util/transform.js";
3
+ import { transform, transformDictionary } from "../util/transform.js";
3
4
  import { State } from "./State.js";
4
5
  /** State that stores a dictionary object and has additional methods to help with that. */
5
6
  export class DictionaryState extends State {
@@ -18,6 +19,19 @@ export class DictionaryState extends State {
18
19
  delete(...keys) {
19
20
  this.set(omitDictionaryItems(this.value, ...keys));
20
21
  }
22
+ /** Update a single named prop in this data. */
23
+ getItem(name) {
24
+ return this.value[name];
25
+ }
26
+ /** Update a single named prop in this data. */
27
+ setItem(name, value) {
28
+ this.set(withProp(this.value, name, value));
29
+ }
30
+ /** Update a single named prop in this data. */
31
+ updateItem(name, update) {
32
+ const value = this.value;
33
+ this.set(withProp(value, name, transform(value[name], update)));
34
+ }
21
35
  /** Iterate over the entries of the object. */
22
36
  [Symbol.iterator]() {
23
37
  return Object.entries(this.value)[Symbol.iterator]();