@lordfokas/yrframe 0.4.1 → 0.4.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.
@@ -1,4 +1,5 @@
1
1
  import { EventBus, EventListener } from '@lordfokas/event-bus';
2
+ import { Component } from './Component.js';
2
3
  class PersistentListener extends EventListener {
3
4
  type;
4
5
  constructor(type, callback, nice) {
@@ -21,7 +22,7 @@ export class ComponentEvents {
21
22
  internals = 0;
22
23
  constructor(component) {
23
24
  this.component = component;
24
- this.owner = component.constructor.name;
25
+ this.owner = component instanceof Component ? component.constructor.name : '<' + component.tagName + '>';
25
26
  }
26
27
  isEmpty() {
27
28
  return (this.listeners.length + this.internals) === 0;
@@ -44,20 +44,14 @@ export class ComponentFactory {
44
44
  }
45
45
  /** Logic for appending children to a parent element according to the possible returns of render() */
46
46
  static appendChildren(element, ...children) {
47
- for (const child of children) {
48
- // Allow returning null from render() when there is nothing to do
49
- if (child === null)
50
- continue;
51
- // Disallow returning undefined to prevent mistakes being ignored. No-ops must explicitely return null.
52
- if (child === undefined)
47
+ element.append(...(children
48
+ .flat(5) // flatten arrays of arrays up to depth=5 (should be enough, if you have more, fuck you)
49
+ .filter(c => c !== null) // ignore nulls
50
+ .map(c => {
51
+ if (c === undefined)
53
52
  throw new Error("An element's child cannot be undefined");
54
- if (Array.isArray(child)) { // Allow returning multiple elements from render()
55
- this.appendChildren(element, child);
56
- }
57
- else {
58
- element.append(child);
59
- }
60
- }
53
+ return c; // accept anything else
54
+ })));
61
55
  }
62
56
  }
63
57
  /**
package/dist/Facade.d.ts CHANGED
@@ -2,7 +2,7 @@ import { ComponentEvents } from "./ComponentEvents.js";
2
2
  import { Attributes, Source } from "./utils.js";
3
3
  declare const evt: unique symbol;
4
4
  interface EventHost {
5
- [evt]: ComponentEvents;
5
+ [evt]: FacadeEvents;
6
6
  }
7
7
  type FacadeElement = HTMLElement & EventHost & {
8
8
  connectedCallback: Source<void>;
@@ -15,8 +15,14 @@ type FacadeElement = HTMLElement & EventHost & {
15
15
  export declare class Facade<A extends Attributes> {
16
16
  protected readonly node: FacadeElement;
17
17
  protected readonly isCustom: boolean;
18
- protected events(): ComponentEvents;
18
+ protected events(): FacadeEvents;
19
19
  constructor(tag: string, props: Partial<A>, defaults?: Partial<A>);
20
20
  content(): FacadeElement;
21
21
  }
22
+ declare class FacadeEvents extends ComponentEvents {
23
+ private connected;
24
+ constructor(component: HTMLElement);
25
+ connect(): void;
26
+ disconnect(): void;
27
+ }
22
28
  export {};
package/dist/Facade.js CHANGED
@@ -11,7 +11,7 @@ export class Facade {
11
11
  isCustom;
12
12
  events() {
13
13
  if (!this.node[evt]) { // Lazily instantiate event manager
14
- this.node[evt] = new ComponentEvents(this.node);
14
+ this.node[evt] = new FacadeEvents(this.node);
15
15
  }
16
16
  return this.node[evt];
17
17
  }
@@ -40,6 +40,24 @@ export class Facade {
40
40
  return this.node;
41
41
  }
42
42
  }
43
+ class FacadeEvents extends ComponentEvents {
44
+ connected = false;
45
+ constructor(component) {
46
+ super(component);
47
+ }
48
+ connect() {
49
+ if (this.connected)
50
+ return;
51
+ super.connect();
52
+ this.connected = true;
53
+ }
54
+ disconnect() {
55
+ if (!this.connected)
56
+ return;
57
+ super.disconnect();
58
+ this.connected = false;
59
+ }
60
+ }
43
61
  (function FacadeMutationObserver() {
44
62
  new MutationObserver((records, _mo) => {
45
63
  for (const record of records) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lordfokas/yrframe",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "A Typescript class-based WebComponents library using Material Design.",
5
5
  "main": "dist/yrframe.js",
6
6
  "scripts": {