vasille 4.0.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,9 +48,12 @@ export class ArrayModel extends Array {
48
48
  * @return {*} removed value
49
49
  */
50
50
  pop() {
51
- const v = super.pop();
52
- this.listener.emitRemoved(v, v);
53
- return v;
51
+ /* istanbul ignore else */
52
+ if (this.length > 0) {
53
+ const v = super.pop();
54
+ this.listener.emitRemoved(v, v);
55
+ return v;
56
+ }
54
57
  }
55
58
  /**
56
59
  * Calls `Array.push` and notify about changes
@@ -69,9 +72,12 @@ export class ArrayModel extends Array {
69
72
  * @return {*} the shifted value
70
73
  */
71
74
  shift() {
72
- const v = super.shift();
73
- this.listener.emitRemoved(v, v);
74
- return v;
75
+ /* istanbul ignore else */
76
+ if (this.length > 0) {
77
+ const v = super.shift();
78
+ this.listener.emitRemoved(v, v);
79
+ return v;
80
+ }
75
81
  }
76
82
  /**
77
83
  * Calls `Array.splice` and notify about changed
package/lib/node/node.js CHANGED
@@ -177,7 +177,7 @@ export class Fragment extends Root {
177
177
  * @extends Fragment
178
178
  */
179
179
  export class TextNode extends Fragment {
180
- handler;
180
+ handler = null;
181
181
  data;
182
182
  constructor(input, runner) {
183
183
  super(runner);
@@ -238,7 +238,7 @@ export class SwitchedNode extends Fragment {
238
238
  * Index of current true condition
239
239
  * @type number
240
240
  */
241
- index;
241
+ index = -1;
242
242
  /**
243
243
  * Array of possible cases
244
244
  * @type {Array<{cond : IValue<unknown>, cb : function(Fragment)}>}
@@ -301,7 +301,7 @@ export class SwitchedNode extends Fragment {
301
301
  * @extends Fragment
302
302
  */
303
303
  export class DebugNode extends Fragment {
304
- handler;
304
+ handler = null;
305
305
  data;
306
306
  constructor(input, runner) {
307
307
  super(runner);
@@ -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
  }
@@ -13,6 +13,5 @@ export class SetView extends BaseView {
13
13
  this.model.forEach(item => {
14
14
  this.createChild(item, item);
15
15
  });
16
- return {};
17
16
  }
18
17
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "vasille",
3
- "description": "The framework designed to build bulletproof frontends (core library).",
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.0.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";
@@ -18,31 +18,31 @@ export declare class Listener<ValueT, IndexT = string | number> {
18
18
  * @param index {*} index of value
19
19
  * @param value {*} value of added item
20
20
  */
21
- emitAdded(index?: IndexT, value?: ValueT): void;
21
+ emitAdded(index: IndexT, value: ValueT): void;
22
22
  /**
23
23
  * Emits removed event to listeners
24
24
  * @param index {*} index of removed value
25
25
  * @param value {*} value of removed item
26
26
  */
27
- emitRemoved(index?: IndexT, value?: ValueT): void;
27
+ emitRemoved(index: IndexT, value: ValueT): void;
28
28
  /**
29
29
  * Adds a handler to added event
30
30
  * @param handler {function} function to run on event emitting
31
31
  */
32
- onAdd(handler: (index?: IndexT, value?: ValueT) => void): void;
32
+ onAdd(handler: (index: IndexT, value: ValueT) => void): void;
33
33
  /**
34
34
  * Adds a handler to removed event
35
35
  * @param handler {function} function to run on event emitting
36
36
  */
37
- onRemove(handler: (index?: IndexT, value?: ValueT) => void): void;
37
+ onRemove(handler: (index: IndexT, value: ValueT) => void): void;
38
38
  /**
39
39
  * Removes a handler from added event
40
40
  * @param handler {function} handler to remove
41
41
  */
42
- offAdd(handler: (index?: IndexT, value?: ValueT) => void): void;
42
+ offAdd(handler: (index: IndexT, value: ValueT) => void): void;
43
43
  /**
44
44
  * Removes a handler form removed event
45
45
  * @param handler {function} handler to remove
46
46
  */
47
- offRemove(handler: (index?: IndexT, value?: ValueT) => void): void;
47
+ offRemove(handler: (index: IndexT, value: ValueT) => void): void;
48
48
  }
@@ -8,5 +8,5 @@ import { SetModel } from "../models/set-model.js";
8
8
  */
9
9
  export declare class SetView<Node, Element, TagOptions extends object, T> extends BaseView<Node, Element, TagOptions, T, T, SetModel<T>> {
10
10
  constructor(input: BaseViewOptions<Node, Element, TagOptions, T, T, SetModel<T>>, runner: Runner<Node, Element, TagOptions>);
11
- compose(): {};
11
+ compose(): void;
12
12
  }
package/eslint.config.js DELETED
@@ -1,25 +0,0 @@
1
- import compat from "eslint-plugin-compat";
2
- import tseslint from "typescript-eslint";
3
- import { globalIgnores } from "eslint/config";
4
-
5
- export default tseslint.config(
6
- tseslint.configs.base,
7
- {
8
- name: "compat check",
9
- files: ["src/**/*.ts", "src/**/*.tsx"],
10
- plugins: { compat },
11
- rules: {
12
- "compat/compat": "error",
13
- },
14
- settings: {
15
- polyfills: ["Set", "Map"],
16
- },
17
- languageOptions: {
18
- parserOptions: {
19
- projectService: false,
20
- tsconfigRootDir: import.meta.dirname,
21
- },
22
- },
23
- },
24
- globalIgnores(["node_modules", "lib/**/*", "types", "coverage/**/*"]),
25
- );