vasille-jsx 4.2.0 → 4.3.0

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/components.js CHANGED
@@ -1,10 +1,15 @@
1
- import { ArrayModel, ArrayView, Fragment, MapModel, MapView, SetModel, SetView, SwitchedNode, userError, Watch as CoreWatch, } from "vasille";
1
+ import { ArrayModel, ArrayView, Fragment, MapModel, MapView, reportError, safe, SetModel, SetView, SwitchedNode, userError, Watch as CoreWatch, } from "vasille";
2
2
  export function Slot({ model, slot, ...options }, ctx, defaultSlot) {
3
- if (model) {
4
- model(options, ctx);
3
+ try {
4
+ if (model) {
5
+ model(options, ctx);
6
+ }
7
+ else {
8
+ (slot ?? defaultSlot)?.({}, ctx);
9
+ }
5
10
  }
6
- else {
7
- (slot ?? defaultSlot)?.({}, ctx);
11
+ catch (e) {
12
+ reportError(e);
8
13
  }
9
14
  }
10
15
  export function Switch(options, ctx) {
@@ -35,20 +40,21 @@ export function For({ of: model, slot: _slot }, ctx, defaultSlot) {
35
40
  }
36
41
  // fallback if is used external Array/Map/Set
37
42
  else {
43
+ const safeSlot = safe(slot);
38
44
  console.warn("Vasille <For of/> fallback detected. Please provide reactive data.");
39
45
  if (model instanceof Array) {
40
46
  model.forEach((value) => {
41
- slot(ctx, value, value);
47
+ safeSlot(ctx, value, value);
42
48
  });
43
49
  }
44
50
  else if (model instanceof Map) {
45
51
  model.forEach((value, key) => {
46
- slot(ctx, value, key);
52
+ safeSlot(ctx, value, key);
47
53
  });
48
54
  }
49
55
  else if (model instanceof Set) {
50
56
  model.forEach(value => {
51
- slot(ctx, value, value);
57
+ safeSlot(ctx, value, value);
52
58
  });
53
59
  }
54
60
  else {
@@ -60,7 +66,7 @@ export function Watch({ $model, slot: _slot }, ctx, defaultSlot) {
60
66
  const slot = _slot ?? defaultSlot;
61
67
  /* istanbul ignore else */
62
68
  if (slot) {
63
- ctx.create(new CoreWatch({ model: $model, slot }, ctx.runner));
69
+ ctx.create(new CoreWatch({ model: $model, slot: safe(slot) }, ctx.runner));
64
70
  }
65
71
  }
66
72
  export function Debug({ $model }, ctx) {
@@ -74,7 +80,7 @@ export function Delay({ time, slot: _slot }, ctx, defaultSlot) {
74
80
  /* istanbul ignore else */
75
81
  if (slot) {
76
82
  timer = setTimeout(() => {
77
- slot(node);
83
+ safe(slot)(node);
78
84
  timer = undefined;
79
85
  }, time);
80
86
  }
package/lib/compose.js CHANGED
@@ -12,7 +12,7 @@ export function view(renderer) {
12
12
  node.create(frag);
13
13
  try {
14
14
  const result = renderer(frag, props);
15
- if (result !== undefined && callback) {
15
+ if (result !== undefined && result !== null && callback) {
16
16
  callback(result);
17
17
  }
18
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vasille-jsx",
3
- "version": "4.2.0",
3
+ "version": "4.3.0",
4
4
  "description": "The same framework which is designed to build bulletproof frontends (JSX components)",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
@@ -44,7 +44,7 @@
44
44
  "opera 15"
45
45
  ],
46
46
  "dependencies": {
47
- "vasille": "^4.1.0"
47
+ "vasille": "^4.3.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/jest": "^30.0.0",