vasille 4.1.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/README.md CHANGED
@@ -35,6 +35,7 @@ $ npm create vasille
35
35
  ### Full documentation:
36
36
  * [Learn `Vasille` in 5 minutes](https://github.com/vasille-js/vasille-js/blob/v4/doc/V4-API.md)
37
37
  * [Vasille Router Documentation](https://github.com/vasille-js/vasille-js/blob/v4/doc/Router-API.md)
38
+ * [Vasille Compostion function](https://github.com/vasille-js/vasille-js/blob/v4/doc/Compositions.md)
38
39
 
39
40
  ### Examples
40
41
  * [TypeScript Example](https://github.com/vasille-js/example-typescript)
@@ -97,10 +98,24 @@ All of these are supported:
97
98
  * [x] `100%` Test Coverage fot babel plugin.
98
99
  * [x] Add CSS support (define styles in components).
99
100
  * [x] Add router.
100
- * [ ] Add SSG (static site generation).
101
+ * [x] Add SSG (static site generation).
101
102
  * [ ] Add SSR (server side rendering).
102
103
  * [ ] Develop tools extension for debugging.
103
104
 
105
+ ## Change log
106
+
107
+ ### 4.2.0
108
+
109
+ Add support for inlined conditions in JSX, binary `&&` and ternary `?:` operator.
110
+
111
+ ### 4.1.0
112
+
113
+ Added SSG (static site generation) as build option `vasille-web build static`.
114
+
115
+ ### 4.0.0
116
+
117
+ Initial version of the framework with file based routing and building scripts (`vasille-web dev` and `vasille-web build spa`).
118
+
104
119
  ## Questions
105
120
 
106
121
  If you have questions, feel free to contact the maintainer of the project:
package/lib/core/core.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { safe } from "../functional/safety.js";
1
2
  /**
2
3
  * A reactive object
3
4
  * @class Reactive
@@ -13,11 +14,16 @@ export class Reactive {
13
14
  this.linked.push(value);
14
15
  }
15
16
  runOnDestroy(func) {
16
- if (this.onDestroy) {
17
- console.warn(new Error("You rewrite onDestroy existing handler"));
18
- console.log(this.onDestroy);
17
+ const existing = this.onDestroy;
18
+ if (existing) {
19
+ this.onDestroy = () => {
20
+ existing();
21
+ safe(func)();
22
+ };
23
+ }
24
+ else {
25
+ this.onDestroy = safe(func);
19
26
  }
20
- this.onDestroy = func;
21
27
  }
22
28
  destroy() {
23
29
  this.onDestroy?.();
@@ -1,7 +1,23 @@
1
1
  export let reportError = (e) => {
2
2
  console.error(e);
3
- console.log("Docs Link https://github.com/vasille-js/vasille-js/blob/v4/doc/V3-API.md");
3
+ console.log("Docs Link https://github.com/vasille-js/vasille-js/blob/v4/doc/V4-API.md");
4
4
  };
5
5
  export function setErrorHandler(handler) {
6
6
  reportError = handler;
7
7
  }
8
+ export function safe(fn) {
9
+ return ((...args) => {
10
+ try {
11
+ const result = fn(...args);
12
+ if (result instanceof Promise) {
13
+ result.catch(reportError);
14
+ }
15
+ else {
16
+ return result;
17
+ }
18
+ }
19
+ catch (e) {
20
+ reportError(e);
21
+ }
22
+ });
23
+ }
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export { Reactive } from "./core/core.js";
2
2
  export { IValue } from "./core/ivalue.js";
3
- export { reportError, setErrorHandler } from "./functional/safety.js";
3
+ export { reportError, setErrorHandler, safe } from "./functional/safety.js";
4
4
  export { ArrayModel } from "./models/array-model.js";
5
5
  export { Listener } from "./models/listener.js";
6
6
  export { MapModel } from "./models/map-model.js";
@@ -48,6 +48,7 @@ export class ArrayModel extends Array {
48
48
  * @return {*} removed value
49
49
  */
50
50
  pop() {
51
+ /* istanbul ignore else */
51
52
  if (this.length > 0) {
52
53
  const v = super.pop();
53
54
  this.listener.emitRemoved(v, v);
@@ -71,6 +72,7 @@ export class ArrayModel extends Array {
71
72
  * @return {*} the shifted value
72
73
  */
73
74
  shift() {
75
+ /* istanbul ignore else */
74
76
  if (this.length > 0) {
75
77
  const v = super.shift();
76
78
  this.listener.emitRemoved(v, v);
@@ -1,4 +1,4 @@
1
- import { TextNode as AbstractTextNode, DebugNode as AbstractDebugNode, Tag as AbstractTag, IValue, } from "../../index.js";
1
+ import { TextNode as AbstractTextNode, DebugNode as AbstractDebugNode, Tag as AbstractTag, IValue, safe, } from "../../index.js";
2
2
  import { internalError } from "../../core/errors.js";
3
3
  import { AttributeBinding } from "./binding/attribute.js";
4
4
  import { addClass, DynamicalClassBinding, removeClass, StaticClassBinding } from "./binding/class.js";
@@ -120,10 +120,10 @@ export class Tag extends AbstractTag {
120
120
  for (const name in options.events) {
121
121
  const event = options.events[name];
122
122
  if (event instanceof Array) {
123
- this.node.addEventListener(name, event[0], event[1]);
123
+ this.node.addEventListener(name, safe(event[0]), event[1]);
124
124
  }
125
125
  else {
126
- this.node.addEventListener(name, event);
126
+ this.node.addEventListener(name, safe(event));
127
127
  }
128
128
  }
129
129
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "The same framework which is designed to build bulletproof frontends (core library).",
4
4
  "main": "lib/index.js",
5
5
  "types": "types/index.d.ts",
6
- "version": "4.1.0",
6
+ "version": "4.3.0",
7
7
  "exports": {
8
8
  ".": {
9
9
  "types": "./types/index.d.ts",
@@ -1,2 +1,3 @@
1
1
  export declare let reportError: (e: unknown) => void;
2
2
  export declare function setErrorHandler(handler: (e: unknown) => void): void;
3
+ export declare function safe<Args extends unknown[], Ret extends unknown>(fn: (...args: Args) => Ret): (...args: Args) => Ret extends Promise<unknown> ? void : Ret | undefined;
package/types/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export type { Destroyable } from "./core/destroyable.js";
2
2
  export { Reactive } from "./core/core.js";
3
3
  export { IValue } from "./core/ivalue.js";
4
- export { reportError, setErrorHandler } from "./functional/safety.js";
4
+ export { reportError, setErrorHandler, safe } from "./functional/safety.js";
5
5
  export { ArrayModel } from "./models/array-model.js";
6
6
  export { Listener } from "./models/listener.js";
7
7
  export { MapModel } from "./models/map-model.js";