element-vir 12.4.5 → 12.4.6
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.
|
@@ -2,22 +2,32 @@ import { getObjectTypedKeys } from '@augment-vir/common';
|
|
|
2
2
|
import { property } from 'lit/decorators.js';
|
|
3
3
|
export function assignInputs(element, inputs) {
|
|
4
4
|
const instanceState = element.instanceState;
|
|
5
|
-
getObjectTypedKeys(inputs).forEach((
|
|
6
|
-
if (instanceState &&
|
|
7
|
-
throw new Error(`Cannot set input '${
|
|
5
|
+
getObjectTypedKeys(inputs).forEach((newInputKey) => {
|
|
6
|
+
if (instanceState && newInputKey in instanceState) {
|
|
7
|
+
throw new Error(`Cannot set input '${newInputKey}' on '${element.tagName}'. '${element.tagName}' already has a state property with the same name.`);
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* No need to check if it's already a property or not, as the property function already
|
|
11
11
|
* makes that check.
|
|
12
12
|
*/
|
|
13
|
-
property()(element,
|
|
13
|
+
property()(element, newInputKey);
|
|
14
14
|
if ('instanceInputs' in element) {
|
|
15
|
-
element.instanceInputs[
|
|
15
|
+
element.instanceInputs[newInputKey] =
|
|
16
|
+
inputs[newInputKey];
|
|
16
17
|
}
|
|
17
18
|
else {
|
|
18
|
-
element[
|
|
19
|
+
element[newInputKey] = inputs[newInputKey];
|
|
19
20
|
}
|
|
20
21
|
});
|
|
22
|
+
/** Wipe out all inputs that weren't set to undefined (as expected) */
|
|
23
|
+
if ('instanceInputs' in element) {
|
|
24
|
+
getObjectTypedKeys(element.instanceInputs).forEach((existingKey) => {
|
|
25
|
+
if (!(existingKey in inputs)) {
|
|
26
|
+
element.instanceInputs[existingKey] =
|
|
27
|
+
undefined;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
21
31
|
markInputsAsHavingBeenSet(element);
|
|
22
32
|
}
|
|
23
33
|
export function markInputsAsHavingBeenSet(element) {
|