element-vir 13.0.2 → 13.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
|
@@ -517,7 +517,7 @@ The following custom [`lit` directives](https://lit.dev/docs/templates/custom-di
|
|
|
517
517
|
|
|
518
518
|
All [built-in `lit` directives](https://lit.dev/docs/templates/directives/) are also exported by `element-vir`.
|
|
519
519
|
|
|
520
|
-
### onDomCreated
|
|
520
|
+
### `onDomCreated`
|
|
521
521
|
|
|
522
522
|
This triggers only once when the element it's attached to has actually been created in the DOM. If the attached element changes, the callback will be triggered again.
|
|
523
523
|
|
|
@@ -543,7 +543,7 @@ export const MyWithOnDomCreated = defineElementNoInputs({
|
|
|
543
543
|
});
|
|
544
544
|
```
|
|
545
545
|
|
|
546
|
-
### onResize
|
|
546
|
+
### `onResize`
|
|
547
547
|
|
|
548
548
|
This directive fires its callback whenever the element it's attached to resizes. The callback is passed an object with a portion of the [`ResizeObserverEntry`](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry) properties.
|
|
549
549
|
|
|
@@ -570,15 +570,15 @@ export const MyWithOnResize = defineElementNoInputs({
|
|
|
570
570
|
});
|
|
571
571
|
```
|
|
572
572
|
|
|
573
|
-
### assign
|
|
573
|
+
### `assign`
|
|
574
574
|
|
|
575
575
|
Assign a value to one of a custom element's properties. This is explained in the **Assigning to inputs** section earlier.
|
|
576
576
|
|
|
577
|
-
### listen
|
|
577
|
+
### `listen`
|
|
578
578
|
|
|
579
579
|
Listen to a specific event. This is explained in the **Listening to element events (outputs)** section earlier.
|
|
580
580
|
|
|
581
|
-
### assignWithCleanup
|
|
581
|
+
### `assignWithCleanup`
|
|
582
582
|
|
|
583
583
|
This directive is the same as the `assign` directive but it accepts an additional `cleanupCallback` input. Use this directive to assign values which need some kind of cleanup when they're overwritten. For example, a 3D rendering engine which uses the canvas that should free up memory when it's swapped out.
|
|
584
584
|
|
|
@@ -613,7 +613,7 @@ export const MyWithCleanup = defineElementNoInputs({
|
|
|
613
613
|
});
|
|
614
614
|
```
|
|
615
615
|
|
|
616
|
-
### renderIf
|
|
616
|
+
### `renderIf`
|
|
617
617
|
|
|
618
618
|
Use the `renderIf` directive to easily render a template if a given condition is true.
|
|
619
619
|
|
|
@@ -637,9 +637,9 @@ export const MyWithRenderIf = defineElement<{shouldRender: boolean}>()({
|
|
|
637
637
|
});
|
|
638
638
|
```
|
|
639
639
|
|
|
640
|
-
###
|
|
640
|
+
### `asyncProp`
|
|
641
641
|
|
|
642
|
-
Use
|
|
642
|
+
Use `renderAsyncProp` or `isRenderReady` in conjunction with `asyncProp` to seamlessly render and update element state based on async values:
|
|
643
643
|
|
|
644
644
|
<!-- example-link: src/readme-examples/my-with-async-prop.element.ts -->
|
|
645
645
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UnPromise } from '@augment-vir/common';
|
|
2
2
|
import { AsyncProp } from './async-prop';
|
|
3
|
-
export declare function renderAsync<T, FallbackResult, ResolutionRenderResult = never, ErrorRenderResult = never>(
|
|
4
|
-
export declare function renderAsync<T, FallbackResult, ResolutionRenderResult = never, ErrorRenderResult = never>(
|
|
5
|
-
export declare function renderAsync<T, FallbackResult, ResolutionRenderResult = never, ErrorRenderResult = never>(
|
|
6
|
-
export declare function renderAsync<T, FallbackResult, ResolutionRenderResult = never, ErrorRenderResult = never>(
|
|
3
|
+
export declare function renderAsync<T, FallbackResult, ResolutionRenderResult = never, ErrorRenderResult = never>(asyncProp: AsyncProp<T>, fallback: FallbackResult, resolutionRender: (resolved: UnPromise<T>) => ResolutionRenderResult, errorRender: (error: Error) => ErrorRenderResult): FallbackResult | ResolutionRenderResult | ErrorRenderResult;
|
|
4
|
+
export declare function renderAsync<T, FallbackResult, ResolutionRenderResult = never, ErrorRenderResult = never>(asyncProp: AsyncProp<T>, fallback: FallbackResult, resolutionRender: (resolved: UnPromise<T>) => ResolutionRenderResult, errorRender?: undefined): FallbackResult | ResolutionRenderResult | string;
|
|
5
|
+
export declare function renderAsync<T, FallbackResult, ResolutionRenderResult = never, ErrorRenderResult = never>(asyncProp: AsyncProp<T>, fallback: FallbackResult, resolutionRender: undefined, errorRender: (error: Error) => ErrorRenderResult): FallbackResult | UnPromise<T> | ErrorRenderResult;
|
|
6
|
+
export declare function renderAsync<T, FallbackResult, ResolutionRenderResult = never, ErrorRenderResult = never>(asyncProp: AsyncProp<T>, fallback: FallbackResult, resolutionRender?: undefined, errorRender?: undefined): FallbackResult | UnPromise<T> | string;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { extractErrorMessage, isPromiseLike } from '@augment-vir/common';
|
|
2
2
|
// full function type
|
|
3
|
-
export function renderAsync(
|
|
3
|
+
export function renderAsync(asyncProp,
|
|
4
4
|
/** This value will be rendered if the async prop has not settled yet. */
|
|
5
5
|
fallback, resolutionRender, errorRender) {
|
|
6
|
-
if (
|
|
6
|
+
if (asyncProp instanceof Error) {
|
|
7
7
|
const errorResult = errorRender
|
|
8
|
-
? errorRender(
|
|
9
|
-
: extractErrorMessage(
|
|
8
|
+
? errorRender(asyncProp)
|
|
9
|
+
: extractErrorMessage(asyncProp);
|
|
10
10
|
return errorResult;
|
|
11
11
|
}
|
|
12
|
-
else if (isPromiseLike(
|
|
12
|
+
else if (isPromiseLike(asyncProp)) {
|
|
13
13
|
const fallbackResult = fallback;
|
|
14
14
|
return fallbackResult;
|
|
15
15
|
}
|
|
16
16
|
else {
|
|
17
17
|
const resolutionResult = resolutionRender
|
|
18
|
-
? resolutionRender(
|
|
19
|
-
:
|
|
18
|
+
? resolutionRender(asyncProp)
|
|
19
|
+
: asyncProp;
|
|
20
20
|
return resolutionResult;
|
|
21
21
|
}
|
|
22
22
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "element-vir",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.3",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"custom",
|
|
6
6
|
"web",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"publish": "virmator publish \"npm run compile && npm run test:all\"",
|
|
32
32
|
"start": "npm install && virmator frontend",
|
|
33
33
|
"test": "virmator test-web",
|
|
34
|
-
"test:all": "concurrently -c auto --kill-others-on-fail --colors \"npm run test:types\" \"npm run test:coverage\" \"npm run test:spelling\" \"npm run test:format\" \"npm run test:docs\"",
|
|
34
|
+
"test:all": "concurrently -c auto --kill-others-on-fail --colors --names types,tests,spelling,format,docs \"npm run test:types\" \"npm run test:coverage\" \"npm run test:spelling\" \"npm run test:format\" \"npm run test:docs\"",
|
|
35
35
|
"test:coverage": "virmator test-web coverage",
|
|
36
36
|
"test:docs": "virmator code-in-markdown check",
|
|
37
37
|
"test:format": "virmator format check",
|