shelving 1.191.1 → 1.192.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 +1 -1
- package/react/useStore.js +1 -2
- package/schema/AddressSchema.d.ts +3 -1
- package/schema/AddressSchema.js +2 -1
- package/store/Store.d.ts +4 -0
- package/store/Store.js +6 -0
package/package.json
CHANGED
package/react/useStore.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useSyncExternalStore } from "react";
|
|
2
|
-
import { NONE } from "../util/constants.js";
|
|
3
2
|
import { BLACKHOLE } from "../util/function.js";
|
|
4
3
|
import { runSequence } from "../util/sequence.js";
|
|
5
4
|
import { useProps } from "./useProps.js";
|
|
@@ -9,7 +8,7 @@ export function useStore(store) {
|
|
|
9
8
|
// Update `internals` if `store` changes.
|
|
10
9
|
if (store !== internals.store || !internals.subscribe || !internals.getSnapshot) {
|
|
11
10
|
internals.subscribe = onStoreChange => (store ? runSequence(store, onStoreChange, onStoreChange) : BLACKHOLE);
|
|
12
|
-
internals.getSnapshot = () =>
|
|
11
|
+
internals.getSnapshot = () => store?.snapshot;
|
|
13
12
|
internals.store = store;
|
|
14
13
|
}
|
|
15
14
|
useSyncExternalStore(internals.subscribe, internals.getSnapshot);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { type AddressData } from "../util/geo.js";
|
|
1
|
+
import { type AddressData, formatAddress } from "../util/geo.js";
|
|
2
2
|
import { DataSchema, type DataSchemaOptions } from "./DataSchema.js";
|
|
3
|
+
export type { AddressData };
|
|
4
|
+
export { formatAddress };
|
|
3
5
|
/** Allowed options for `AddressSchema` */
|
|
4
6
|
export interface AddressSchemaOptions extends Omit<DataSchemaOptions<AddressData>, "props"> {
|
|
5
7
|
}
|
package/schema/AddressSchema.js
CHANGED
|
@@ -3,11 +3,12 @@ import { COUNTRY } from "./CountrySchema.js";
|
|
|
3
3
|
import { DataSchema } from "./DataSchema.js";
|
|
4
4
|
import { NULLABLE } from "./NullableSchema.js";
|
|
5
5
|
import { StringSchema } from "./StringSchema.js";
|
|
6
|
+
export { formatAddress };
|
|
6
7
|
const ADDRESS_PROPS = {
|
|
7
8
|
address1: new StringSchema({ title: "Address 1", max: 60, min: 1 }),
|
|
8
9
|
address2: new StringSchema({ title: "Address 2", max: 60, min: 0 }),
|
|
9
10
|
city: new StringSchema({ title: "City", min: 1, max: 60 }),
|
|
10
|
-
state: new StringSchema({ title: "State", min:
|
|
11
|
+
state: new StringSchema({ title: "State", min: 0, max: 60 }),
|
|
11
12
|
postcode: new StringSchema({ title: "Postcode", min: 1, max: 12, case: "upper" }),
|
|
12
13
|
country: COUNTRY,
|
|
13
14
|
};
|
package/store/Store.d.ts
CHANGED
|
@@ -34,6 +34,10 @@ export type StoreReducer<I, O, A extends Arguments = []> = (value: O, ...args: A
|
|
|
34
34
|
export declare class Store<T, TT = T> implements AsyncIterable<T, void, void>, AsyncDisposable {
|
|
35
35
|
/** Deferred sequence this store uses to issue values as they change. */
|
|
36
36
|
readonly next: DeferredSequence<T, void, void>;
|
|
37
|
+
/**
|
|
38
|
+
* Snapshot returns either the current reason or the current value (or `NONE` if reason is unset).
|
|
39
|
+
*/
|
|
40
|
+
get snapshot(): unknown;
|
|
37
41
|
/**
|
|
38
42
|
* Store is considered to be "loading" if it has no value or error.
|
|
39
43
|
* - Calling `this.value` will throw `this.reason` if there's an error reason set, or a `Promise` if there's no value set.
|
package/store/Store.js
CHANGED
|
@@ -26,6 +26,12 @@ import { getStarter } from "../util/start.js";
|
|
|
26
26
|
export class Store {
|
|
27
27
|
/** Deferred sequence this store uses to issue values as they change. */
|
|
28
28
|
next = new DeferredSequence();
|
|
29
|
+
/**
|
|
30
|
+
* Snapshot returns either the current reason or the current value (or `NONE` if reason is unset).
|
|
31
|
+
*/
|
|
32
|
+
get snapshot() {
|
|
33
|
+
return this._reason !== undefined ? this._reason : this._value;
|
|
34
|
+
}
|
|
29
35
|
/**
|
|
30
36
|
* Store is considered to be "loading" if it has no value or error.
|
|
31
37
|
* - Calling `this.value` will throw `this.reason` if there's an error reason set, or a `Promise` if there's no value set.
|