element-vir 14.1.0 → 14.2.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.
@@ -4,7 +4,7 @@ import { ObservablePropertyHandlerCreator, ObservablePropertyHandlerInstance, ob
4
4
  export type AsyncProp<ValueGeneric> = Error | UnPromise<ValueGeneric> | Promise<UnPromise<ValueGeneric>>;
5
5
  declare const notSetSymbol: unique symbol;
6
6
  export type AsyncPropTriggerInputBase = object | undefined;
7
- type AllSetValueProperties<ValueGeneric, TriggerInput extends AsyncPropTriggerInputBase> = {
7
+ type AllSetValueProperties<ValueGeneric, TriggerInput extends AsyncPropTriggerInputBase, UpdaterInput> = {
8
8
  /** Set a new value directly without using any promises. */
9
9
  resolvedValue: UnPromise<ValueGeneric>;
10
10
  /**
@@ -14,12 +14,18 @@ type AllSetValueProperties<ValueGeneric, TriggerInput extends AsyncPropTriggerIn
14
14
  * used for equality checking.
15
15
  */
16
16
  serializableTrigger: TriggerInput;
17
+ /**
18
+ * These values are passed to the asyncProp's updateCallback but they will not used to trigger
19
+ * updates. Meaning, if one of these values changes, the asyncProp will not update. Use
20
+ * serializableTrigger for that purpose.
21
+ */
22
+ updaterInputs: UpdaterInput;
17
23
  newPromise: Promise<UnPromise<ValueGeneric>>;
18
24
  /** Clear the asyncProp's currently stored value and trigger updateCallback to get called again. */
19
25
  forceUpdate: true;
20
26
  };
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'>;
22
- export declare class AsyncObservablePropertyHandler<ValueGeneric, TriggerInput extends AsyncPropTriggerInputBase> implements ObservablePropertyHandlerInstance<AsyncPropSetValue<ValueGeneric, TriggerInput>, AsyncProp<ValueGeneric>> {
27
+ export type AsyncPropSetValue<ValueGeneric, TriggerInput extends AsyncPropTriggerInputBase, UpdaterInput> = (undefined extends TriggerInput ? undefined extends UpdaterInput ? never : PickAndBlockOthers<AllSetValueProperties<ValueGeneric, TriggerInput, UpdaterInput>, 'updaterInputs'> : undefined extends UpdaterInput ? PickAndBlockOthers<AllSetValueProperties<ValueGeneric, TriggerInput, UpdaterInput>, 'serializableTrigger'> : PickAndBlockOthers<AllSetValueProperties<ValueGeneric, TriggerInput, UpdaterInput>, 'serializableTrigger' | 'updaterInputs'>) | PickAndBlockOthers<AllSetValueProperties<ValueGeneric, TriggerInput, UpdaterInput>, 'newPromise'> | PickAndBlockOthers<AllSetValueProperties<ValueGeneric, TriggerInput, UpdaterInput>, 'forceUpdate'> | PickAndBlockOthers<AllSetValueProperties<ValueGeneric, TriggerInput, UpdaterInput>, 'resolvedValue'>;
28
+ export declare class AsyncObservablePropertyHandler<ValueGeneric, TriggerInput extends AsyncPropTriggerInputBase, UpdaterInput> implements ObservablePropertyHandlerInstance<AsyncPropSetValue<ValueGeneric, TriggerInput, UpdaterInput>, AsyncProp<ValueGeneric>> {
23
29
  private lastTrigger;
24
30
  private resolutionValue;
25
31
  private rejectionError;
@@ -27,14 +33,14 @@ export declare class AsyncObservablePropertyHandler<ValueGeneric, TriggerInput e
27
33
  private lastSetPromise;
28
34
  private waitingForValuePromise;
29
35
  [observablePropertyHandlerInstanceMarkerKey]: true;
30
- constructor(initialValue: AsyncPropInit<ValueGeneric, TriggerInput> | typeof notSetSymbol);
36
+ constructor(initialValue: AsyncPropInit<ValueGeneric, TriggerInput, UpdaterInput> | typeof notSetSymbol);
31
37
  private promiseUpdater;
32
- resetValue(rawValue: AsyncPropInit<ValueGeneric, TriggerInput> | typeof notSetSymbol): void;
38
+ resetValue(rawValue: AsyncPropInit<ValueGeneric, TriggerInput, UpdaterInput> | typeof notSetSymbol): void;
33
39
  private fireListeners;
34
40
  private setPromise;
35
41
  private resolveValue;
36
42
  private resetWaitingForValuePromise;
37
- setValue(setInputs: AsyncPropSetValue<ValueGeneric, TriggerInput>): void;
43
+ setValue(setInputs: AsyncPropSetValue<ValueGeneric, TriggerInput, UpdaterInput>): void;
38
44
  getValue(): AsyncProp<ValueGeneric>;
39
45
  addListener(fireImmediately: boolean, listener: ObservablePropertyListener<AsyncProp<ValueGeneric>>): void;
40
46
  addMultipleListeners(listeners: ReadonlySet<ObservablePropertyListener<AsyncProp<ValueGeneric>>>): void;
@@ -42,9 +48,9 @@ export declare class AsyncObservablePropertyHandler<ValueGeneric, TriggerInput e
42
48
  removeListener(listener: ObservablePropertyListener<AsyncProp<ValueGeneric>>): boolean;
43
49
  removeAllListeners(): number;
44
50
  }
45
- export type AsyncObservablePropertyHandlerCreator<ValueGeneric, TriggerInput extends AsyncPropTriggerInputBase> = ObservablePropertyHandlerCreator<AsyncPropSetValue<ValueGeneric, TriggerInput>, AsyncProp<ValueGeneric>>;
46
- export type AsyncPropUpdateCallback<ValueGeneric, TriggerInput extends AsyncPropTriggerInputBase> = undefined extends TriggerInput ? () => Promise<UnPromise<ValueGeneric>> : (triggerInput: TriggerInput) => Promise<UnPromise<ValueGeneric>>;
47
- export type AsyncPropInit<ValueGeneric, TriggerInput extends AsyncPropTriggerInputBase> = {
51
+ export type AsyncObservablePropertyHandlerCreator<ValueGeneric, TriggerInput extends AsyncPropTriggerInputBase, UpdaterInput> = ObservablePropertyHandlerCreator<AsyncPropSetValue<ValueGeneric, TriggerInput, UpdaterInput>, AsyncProp<ValueGeneric>>;
52
+ export type AsyncPropUpdateCallback<ValueGeneric, TriggerInput extends AsyncPropTriggerInputBase, UpdaterInput> = undefined extends TriggerInput ? () => Promise<UnPromise<ValueGeneric>> : (triggers: TriggerInput, inputs: UpdaterInput) => Promise<UnPromise<ValueGeneric>>;
53
+ export type AsyncPropInit<ValueGeneric, TriggerInput extends AsyncPropTriggerInputBase, UpdaterInput> = {
48
54
  /** Starting value */
49
55
  defaultValue: Promise<UnPromise<ValueGeneric>> | UnPromise<ValueGeneric> | ValueGeneric;
50
56
  } | {
@@ -56,7 +62,7 @@ export type AsyncPropInit<ValueGeneric, TriggerInput extends AsyncPropTriggerInp
56
62
  * Set this to undefined to disabled automatic updating. Meaning, updateCallback will only
57
63
  * be called the first time.
58
64
  */
59
- updateCallback: AsyncPropUpdateCallback<ValueGeneric, TriggerInput>;
65
+ updateCallback: AsyncPropUpdateCallback<ValueGeneric, TriggerInput, UpdaterInput>;
60
66
  };
61
- export declare function asyncProp<ValueGeneric, TriggerInput extends AsyncPropTriggerInputBase = undefined>(...args: [AsyncPropInit<ValueGeneric, TriggerInput>] | []): AsyncObservablePropertyHandlerCreator<ValueGeneric, TriggerInput>;
67
+ export declare function asyncProp<ValueGeneric, TriggerInput extends AsyncPropTriggerInputBase = undefined, UpdaterInput = undefined>(...args: [AsyncPropInit<ValueGeneric, TriggerInput, UpdaterInput>] | []): AsyncObservablePropertyHandlerCreator<ValueGeneric, TriggerInput, UpdaterInput>;
62
68
  export {};
@@ -91,7 +91,10 @@ export class AsyncObservablePropertyHandler {
91
91
  * This will expand proxies so that `inputs` or `state` can be used directly as a
92
92
  * serializableTrigger without issues.
93
93
  */
94
- const expandedTrigger = { ...setInputs.serializableTrigger };
94
+ const expandedTrigger = {
95
+ ...setInputs.serializableTrigger,
96
+ };
97
+ const expandedInputs = { ...setInputs.updaterInputs };
95
98
  if (this.lastTrigger === notSetSymbol ||
96
99
  !areJsonEqual(expandedTrigger, this.lastTrigger, {
97
100
  ignoreNonSerializableProperties: true,
@@ -100,7 +103,7 @@ export class AsyncObservablePropertyHandler {
100
103
  if (!this.promiseUpdater) {
101
104
  throw new Error(`got serializableTrigger input to updateState for asyncProp but no updateCallback has been defined.`);
102
105
  }
103
- const newValue = this.promiseUpdater(expandedTrigger);
106
+ const newValue = this.promiseUpdater(expandedTrigger, expandedInputs);
104
107
  this.setPromise(newValue);
105
108
  this.fireListeners();
106
109
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "element-vir",
3
- "version": "14.1.0",
3
+ "version": "14.2.0",
4
4
  "keywords": [
5
5
  "custom",
6
6
  "web",
@@ -39,15 +39,15 @@
39
39
  "test:types": "tsc --noEmit"
40
40
  },
41
41
  "dependencies": {
42
- "@augment-vir/browser": "^15.3.0",
43
- "@augment-vir/common": "^15.3.0",
44
- "element-vir": "^14.0.4",
42
+ "@augment-vir/browser": "^15.4.0",
43
+ "@augment-vir/common": "^15.4.0",
44
+ "element-vir": "^14.1.0",
45
45
  "lit": "2.7.6",
46
46
  "lit-css-vars": "^2.0.3"
47
47
  },
48
48
  "devDependencies": {
49
- "@augment-vir/browser-testing": "^15.3.0",
50
- "@augment-vir/node-js": "^15.3.0",
49
+ "@augment-vir/browser-testing": "^15.4.0",
50
+ "@augment-vir/node-js": "^15.4.0",
51
51
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
52
52
  "@open-wc/testing": "^3.2.0",
53
53
  "@types/chai": "^4.3.5",
@@ -60,7 +60,7 @@
60
60
  "ansi-colors": "^4.1.3",
61
61
  "concurrently": "^8.2.0",
62
62
  "cspell": "^6.31.2",
63
- "esbuild": "^0.18.13",
63
+ "esbuild": "^0.18.14",
64
64
  "istanbul-smart-text-reporter": "^1.1.2",
65
65
  "markdown-code-example-inserter": "^0.3.1",
66
66
  "mocha-spec-reporter-with-file-names": "^0.0.3",
@@ -77,7 +77,7 @@
77
77
  "ts-node": "^10.9.1",
78
78
  "type-fest": "^4.0.0",
79
79
  "typescript": "~5.1.6",
80
- "virmator": "^7.2.1",
80
+ "virmator": "^7.2.4",
81
81
  "vite": "^4.4.4",
82
82
  "vite-tsconfig-paths": "^4.2.0"
83
83
  },