vasille-jsx 4.2.0 → 4.3.1

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
@@ -104,6 +104,10 @@ All of these are supported:
104
104
 
105
105
  ## Change log
106
106
 
107
+ ### 4.3.0
108
+
109
+ Add new function `safe` which make functions safe, errors are reported automatically.
110
+
107
111
  ### 4.2.0
108
112
 
109
113
  Add support for inlined conditions in JSX, binary `&&` and ternary `?:` operator.
package/lib/components.js CHANGED
@@ -1,10 +1,18 @@
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 if (slot) {
8
+ slot({}, ctx);
9
+ }
10
+ else if (defaultSlot) {
11
+ defaultSlot(ctx);
12
+ }
5
13
  }
6
- else {
7
- (slot ?? defaultSlot)?.({}, ctx);
14
+ catch (e) {
15
+ reportError(e);
8
16
  }
9
17
  }
10
18
  export function Switch(options, ctx) {
@@ -35,20 +43,21 @@ export function For({ of: model, slot: _slot }, ctx, defaultSlot) {
35
43
  }
36
44
  // fallback if is used external Array/Map/Set
37
45
  else {
46
+ const safeSlot = safe(slot);
38
47
  console.warn("Vasille <For of/> fallback detected. Please provide reactive data.");
39
48
  if (model instanceof Array) {
40
49
  model.forEach((value) => {
41
- slot(ctx, value, value);
50
+ safeSlot(ctx, value, value);
42
51
  });
43
52
  }
44
53
  else if (model instanceof Map) {
45
54
  model.forEach((value, key) => {
46
- slot(ctx, value, key);
55
+ safeSlot(ctx, value, key);
47
56
  });
48
57
  }
49
58
  else if (model instanceof Set) {
50
59
  model.forEach(value => {
51
- slot(ctx, value, value);
60
+ safeSlot(ctx, value, value);
52
61
  });
53
62
  }
54
63
  else {
@@ -60,7 +69,7 @@ export function Watch({ $model, slot: _slot }, ctx, defaultSlot) {
60
69
  const slot = _slot ?? defaultSlot;
61
70
  /* istanbul ignore else */
62
71
  if (slot) {
63
- ctx.create(new CoreWatch({ model: $model, slot }, ctx.runner));
72
+ ctx.create(new CoreWatch({ model: $model, slot: safe(slot) }, ctx.runner));
64
73
  }
65
74
  }
66
75
  export function Debug({ $model }, ctx) {
@@ -74,7 +83,7 @@ export function Delay({ time, slot: _slot }, ctx, defaultSlot) {
74
83
  /* istanbul ignore else */
75
84
  if (slot) {
76
85
  timer = setTimeout(() => {
77
- slot(node);
86
+ safe(slot)(node);
78
87
  timer = undefined;
79
88
  }, time);
80
89
  }
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.1",
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",
@@ -3,7 +3,7 @@ interface SlotOptions<Node, Element, TagOptions extends object, T extends object
3
3
  model?: (input: T, ctx: Fragment<Node, Element, TagOptions>) => void;
4
4
  slot?: (input: object, ctx: Fragment<Node, Element, TagOptions>) => void;
5
5
  }
6
- export declare function Slot<Node, Element, TagOptions extends object, T extends object = {}>({ model, slot, ...options }: SlotOptions<Node, Element, TagOptions, T> & T, ctx: Fragment<Node, Element, TagOptions>, defaultSlot?: (input: object, ctx: Fragment<Node, Element, TagOptions>) => void): void;
6
+ export declare function Slot<Node, Element, TagOptions extends object, T extends object = {}>({ model, slot, ...options }: SlotOptions<Node, Element, TagOptions, T> & T, ctx: Fragment<Node, Element, TagOptions>, defaultSlot?: (ctx: Fragment<Node, Element, TagOptions>) => void): void;
7
7
  interface SwitchOptions<Node, Element, TagOptions extends object> {
8
8
  cases: {
9
9
  $case: IValue<unknown>;