Skip to content

Commit cec5ca2

Browse files
committed
more functionality with renderer tag
1 parent b73a63d commit cec5ca2

File tree

6 files changed

+337
-94
lines changed

6 files changed

+337
-94
lines changed

package-lock.json

Lines changed: 52 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@default-js/defaultjs-html-components",
33
"buildname": "defaultjs-html-components",
4-
"version": "1.2.4",
4+
"version": "1.3.4",
55
"description": "Useful web components",
66
"main": "./index.js",
77
"scripts": {

src/Component.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { defValue } from "@default-js/defaultjs-common-utils/src/ObjectUtils";
1+
import {privateProperty } from "@default-js/defaultjs-common-utils/src/PrivateProperty";
22
import { lazyPromise } from "@default-js/defaultjs-common-utils/src/PromiseUtils";
33
import { uuid } from "@default-js/defaultjs-common-utils/src/UUID";
44
import { initTimeout, triggerTimeout } from "./Constants";
55
import { attributeChangeEventname, componentEventname } from "./utils/EventHelper";
66
import WeakData from "./utils/WeakData";
77

8+
const PRIVATE_READY = "ready";
9+
810
const TIMEOUTS = new WeakData();
911
const init = (component) => {
1012
const data = TIMEOUTS.data(component);
@@ -37,7 +39,7 @@ export const createUID = (prefix, suffix) => {
3739
class Component extends HTMLElement {
3840
constructor({shadowRoot = false, content = null, createUID = false, uidPrefix = "id-", uidSuffix = ""} = {}) {
3941
super();
40-
defValue(this, "ready", lazyPromise());
42+
privateProperty(this, PRIVATE_READY, lazyPromise());
4143

4244
if(createUID)
4345
this.attr("id", createUID(uidPrefix, uidSuffix));
@@ -53,8 +55,17 @@ class Component extends HTMLElement {
5355
return this.shadowRoot || this;
5456
}
5557

58+
get ready(){
59+
return privateProperty(this, PRIVATE_READY);
60+
}
61+
5662
async init() {}
5763

64+
async destroy() {
65+
if(this.ready.resolved)
66+
privateProperty(this, PRIVATE_READY, lazyPromise());
67+
}
68+
5869
connectedCallback() {
5970
if (this.ownerDocument == document) init(this);
6071
}
@@ -69,6 +80,10 @@ class Component extends HTMLElement {
6980
this.trigger(triggerTimeout, componentEventname("change", this));
7081
}
7182
}
83+
84+
disconnectedCallback(){
85+
this.destroy();
86+
}
7287
}
7388

7489
export default Component;

0 commit comments

Comments
 (0)