@unsetsoft/ryunixjs 0.1.2-alpha.1 → 0.1.4
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 +25 -0
- package/lib/component.js +0 -10
- package/lib/hooks.js +5 -0
- package/lib/reconciler.js +30 -17
- package/lib/ryunix.js +2 -3
- package/package.json +8 -1
- package/lib/hooks/index.js +0 -3
- package/lib/hooks/store.js +0 -20
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# RyunixJS
|
|
2
|
+
|
|
3
|
+
## What is RyunixJS?
|
|
4
|
+
|
|
5
|
+
Is a ReactJS Clone! Even lighter, however, at a very early stage for production use.
|
|
6
|
+
|
|
7
|
+
## Install & Usage
|
|
8
|
+
|
|
9
|
+
`npm install @unsetsoft/create-ryunix-app -g`
|
|
10
|
+
|
|
11
|
+
### Obtain and download the template
|
|
12
|
+
|
|
13
|
+
`create-ryunix-app get`
|
|
14
|
+
|
|
15
|
+
### Rename your final folder
|
|
16
|
+
|
|
17
|
+
`create-ryunix-app get --dirname awasome-ryunix-app`
|
|
18
|
+
|
|
19
|
+
## Bugs?
|
|
20
|
+
|
|
21
|
+
You can create an issue on GitHub.
|
|
22
|
+
|
|
23
|
+
## Do you want to contribute?
|
|
24
|
+
|
|
25
|
+
Fork a send a pull request!
|
package/lib/component.js
CHANGED
|
@@ -2,15 +2,5 @@ import { reconcile } from "./reconciler";
|
|
|
2
2
|
export class Component {
|
|
3
3
|
constructor(props) {
|
|
4
4
|
this.props = props;
|
|
5
|
-
this.state = this.state || {};
|
|
6
|
-
}
|
|
7
|
-
setState(partialState) {
|
|
8
|
-
this.state = Object.assign({}, this.state, partialState);
|
|
9
|
-
updateInstance(this.__internalInstance);
|
|
10
5
|
}
|
|
11
6
|
}
|
|
12
|
-
function updateInstance(internalInstance) {
|
|
13
|
-
const parentDom = internalInstance.dom.parentNode;
|
|
14
|
-
const element = internalInstance.element;
|
|
15
|
-
reconcile(parentDom, internalInstance, element);
|
|
16
|
-
}
|
package/lib/hooks.js
ADDED
package/lib/reconciler.js
CHANGED
|
@@ -6,33 +6,42 @@ export function render(element, parentDom) {
|
|
|
6
6
|
const nextInstance = reconcile(parentDom, prevInstance, element);
|
|
7
7
|
rootInstance = nextInstance;
|
|
8
8
|
}
|
|
9
|
+
|
|
9
10
|
export function reconcile(parentDom, instance, element) {
|
|
10
11
|
if (instance === null) {
|
|
11
12
|
const newInstance = instantiate(element);
|
|
12
13
|
parentDom.appendChild(newInstance.dom);
|
|
13
14
|
return newInstance;
|
|
14
|
-
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (element == null) {
|
|
15
18
|
parentDom.removeChild(instance.dom);
|
|
16
19
|
return null;
|
|
17
|
-
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (instance.element.type !== element.type) {
|
|
18
23
|
const newInstance = instantiate(element);
|
|
19
|
-
parentDom.replaceChild(
|
|
24
|
+
parentDom.replaceChild(instance.dom, newInstance.dom);
|
|
20
25
|
return newInstance;
|
|
21
|
-
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (typeof element.type === "string") {
|
|
22
29
|
instance.childInstances = reconcileChildren(instance, element);
|
|
23
30
|
instance.element = element;
|
|
24
31
|
return instance;
|
|
25
|
-
} else {
|
|
26
|
-
instance.publicInstance.props = element.props;
|
|
27
|
-
const childElement = instance.publicInstance.render();
|
|
28
|
-
const oldChildInstance = instance.childInstance;
|
|
29
|
-
const childInstance = reconcile(parentDom, oldChildInstance, childElement);
|
|
30
|
-
instance.dom = childInstance.dom;
|
|
31
|
-
instance.childInstance = childInstance;
|
|
32
|
-
instance.element = element;
|
|
33
|
-
return instance;
|
|
34
32
|
}
|
|
33
|
+
|
|
34
|
+
// Si no es una cadena, asumimos que es un componente personalizado
|
|
35
|
+
instance.publicInstance.props = element.props;
|
|
36
|
+
const childElement = instance.publicInstance.render();
|
|
37
|
+
const oldChildInstance = instance.childInstance;
|
|
38
|
+
const childInstance = reconcile(parentDom, oldChildInstance, childElement);
|
|
39
|
+
instance.dom = childInstance.dom;
|
|
40
|
+
instance.childInstance = childInstance;
|
|
41
|
+
instance.element = element;
|
|
42
|
+
return instance;
|
|
35
43
|
}
|
|
44
|
+
|
|
36
45
|
function instantiate(element) {
|
|
37
46
|
const { type, props } = element;
|
|
38
47
|
const isDomElement = typeof type === "string";
|
|
@@ -73,17 +82,21 @@ function createPublicInstance(element, internalInstance) {
|
|
|
73
82
|
publicInstance.__internalInstance = internalInstance;
|
|
74
83
|
return publicInstance;
|
|
75
84
|
}
|
|
85
|
+
|
|
76
86
|
function reconcileChildren(instance, element) {
|
|
77
|
-
const dom = instance
|
|
78
|
-
const childInstances = instance.childInstances;
|
|
87
|
+
const { dom, childInstances } = instance;
|
|
79
88
|
const nextChildElements = element.props.children || [];
|
|
89
|
+
|
|
80
90
|
const newChildInstances = [];
|
|
91
|
+
|
|
81
92
|
const count = Math.max(childInstances.length, nextChildElements.length);
|
|
93
|
+
|
|
82
94
|
for (let i = 0; i < count; i++) {
|
|
83
95
|
const childInstance = childInstances[i];
|
|
84
96
|
const childElement = nextChildElements[i];
|
|
85
97
|
const newChildInstance = reconcile(dom, childInstance, childElement);
|
|
86
98
|
newChildInstances.push(newChildInstance);
|
|
87
99
|
}
|
|
88
|
-
|
|
89
|
-
|
|
100
|
+
|
|
101
|
+
return newChildInstances.filter(Boolean);
|
|
102
|
+
}
|
package/lib/ryunix.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { render } from "./reconciler";
|
|
2
2
|
import { createElement } from "./element";
|
|
3
3
|
import { Component } from "./component";
|
|
4
|
-
import
|
|
5
|
-
export { createElement, render, Component,
|
|
4
|
+
import { useLoaded } from "./hooks";
|
|
5
|
+
export { createElement, render, Component, useLoaded };
|
|
6
6
|
export default {
|
|
7
7
|
render,
|
|
8
8
|
createElement,
|
|
9
9
|
Component,
|
|
10
|
-
hooks,
|
|
11
10
|
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unsetsoft/ryunixjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/Ryunix.js",
|
|
6
6
|
"private": false,
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/UnSetSoft/Ryunixjs/issues"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/UnSetSoft/Ryunixjs#readme",
|
|
7
11
|
"scripts": {
|
|
8
12
|
"build": "rollup ./lib/ryunix.js --file ./dist/Ryunix.js --format umd --name Ryunix",
|
|
9
13
|
"prepublishOnly": "yarn build"
|
|
10
14
|
},
|
|
11
15
|
"devDependencies": {
|
|
12
16
|
"rollup": "3.24.0"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=18.16.0"
|
|
13
20
|
}
|
|
14
21
|
}
|
package/lib/hooks/index.js
DELETED
package/lib/hooks/store.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
class Store {
|
|
2
|
-
constructor(defvalue) {
|
|
3
|
-
this.defvalue = defvalue;
|
|
4
|
-
}
|
|
5
|
-
/* `setValue` is a method that takes in a parameter `newValue`. The arrow function syntax `=>` is
|
|
6
|
-
used to define the function. Inside the function, the `defvalue` property of the `Store` instance
|
|
7
|
-
is set to the `newValue` parameter. This means that when `setValue` is called with a new value, it
|
|
8
|
-
updates the `defvalue` property of the `Store` instance to that new value. */
|
|
9
|
-
setValue = (newValue) => (this.defvalue = newValue);
|
|
10
|
-
|
|
11
|
-
/* `hook` is a method that returns an array containing two functions: `getValue` and `setValue`.
|
|
12
|
-
These functions can be used to get and set the value of the `defvalue` property of the `Store`
|
|
13
|
-
class instance. This is useful for implementing state management in React functional components
|
|
14
|
-
using the `useState` hook. */
|
|
15
|
-
hook = () => {
|
|
16
|
-
return [this.defvalue, this.setValue];
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default Store;
|