nesquick 2.2.0 → 2.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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NesquickComponent = void 0;
4
4
  const State_1 = require("./State");
5
+ const util_1 = require("./util");
5
6
  const SVGNamespaces = new Map([
6
7
  ["xlink", "http://www.w3.org/1999/xlink"],
7
8
  ["xml", "http://www.w3.org/XML/1998/namespace"]
@@ -166,23 +167,23 @@ class NesquickComponent {
166
167
  this._renderStyle(element, props[k]);
167
168
  }
168
169
  else if (typeof props[k] === "function") {
169
- if (k.startsWith("on")) {
170
- element[k.toLowerCase()] = props[k];
170
+ const attribute = getAttributeNs(attributes, k);
171
+ if (attribute) {
172
+ (0, State_1.useRender)(props[k], v => {
173
+ element.setAttributeNS(attribute.namespace, attribute.name, String(v));
174
+ this._onUpdated();
175
+ });
176
+ }
177
+ else if ((0, util_1.isEvent)(k)) {
178
+ (0, State_1.useRender)(props[k], v => {
179
+ element[k.toLowerCase()] = v;
180
+ });
171
181
  }
172
182
  else {
173
- const attribute = getAttributeNs(attributes, k);
174
- if (attribute) {
175
- (0, State_1.useRender)(props[k], v => {
176
- element.setAttributeNS(attribute.namespace, attribute.name, String(v));
177
- this._onUpdated();
178
- });
179
- }
180
- else {
181
- (0, State_1.useRender)(props[k], v => {
182
- element.setAttribute(k, String(v));
183
- this._onUpdated();
184
- });
185
- }
183
+ (0, State_1.useRender)(props[k], v => {
184
+ element.setAttribute(k, String(v));
185
+ this._onUpdated();
186
+ });
186
187
  }
187
188
  }
188
189
  else {
@@ -205,8 +206,10 @@ class NesquickComponent {
205
206
  this._renderStyle(element, props[k]);
206
207
  }
207
208
  else if (typeof props[k] === "function") {
208
- if (k.startsWith("on")) {
209
- element[k.toLowerCase()] = props[k];
209
+ if ((0, util_1.isEvent)(k)) {
210
+ (0, State_1.useRender)(props[k], v => {
211
+ element[k.toLowerCase()] = v;
212
+ });
210
213
  }
211
214
  else {
212
215
  (0, State_1.useRender)(props[k], v => {
@@ -315,6 +318,7 @@ class NesquickComponent {
315
318
  _pushChild() {
316
319
  const nesquickChild = {
317
320
  node: null,
321
+ comment: false,
318
322
  component: null,
319
323
  fragment: null
320
324
  };
@@ -324,6 +328,7 @@ class NesquickComponent {
324
328
  _spliceChild(i) {
325
329
  const nesquickChild = {
326
330
  node: null,
331
+ comment: false,
327
332
  component: null,
328
333
  fragment: null
329
334
  };
@@ -402,11 +407,19 @@ class NesquickComponent {
402
407
  nesquickChild.node = node;
403
408
  }
404
409
  else {
405
- const value = child == null ? "" : String(child);
410
+ const value = String(child);
406
411
  if (nesquickChild.node == null || nesquickChild.component != null || nesquickChild.fragment != null) {
407
412
  nesquickChild.component = null;
408
413
  nesquickChild.fragment = null;
409
- const node = document.createTextNode(value);
414
+ let node;
415
+ if (child == null || child === false || child === true) {
416
+ node = document.createComment("");
417
+ nesquickChild.comment = true;
418
+ }
419
+ else {
420
+ node = document.createTextNode(String(value));
421
+ nesquickChild.comment = false;
422
+ }
410
423
  if (nesquickChild.node) {
411
424
  parent.replaceChild(node, nesquickChild.node);
412
425
  }
@@ -415,8 +428,24 @@ class NesquickComponent {
415
428
  }
416
429
  nesquickChild.node = node;
417
430
  }
431
+ else if (child == null || child === false || child === true) {
432
+ if (!nesquickChild.comment) {
433
+ const node = document.createComment("");
434
+ parent.replaceChild(node, nesquickChild.node);
435
+ nesquickChild.node = node;
436
+ nesquickChild.comment = true;
437
+ }
438
+ }
418
439
  else {
419
- nesquickChild.node.textContent = value;
440
+ if (nesquickChild.comment) {
441
+ const node = document.createTextNode(String(value));
442
+ parent.replaceChild(node, nesquickChild.node);
443
+ nesquickChild.node = node;
444
+ nesquickChild.comment = false;
445
+ }
446
+ else {
447
+ nesquickChild.node.textContent = value;
448
+ }
420
449
  }
421
450
  }
422
451
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformer = void 0;
4
4
  const TS = require("typescript");
5
+ const util_1 = require("../util");
5
6
  function getSingleIdentifier(node) {
6
7
  let identifier = null;
7
8
  node.forEachChild(node => {
@@ -87,8 +88,9 @@ const transformer = context => {
87
88
  node = res.node;
88
89
  }
89
90
  else if (TS.isJsxAttribute(node)) {
91
+ const propIsEvent = TS.isIdentifier(node.name) && (0, util_1.isEvent)(node.name.text);
90
92
  node = TS.visitEachChild(node, node => {
91
- const res = visitGeneric(node, { ...options, isJsxAttribute: true });
93
+ const res = visitGeneric(node, { ...options, isJsxAttribute: true, isEvent: propIsEvent });
92
94
  hasCallExpression = hasCallExpression || res.hasCallExpression;
93
95
  return res.node;
94
96
  }, context);
@@ -97,7 +99,7 @@ const transformer = context => {
97
99
  node = TS.visitEachChild(node, node => visitorExpression(node, { ...options, isJsxAttribute: false }), context);
98
100
  }
99
101
  else if (options.isJsxAttribute && TS.isStringLiteral(node)) {
100
- const returnNode = TS.visitNode(node, node => visitorExpression(node, { ...options, isJsxAttribute: false }), TS.isExpression);
102
+ const returnNode = TS.visitNode(node, node => visitorExpression(node, { ...options, isJsxAttribute: false, isEvent: false }), TS.isExpression);
101
103
  if (TS.isStringLiteral(returnNode)) {
102
104
  node = returnNode;
103
105
  }
@@ -107,13 +109,13 @@ const transformer = context => {
107
109
  }
108
110
  else if (TS.isFunctionLike(node)) {
109
111
  node = TS.visitEachChild(node, node => {
110
- const res = visitGeneric(node, { ...options, isJsxAttribute: false });
112
+ const res = visitGeneric(node, { ...options, isJsxAttribute: false, isEvent: false });
111
113
  return res.node;
112
114
  }, context);
113
115
  }
114
116
  else {
115
117
  node = TS.visitEachChild(node, node => {
116
- const res = visitGeneric(node, { ...options, isJsxAttribute: false });
118
+ const res = visitGeneric(node, { ...options, isJsxAttribute: false, isEvent: false });
117
119
  hasCallExpression = hasCallExpression || res.hasCallExpression;
118
120
  return res.node;
119
121
  }, context);
@@ -138,7 +140,7 @@ const transformer = context => {
138
140
  }
139
141
  const res = visitGeneric(node, {});
140
142
  node = res.node;
141
- if (TS.isConciseBody(node) && (options.userComponent || res.hasCallExpression)) {
143
+ if (TS.isConciseBody(node) && (options.userComponent || res.hasCallExpression || options.isEvent)) {
142
144
  node = arrowify(node);
143
145
  }
144
146
  return node;
@@ -4,9 +4,13 @@ export type ChildFunc = () => Exclude<Child, ChildFunc> | Exclude<Child, ChildFu
4
4
  export type ComponentProps = Record<string, any>;
5
5
  export type FunctionComponent<P extends ComponentProps = {}> = (props: P) => NesquickComponent<any>;
6
6
  export type NesquickDocument = Pick<Document, "createElement" | "createElementNS" | "createTextNode" | "createDocumentFragment" | "createComment">;
7
- type NesquickChild = {
7
+ type NesquickChild = ({
8
8
  node: Node | null;
9
- } & ({
9
+ comment: false;
10
+ } | {
11
+ node: Comment;
12
+ comment: true;
13
+ }) & ({
10
14
  component: NesquickComponent | null;
11
15
  fragment: null;
12
16
  } | {
@@ -0,0 +1 @@
1
+ export declare function isEvent(name: string): boolean;
package/lib/util.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isEvent = isEvent;
4
+ function isEvent(name) {
5
+ return name.startsWith("on") && name.length > 2 && name[2] === name[2].toUpperCase();
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nesquick",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "React-like library with focus on drawing performance",
5
5
  "types": "./lib/types/index.d.ts",
6
6
  "main": "./lib/index.js",