element-vir 16.0.0 → 16.0.2

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.
@@ -36,7 +36,6 @@ export declare abstract class DeclarativeElement<TagName extends CustomElementTa
36
36
  abstract readonly instanceInputs: Inputs;
37
37
  abstract assignInputs(inputs: {} extends Required<Inputs> ? never : Partial<Inputs>): void;
38
38
  abstract haveInputsBeenSet: boolean;
39
- abstract markInputsAsHavingBeenSet(): void;
40
39
  abstract readonly definition: DeclarativeElementDefinition<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, RenderOutputGeneric>;
41
40
  }
42
41
  export interface StaticDeclarativeElementProperties<TagName extends CustomElementTagName, Inputs extends PropertyInitMapBase, StateInit extends PropertyInitMapBase, EventsInit extends EventsInitMap, HostClassKeys extends BaseCssPropertyName<TagName>, CssVarKeys extends BaseCssPropertyName<TagName>, RenderOutputGeneric> {
@@ -8,9 +8,8 @@ import { defineCssVars } from 'lit-css-vars';
8
8
  import { property } from 'lit/decorators.js';
9
9
  import { DeclarativeElement, } from './declarative-element';
10
10
  import { IgnoreInputsNotBeenSetBeforeWarningSymbol, defaultDeclarativeElementDefinitionOptions, } from './definition-options';
11
- import { assign } from './directives/assign.directive';
12
11
  import { hasDeclarativeElementParent } from './has-declarative-element-parent';
13
- import { assignInputs, markInputsAsHavingBeenSet } from './properties/assign-inputs';
12
+ import { assignInputs } from './properties/assign-inputs';
14
13
  import { assertValidCssProperties } from './properties/css-properties';
15
14
  import { createEventDescriptorMap } from './properties/element-events';
16
15
  import { createElementUpdaterProxy } from './properties/element-updater-proxy';
@@ -66,9 +65,6 @@ export function defineElementNoInputs(initInput) {
66
65
  static get stateType() {
67
66
  throw new Error(`"stateType" was called on ${initInput.tagName} as a value but it is only for types.`);
68
67
  }
69
- markInputsAsHavingBeenSet() {
70
- markInputsAsHavingBeenSet(this);
71
- }
72
68
  render() {
73
69
  try {
74
70
  if (
@@ -77,7 +73,7 @@ export function defineElementNoInputs(initInput) {
77
73
  hasDeclarativeElementParent(this) &&
78
74
  !this.haveInputsBeenSet &&
79
75
  !elementOptions[IgnoreInputsNotBeenSetBeforeWarningSymbol]) {
80
- console.warn(this, `${initInput.tagName} got rendered before its input object was set. This was most likely caused by forgetting to use the "${assign.name}" directive on it. If no inputs are intended, use "${defineElementNoInputs.name}" to define ${initInput.tagName}.`);
76
+ console.warn(this, `${initInput.tagName} got rendered before its input object was set. This was most likely caused by forgetting to use '.assign()' on its opening tag. If no inputs are intended, use '${defineElementNoInputs.name}' to define ${initInput.tagName}.`);
81
77
  }
82
78
  this.hasRendered = true;
83
79
  const renderParams = this.createRenderParams();
@@ -9,8 +9,13 @@ export type ObservablePropertyWithSetter<ValueType> = ObservableProperty<ValueTy
9
9
  */
10
10
  export declare function createObservablePropertyWithSetter<ValueType>(initValue: ValueType, equalityCallback?: typeof referenceEqualityCheck): ObservablePropertyWithSetter<ValueType>;
11
11
  export type UpdaterCallback<ValueType, UpdateInputType> = Exclude<UpdateInputType, undefined> extends never ? () => ValueType : (inputs: UpdateInputType) => ValueType;
12
- export type ObservablePropertyWithUpdaterCallback<ValueType, UpdateInputType> = ObservableProperty<ValueType> & {
12
+ export type ObservablePropertyWithUpdaterCallback<ValueType, UpdateInputType> = ObservableProperty<ValueType | Awaited<ValueType>> & {
13
13
  triggerUpdate: UpdaterCallback<ValueType, UpdateInputType>;
14
+ /**
15
+ * The last value that was resolved. This will be undefined if there has never, so far, been a
16
+ * resolved value.
17
+ */
18
+ latestResolvedValue: ValueType extends Promise<any> ? Awaited<ValueType> | undefined : ValueType;
14
19
  };
15
20
  export type ObservablePropertyWithUpdaterSetup<ValueType, UpdateInputType> = {
16
21
  initInput: UpdateInputType;
@@ -22,11 +27,11 @@ export type ObservablePropertyWithIntervalSetup<ValueType, UpdateInputType> = Ob
22
27
  /** Interval duration in Milliseconds. */
23
28
  intervalMs: number;
24
29
  };
25
- export type ObservablePropertyWithInterval<ValueType, UpdateInputType> = ObservableProperty<ValueType> & {
30
+ export type ObservablePropertyWithInterval<ValueType, UpdateInputType> = Omit<ObservablePropertyWithUpdaterCallback<ValueType, UpdateInputType>, 'triggerUpdate'> & {
26
31
  forceUpdate: UpdaterCallback<ValueType, UpdateInputType>;
27
32
  /**
28
- * Pauses the update interval, if it isn't already paused. Use .resumeInterval() to start
29
- * the interval again. Under the hood, this actually clears the interval entirely.
33
+ * Pauses the update interval, if it isn't already paused. Use .resumeInterval() to start the
34
+ * interval again. Under the hood, this actually clears the interval entirely.
30
35
  */
31
36
  pauseInterval(): void;
32
37
  /**
@@ -31,13 +31,15 @@ export function createObservablePropertyWithSetter(initValue, equalityCallback =
31
31
  }
32
32
  export function createObservablePropertyWithUpdater(setup) {
33
33
  const areEqual = setup.equalityCallback ?? referenceEqualityCheck;
34
- const innerSimpleObservableProperty = createObservablePropertyWithSetter(setup.updateCallback(setup.initInput), areEqual);
34
+ const innerSimpleObservableProperty = createObservablePropertyWithSetter(undefined, areEqual);
35
35
  function updateValue(inputs) {
36
36
  const newValue = setup.updateCallback(inputs);
37
37
  if (newValue instanceof Promise) {
38
- return new Promise(async (resolve, reject) => {
38
+ const wrappedPromise = new Promise(async (resolve, reject) => {
39
39
  try {
40
40
  const resolvedValue = await newValue;
41
+ observableWithUpdater.latestResolvedValue =
42
+ resolvedValue;
41
43
  innerSimpleObservableProperty.setValue(resolvedValue);
42
44
  resolve(resolvedValue);
43
45
  }
@@ -45,15 +47,22 @@ export function createObservablePropertyWithUpdater(setup) {
45
47
  reject(error);
46
48
  }
47
49
  });
50
+ /** Set the promise so consumers know it's loading. */
51
+ innerSimpleObservableProperty.setValue(wrappedPromise);
52
+ return wrappedPromise;
48
53
  }
49
54
  else {
50
55
  innerSimpleObservableProperty.setValue(newValue);
56
+ observableWithUpdater.latestResolvedValue =
57
+ newValue;
51
58
  return newValue;
52
59
  }
53
60
  }
54
61
  const observableWithUpdater = Object.assign(innerSimpleObservableProperty, {
55
62
  triggerUpdate: updateValue,
63
+ latestResolvedValue: undefined,
56
64
  });
65
+ updateValue(setup.initInput);
57
66
  return observableWithUpdater;
58
67
  }
59
68
  export function createObservablePropertyWithIntervalUpdate(setup) {
@@ -30,9 +30,7 @@ function transformHtml(...[lastNewString, currentLitString, rawCurrentValue,]) {
30
30
  ? extraValueCurrentValue.inputs
31
31
  : undefined;
32
32
  return [
33
- isOpeningTag && assignedInputs && Object.values(assignedInputs).length
34
- ? assign(assignedInputs)
35
- : undefined,
33
+ isOpeningTag && assignedInputs ? assign(assignedInputs) : undefined,
36
34
  ].filter(isTruthy);
37
35
  },
38
36
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "element-vir",
3
- "version": "16.0.0",
3
+ "version": "16.0.2",
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.5.0",
43
- "@augment-vir/common": "^15.5.0",
42
+ "@augment-vir/browser": "^16.0.0",
43
+ "@augment-vir/common": "^16.0.0",
44
44
  "lit": "2.7.6",
45
45
  "lit-css-vars": "^2.0.3",
46
46
  "object-shape-tester": "^0.4.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@augment-vir/browser-testing": "^15.5.0",
50
- "@augment-vir/node-js": "^15.5.0",
49
+ "@augment-vir/browser-testing": "^16.0.0",
50
+ "@augment-vir/node-js": "^16.0.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,11 +60,11 @@
60
60
  "ansi-colors": "^4.1.3",
61
61
  "concurrently": "^8.2.0",
62
62
  "cspell": "^6.31.2",
63
- "esbuild": "^0.18.16",
63
+ "esbuild": "^0.18.17",
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",
67
- "npm-check-updates": "^16.10.16",
67
+ "npm-check-updates": "^16.10.17",
68
68
  "nyc": "^15.1.0",
69
69
  "prettier": "^2.8.8",
70
70
  "prettier-plugin-interpolated-html-tags": "^0.0.4",
@@ -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.5",
80
+ "virmator": "^7.3.0",
81
81
  "vite": "^4.4.7",
82
82
  "vite-tsconfig-paths": "^4.2.0"
83
83
  },