nesquick 2.0.0 → 2.1.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.
@@ -39,6 +39,7 @@ class NesquickComponent {
39
39
  this._subscriptions = new State_1.Subscriptions();
40
40
  this._styleSubscriptions = null;
41
41
  this._xmlns = null;
42
+ this._onUpdate = null;
42
43
  this._children = [];
43
44
  }
44
45
  render(document) {
@@ -88,8 +89,15 @@ class NesquickComponent {
88
89
  }
89
90
  }
90
91
  this._renderChildren(document, element, this.props.children);
91
- if (this.props.ref != null) {
92
- this.props.ref(element);
92
+ if (typeof this.props["nq:ref"] === "function") {
93
+ this.props["nq:ref"](element);
94
+ }
95
+ if (typeof this.props["nq:update"] === "function") {
96
+ this._onUpdate = {
97
+ waiting: true,
98
+ element: element,
99
+ cb: this.props["nq:update"]
100
+ };
93
101
  }
94
102
  this.props = {};
95
103
  State_1.subscriptions.reset();
@@ -98,9 +106,18 @@ class NesquickComponent {
98
106
  setXmlns(xmlns) {
99
107
  this._xmlns = xmlns;
100
108
  }
109
+ _onUpdated() {
110
+ if (this._onUpdate?.waiting) {
111
+ this._onUpdate.waiting = false;
112
+ (0, State_1.afterRender)(() => {
113
+ this._onUpdate.waiting = true;
114
+ this._onUpdate.cb(this._onUpdate.element);
115
+ });
116
+ }
117
+ }
101
118
  _renderPropsNs(attributes, element, props) {
102
119
  for (const k in props) {
103
- if (k !== "children" && k !== "xmlns" && k !== "ref") {
120
+ if (k !== "children" && k !== "xmlns" && k !== "nq:ref" && k !== "nq:update") {
104
121
  if (k === "style") {
105
122
  this._renderStyle(element, props[k]);
106
123
  }
@@ -113,11 +130,13 @@ class NesquickComponent {
113
130
  if (attribute) {
114
131
  (0, State_1.useRender)(props[k], v => {
115
132
  element.setAttributeNS(attribute.namespace, attribute.name, String(v));
133
+ this._onUpdated();
116
134
  });
117
135
  }
118
136
  else {
119
137
  (0, State_1.useRender)(props[k], v => {
120
138
  element.setAttribute(k, String(v));
139
+ this._onUpdated();
121
140
  });
122
141
  }
123
142
  }
@@ -137,7 +156,7 @@ class NesquickComponent {
137
156
  ;
138
157
  _renderProps(element, props) {
139
158
  for (const k in props) {
140
- if (k !== "children" && k !== "xmlns" && k !== "ref") {
159
+ if (k !== "children" && k !== "xmlns" && k !== "nq:ref" && k !== "nq:update") {
141
160
  if (k === "style") {
142
161
  this._renderStyle(element, props[k]);
143
162
  }
@@ -148,6 +167,7 @@ class NesquickComponent {
148
167
  else {
149
168
  (0, State_1.useRender)(props[k], v => {
150
169
  element.setAttribute(k, String(v));
170
+ this._onUpdated();
151
171
  });
152
172
  }
153
173
  }
@@ -162,6 +182,7 @@ class NesquickComponent {
162
182
  if (typeof styles[k] === "function") {
163
183
  (0, State_1.useRender)(styles[k], v => {
164
184
  element.style[k] = String(v);
185
+ this._onUpdated();
165
186
  });
166
187
  }
167
188
  else {
@@ -198,6 +219,7 @@ class NesquickComponent {
198
219
  break;
199
220
  }
200
221
  }
222
+ this._onUpdated();
201
223
  });
202
224
  break;
203
225
  }
@@ -237,6 +259,7 @@ class NesquickComponent {
237
259
  }
238
260
  this._renderChild(document, parent, ch, children);
239
261
  }
262
+ this._onUpdated();
240
263
  });
241
264
  }
242
265
  else {
package/lib/State.js CHANGED
@@ -4,6 +4,7 @@ exports.subscriptions = exports.Subscriptions = void 0;
4
4
  exports.useState = useState;
5
5
  exports.useEffect = useEffect;
6
6
  exports.useRender = useRender;
7
+ exports.afterRender = afterRender;
7
8
  exports.useMemo = useMemo;
8
9
  exports.useDispose = useDispose;
9
10
  let currentReactor = [];
@@ -19,6 +20,7 @@ var reactor;
19
20
  reactor_1.reset = reset;
20
21
  })(reactor || (reactor = {}));
21
22
  let pendingReactor = null;
23
+ const onRenders = [];
22
24
  function renderReactor(reactor, instant) {
23
25
  if (instant) {
24
26
  runSubscription(reactor);
@@ -49,6 +51,9 @@ function renderReactors() {
49
51
  next = n;
50
52
  } while (next);
51
53
  pendingReactor = null;
54
+ for (const cb of onRenders.splice(0)) {
55
+ cb();
56
+ }
52
57
  }
53
58
  class Subscriptions {
54
59
  constructor() {
@@ -109,6 +114,15 @@ function useRender(cb, reaction = null) {
109
114
  const sub = newSubscription(cb, reaction, false);
110
115
  runSubscription(sub);
111
116
  }
117
+ const NopSubscription = newSubscription(() => { }, null, false);
118
+ cancelSubscription(NopSubscription);
119
+ function afterRender(cb) {
120
+ onRenders.push(cb);
121
+ if (pendingReactor == null) {
122
+ NopSubscription.pending = false;
123
+ renderReactor(NopSubscription, false);
124
+ }
125
+ }
112
126
  function useMemo(cb) {
113
127
  const reactors = new Set();
114
128
  let state = 0;
@@ -34,6 +34,9 @@ function createSpreadCheckFunction(fName) {
34
34
  TS.factory.createParameterDeclaration(void 0, void 0, obj),
35
35
  TS.factory.createParameterDeclaration(void 0, void 0, check)
36
36
  ], void 0, TS.factory.createBlock([
37
+ TS.factory.createIfStatement(TS.factory.createPrefixUnaryExpression(TS.SyntaxKind.ExclamationToken, obj), TS.factory.createBlock([
38
+ TS.factory.createReturnStatement(obj)
39
+ ], true), void 0),
37
40
  TS.factory.createVariableStatement(void 0, TS.factory.createVariableDeclarationList([
38
41
  TS.factory.createVariableDeclaration(res, void 0, void 0, TS.factory.createCallExpression(TS.factory.createPropertyAccessExpression(TS.factory.createIdentifier("Object"), "create"), void 0, [TS.factory.createNull()]))
39
42
  ], TS.NodeFlags.Const)),
@@ -73,6 +76,12 @@ const transformer = context => {
73
76
  node = TS.factory.updateJsxSpreadAttribute(node, callExpression);
74
77
  }
75
78
  }
79
+ else if (TS.isJsxElement(node)) {
80
+ const firstLetter = node.openingElement.tagName.getText()[0];
81
+ const userComponent = firstLetter !== firstLetter.toLowerCase();
82
+ const res = processNode(node, { userComponent });
83
+ node = res.node;
84
+ }
76
85
  else if (TS.isJsxOpeningLikeElement(node)) {
77
86
  const firstLetter = node.tagName.getText()[0];
78
87
  const userComponent = firstLetter !== firstLetter.toLowerCase();
@@ -28,10 +28,12 @@ export declare class NesquickComponent<P extends ComponentProps = {}> {
28
28
  private _subscriptions;
29
29
  private _styleSubscriptions;
30
30
  private _xmlns;
31
+ private _onUpdate;
31
32
  protected _children: NesquickChild[];
32
33
  constructor(_render: string | FunctionComponent<P>, props: P);
33
34
  render(document: VeactDocument): Node;
34
35
  setXmlns(xmlns: XmlNs | null): void;
36
+ private _onUpdated;
35
37
  private _renderPropsNs;
36
38
  private _renderProps;
37
39
  private _renderStyles;
@@ -26,6 +26,7 @@ export declare namespace subscriptions {
26
26
  export declare function useState<T>(value: T): State<T>;
27
27
  export declare function useEffect<T>(cb: () => T, reaction?: ((data: T, lastReaction: boolean) => void) | null): void;
28
28
  export declare function useRender<T>(cb: () => T, reaction?: ((data: T, lastReaction: boolean) => void) | null): void;
29
+ export declare function afterRender(cb: () => void): void;
29
30
  export declare function useMemo<T>(cb: () => T): Getter<T>;
30
31
  export declare function useDispose(cb: () => void): void;
31
32
  export {};
@@ -18,7 +18,8 @@ export declare namespace JSX {
18
18
  [k: string]: any;
19
19
  style?: Style;
20
20
  xmlns?: string | null;
21
- ref?: ((el: T) => void) | null;
21
+ "nq:ref"?: ((el: T) => void) | null;
22
+ "nq:update"?: ((el: T) => void) | null;
22
23
  }
23
24
  export type Style = StyleProps | string;
24
25
  export type StyleProps = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nesquick",
3
- "version": "2.0.0",
3
+ "version": "2.1.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",