@zcomponent/core 0.0.9 → 0.0.10

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/lib/behavior.d.ts CHANGED
@@ -16,7 +16,7 @@ export declare class Behavior<InstanceType extends Component = Component> {
16
16
  private _registered;
17
17
  private _zcomponent;
18
18
  constructor(contextManager: ContextManager, instance: InstanceType);
19
- getZComponentInstance<T extends ZComponent = ZComponent>(type?: ConstructorForComponent<T>): T | undefined;
19
+ getZComponentInstance<T extends ZComponent = ZComponent>(type?: ConstructorForComponent<T>): T;
20
20
  private _updateEnabledResolved;
21
21
  /**
22
22
  * @zprop
package/lib/behavior.js CHANGED
@@ -28,9 +28,13 @@ export class Behavior {
28
28
  this.register(instance.enabledResolved, this._updateEnabledResolved);
29
29
  }
30
30
  getZComponentInstance(type) {
31
+ if (this._zcomponent === undefined)
32
+ throw new Error("getZComponentInstance called in behavior that's not part of a ZComponent");
31
33
  if (!type)
32
34
  return this._zcomponent;
33
- return (type && this._zcomponent instanceof type) ? this._zcomponent : undefined;
35
+ if (this._zcomponent instanceof type)
36
+ return this._zcomponent;
37
+ throw new Error("getZComponentInstance called in behavior passing wrong kind of ZComponent");
34
38
  }
35
39
  register(e, fn) {
36
40
  if (e instanceof Event)
package/lib/component.js CHANGED
@@ -48,16 +48,25 @@ export class Component {
48
48
  constructChildren(children, contextManager) {
49
49
  contextManager = contextManager ?? this.contextManager;
50
50
  for (const [constructor, props, ref] of children) {
51
- const instance = new constructor(contextManager, props);
52
- this.appendChild(instance);
53
- if (ref)
54
- ref.value = instance;
51
+ try {
52
+ const instance = new constructor(contextManager, props);
53
+ this.appendChild(instance);
54
+ if (ref)
55
+ ref.value = instance;
56
+ }
57
+ catch (err) {
58
+ console.log('An error occurred when constructing component child of type:', constructor, err);
59
+ }
55
60
  }
56
61
  }
57
62
  getZComponentInstance(type) {
63
+ if (this._zcomponent === undefined)
64
+ throw new Error("getZComponentInstance called in component that's not part of a ZComponent");
58
65
  if (!type)
59
66
  return this._zcomponent;
60
- return (type && this._zcomponent instanceof type) ? this._zcomponent : undefined;
67
+ if (this._zcomponent instanceof type)
68
+ return this._zcomponent;
69
+ throw new Error("getZComponentInstance called in component passing wrong kind of ZComponent");
61
70
  }
62
71
  appendChild(c) {
63
72
  c.remove();
package/lib/zcomponent.js CHANGED
@@ -171,9 +171,16 @@ export class ZComponent extends Component {
171
171
  _wrapBehaviors(nodeID, impl, ctx) {
172
172
  const behaviors = this._opts.data.behaviorsByNode?.[nodeID] ?? [];
173
173
  for (const behaviorID of behaviors) {
174
- const constructor = this._constructorForBehavior(behaviorID);
175
- if (constructor)
176
- new constructor(ctx, impl);
174
+ try {
175
+ const constructor = this._constructorForBehavior(behaviorID);
176
+ if (constructor)
177
+ new constructor(ctx, impl);
178
+ }
179
+ catch (err) {
180
+ const nodeName = this._opts.data.nodes[nodeID]?.label ?? "Unknown node";
181
+ const behaviorType = this._opts.data.behaviors[behaviorID]?.type;
182
+ console.log('An error occurred when constructing behavior of type:', behaviorType, 'for node:', nodeName, err);
183
+ }
177
184
  }
178
185
  }
179
186
  notifyPropsChanged(entries) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zcomponent/core",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",