@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 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
@@ -0,0 +1,5 @@
1
+ const useLoaded = (fn) => {
2
+ return document.addEventListener("DOMContentLoaded", fn);
3
+ };
4
+
5
+ export { useLoaded };
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
- } else if (element == null) {
15
+ }
16
+
17
+ if (element == null) {
15
18
  parentDom.removeChild(instance.dom);
16
19
  return null;
17
- } else if (instance.element.type !== element.type) {
20
+ }
21
+
22
+ if (instance.element.type !== element.type) {
18
23
  const newInstance = instantiate(element);
19
- parentDom.replaceChild(newInstance.dom, instance.dom);
24
+ parentDom.replaceChild(instance.dom, newInstance.dom);
20
25
  return newInstance;
21
- } else if (typeof element.type === "string") {
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.dom;
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
- return newChildInstances.filter((instance) => instance != null);
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 hooks from "./hooks/index.js";
5
- export { createElement, render, Component, hooks };
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.2-alpha.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
  }
@@ -1,3 +0,0 @@
1
- import Store from "./store";
2
- const useStore = (val) => new Store(val).hook();
3
- export default { useStore };
@@ -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;