nesquick 1.1.0 → 1.2.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 +2 -2
- package/lib/NesquickComponent.js +11 -3
- package/lib/types/State.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
### Motivation
|
|
2
|
-
I like react, but it always bugged me how you need to create a full fake DOM that is going to be compared to a virtual DOM to finally render the updates in the browser. Yes, it will only update the real DOM with the new changes, but the process of creating a full fake DOM and comparing it each time something is updated is incredibly resource wasting. I always thought in a way to link states to HTML elementos directly, so no more virtual DOM is needed, and like so, **N**imble **E**
|
|
2
|
+
I like react, but it always bugged me how you need to create a full fake DOM that is going to be compared to a virtual DOM to finally render the updates in the browser. Yes, it will only update the real DOM with the new changes, but the process of creating a full fake DOM and comparing it each time something is updated is incredibly resource wasting. I always thought in a way to link states to HTML elementos directly, so no more virtual DOM is needed, and like so, **N**imble **E**elements **S**uper **Quick** (`nesquick`) was born. At first it required for you to define the *subscribers*, so if you forgot to create a subscriber, no state will be linked to an HTML property. Now, with the magic of Typescript, you can link states to HTML elements without taking care of the subscribers, which makes it easier. For example, this is `nesquick`:
|
|
3
3
|
```ts
|
|
4
4
|
import { useState } from "nesquick";
|
|
5
5
|
|
|
6
6
|
function MyComp() {
|
|
7
7
|
const [ getNumber, setNumber ] = useState(0);
|
|
8
8
|
return <div>
|
|
9
|
-
<button onClick={() => setNumber(
|
|
9
|
+
<button onClick={() => setNumber(Math.random())}>Update number</button>
|
|
10
10
|
<div>Number: {getNumber()}</div>
|
|
11
11
|
</div>;
|
|
12
12
|
}
|
package/lib/NesquickComponent.js
CHANGED
|
@@ -215,9 +215,17 @@ class NesquickComponent {
|
|
|
215
215
|
this._renderChild(document, parent, this._pushChild(), child);
|
|
216
216
|
}
|
|
217
217
|
else if (typeof child === "function") {
|
|
218
|
-
|
|
219
|
-
(0, State_1.useRender)(child, children => {
|
|
220
|
-
|
|
218
|
+
let ch = null;
|
|
219
|
+
(0, State_1.useRender)(child, (children, lastReaction) => {
|
|
220
|
+
if (lastReaction && ch == null && Array.isArray(children)) {
|
|
221
|
+
this._renderChildren(document, parent, children);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
if (ch == null) {
|
|
225
|
+
ch = this._pushChild();
|
|
226
|
+
}
|
|
227
|
+
this._renderChild(document, parent, ch, children);
|
|
228
|
+
}
|
|
221
229
|
});
|
|
222
230
|
}
|
|
223
231
|
else {
|
package/lib/types/State.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type Getter<T> = () => T;
|
|
2
2
|
export type Setter<T> = (value: T) => void;
|
|
3
|
-
export type
|
|
4
|
-
export type State<T> = [get: Getter<T>, set: Setter<T>,
|
|
3
|
+
export type Updater<T> = (cb: (value: T) => T) => void;
|
|
4
|
+
export type State<T> = [get: Getter<T>, set: Setter<T>, update: Updater<T>];
|
|
5
5
|
type Subscription<T> = {
|
|
6
6
|
cb: () => T;
|
|
7
7
|
iteration: number;
|