element-vir 14.0.1 → 14.0.3

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/README.md CHANGED
@@ -678,7 +678,7 @@ export const MyWithAsyncProp = defineElement<{endpoint: string}>()({
678
678
  */
679
679
  updateState({
680
680
  data: {
681
- trigger: inputs,
681
+ serializableTrigger: inputs,
682
682
  },
683
683
  });
684
684
 
@@ -1,28 +1,24 @@
1
- import { JsonCompatibleValue, UnPromise } from '@augment-vir/common';
1
+ import { UnPromise } from '@augment-vir/common';
2
2
  import { PickAndBlockOthers } from '../../augments/type';
3
3
  import { ObservablePropertyHandlerCreator, ObservablePropertyHandlerInstance, observablePropertyHandlerInstanceMarkerKey, ObservablePropertyListener } from '../properties/observable-property/observable-property-handler';
4
4
  export type AsyncProp<ValueGeneric> = Error | UnPromise<ValueGeneric> | Promise<UnPromise<ValueGeneric>>;
5
5
  declare const notSetSymbol: unique symbol;
6
- type JsonCompatibleObjectWithFunctionsAllowedAtTopLevel = Partial<{
7
- readonly [key: string | number]: JsonCompatibleValue | Readonly<JsonCompatibleValue> | ((...args: any[]) => void);
8
- }> | Partial<{
9
- [key: string | number]: JsonCompatibleValue | Readonly<JsonCompatibleValue> | ((...args: any[]) => void);
10
- }>;
11
- export type AsyncPropTriggerInputBase = JsonCompatibleObjectWithFunctionsAllowedAtTopLevel | undefined;
6
+ export type AsyncPropTriggerInputBase = object | undefined;
12
7
  type AllSetValueProperties<ValueGeneric, TriggerInput extends AsyncPropTriggerInputBase> = {
13
8
  /** Set a new value directly without using any promises. */
14
9
  resolvedValue: UnPromise<ValueGeneric>;
15
10
  /**
16
- * A value that, if it changes from one assignment to another, triggers the asyncProp to
17
- * re-evaluate itself. Must be a JSON-compatible object for quick equality checks. Functions are
18
- * also be allowed at the top level, but they are ignored for the equality checking.
11
+ * An object that, if it changes from one assignment to another, triggers the asyncProp to
12
+ * re-evaluate itself: calling its defined updateCallback and going through the asyncProp
13
+ * process again. Note that only serializable (JSON compatible) properties in this object are
14
+ * used for equality checking.
19
15
  */
20
- trigger: TriggerInput;
16
+ serializableTrigger: TriggerInput;
21
17
  newPromise: Promise<UnPromise<ValueGeneric>>;
22
- /** Clear the current value and trigger updateCallback to get called again on the next render. */
18
+ /** Clear the asyncProp's currently stored value and trigger updateCallback to get called again. */
23
19
  forceUpdate: true;
24
20
  };
25
- export type AsyncPropSetValue<ValueGeneric, TriggerInput extends AsyncPropTriggerInputBase> = (undefined extends TriggerInput ? never : PickAndBlockOthers<AllSetValueProperties<ValueGeneric, TriggerInput>, 'trigger'>) | PickAndBlockOthers<AllSetValueProperties<ValueGeneric, TriggerInput>, 'newPromise'> | PickAndBlockOthers<AllSetValueProperties<ValueGeneric, TriggerInput>, 'forceUpdate'> | PickAndBlockOthers<AllSetValueProperties<ValueGeneric, TriggerInput>, 'resolvedValue'>;
21
+ export type AsyncPropSetValue<ValueGeneric, TriggerInput extends AsyncPropTriggerInputBase> = (undefined extends TriggerInput ? never : PickAndBlockOthers<AllSetValueProperties<ValueGeneric, TriggerInput>, 'serializableTrigger'>) | PickAndBlockOthers<AllSetValueProperties<ValueGeneric, TriggerInput>, 'newPromise'> | PickAndBlockOthers<AllSetValueProperties<ValueGeneric, TriggerInput>, 'forceUpdate'> | PickAndBlockOthers<AllSetValueProperties<ValueGeneric, TriggerInput>, 'resolvedValue'>;
26
22
  export declare class AsyncObservablePropertyHandler<ValueGeneric, TriggerInput extends AsyncPropTriggerInputBase> implements ObservablePropertyHandlerInstance<AsyncPropSetValue<ValueGeneric, TriggerInput>, AsyncProp<ValueGeneric>> {
27
23
  private lastTrigger;
28
24
  private resolutionValue;
@@ -86,23 +86,21 @@ export class AsyncObservablePropertyHandler {
86
86
  this.waitingForValuePromise = createDeferredPromiseWrapper();
87
87
  }
88
88
  setValue(setInputs) {
89
- if (typedHasProperty(setInputs, 'trigger')) {
89
+ if (typedHasProperty(setInputs, 'serializableTrigger')) {
90
90
  /**
91
91
  * This will expand proxies so that `inputs` or `state` can be used directly as a
92
- * trigger without issues.
92
+ * serializableTrigger without issues.
93
93
  */
94
- const expandedNewTrigger = { ...setInputs.trigger };
94
+ const expandedTrigger = { ...setInputs.serializableTrigger };
95
95
  if (this.lastTrigger === notSetSymbol ||
96
- /**
97
- * No need to explicitly remove function properties here before the equality check:
98
- * JSON.stringify (which areJsonEqual is based on) will automatically do that.
99
- */
100
- !areJsonEqual(expandedNewTrigger, this.lastTrigger)) {
101
- this.lastTrigger = expandedNewTrigger;
96
+ !areJsonEqual(expandedTrigger, this.lastTrigger, {
97
+ ignoreNonSerializableProperties: true,
98
+ })) {
99
+ this.lastTrigger = expandedTrigger;
102
100
  if (!this.promiseUpdater) {
103
- throw new Error(`got trigger input to updateState for asyncProp but no updateCallback has been defined.`);
101
+ throw new Error(`got serializableTrigger input to updateState for asyncProp but no updateCallback has been defined.`);
104
102
  }
105
- const newValue = this.promiseUpdater(expandedNewTrigger);
103
+ const newValue = this.promiseUpdater(expandedTrigger);
106
104
  this.setPromise(newValue);
107
105
  this.fireListeners();
108
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "element-vir",
3
- "version": "14.0.1",
3
+ "version": "14.0.3",
4
4
  "keywords": [
5
5
  "custom",
6
6
  "web",
@@ -39,14 +39,14 @@
39
39
  "test:types": "tsc --noEmit"
40
40
  },
41
41
  "dependencies": {
42
- "@augment-vir/browser": "^15.1.0",
43
- "@augment-vir/common": "^15.1.0",
42
+ "@augment-vir/browser": "^15.2.0",
43
+ "@augment-vir/common": "^15.2.0",
44
44
  "lit": "2.7.5",
45
45
  "lit-css-vars": "^2.0.3"
46
46
  },
47
47
  "devDependencies": {
48
- "@augment-vir/browser-testing": "^15.1.0",
49
- "@augment-vir/node-js": "^15.1.0",
48
+ "@augment-vir/browser-testing": "^15.2.0",
49
+ "@augment-vir/node-js": "^15.2.0",
50
50
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
51
51
  "@open-wc/testing": "^3.2.0",
52
52
  "@types/chai": "^4.3.5",