@unsetsoft/ryunixjs 0.2.6 → 0.2.8-nightly.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/lib/dom.js +42 -4
- package/lib/main.js +5 -8
- package/package.json +1 -1
- package/webpack.config.js +3 -0
package/lib/dom.js
CHANGED
|
@@ -68,7 +68,7 @@ function createDom(fiber) {
|
|
|
68
68
|
const isEvent = (key) => key.startsWith("on");
|
|
69
69
|
const isProperty = (key) => key !== "children" && !isEvent(key);
|
|
70
70
|
const isNew = (prev, next) => (key) => prev[key] !== next[key];
|
|
71
|
-
const isGone = (
|
|
71
|
+
const isGone = (next) => (key) => !(key in next);
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
74
|
* The function updates the DOM by removing old event listeners and properties, and adding new ones
|
|
@@ -80,7 +80,7 @@ const isGone = (prev, next) => (key) => !(key in next);
|
|
|
80
80
|
function updateDom(dom, prevProps, nextProps) {
|
|
81
81
|
Object.keys(prevProps)
|
|
82
82
|
.filter(isEvent)
|
|
83
|
-
.filter((key) =>
|
|
83
|
+
.filter((key) => isGone(nextProps)(key) || isNew(prevProps, nextProps)(key))
|
|
84
84
|
.forEach((name) => {
|
|
85
85
|
const eventType = name.toLowerCase().substring(2);
|
|
86
86
|
dom.removeEventListener(eventType, prevProps[name]);
|
|
@@ -88,7 +88,7 @@ function updateDom(dom, prevProps, nextProps) {
|
|
|
88
88
|
|
|
89
89
|
Object.keys(prevProps)
|
|
90
90
|
.filter(isProperty)
|
|
91
|
-
.filter(isGone(
|
|
91
|
+
.filter(isGone(nextProps))
|
|
92
92
|
.forEach((name) => {
|
|
93
93
|
dom[name] = "";
|
|
94
94
|
});
|
|
@@ -97,7 +97,15 @@ function updateDom(dom, prevProps, nextProps) {
|
|
|
97
97
|
.filter(isProperty)
|
|
98
98
|
.filter(isNew(prevProps, nextProps))
|
|
99
99
|
.forEach((name) => {
|
|
100
|
-
|
|
100
|
+
if (name === "style") {
|
|
101
|
+
DomStyle(dom, nextProps.style);
|
|
102
|
+
} else if (name === "className") {
|
|
103
|
+
prevProps.className &&
|
|
104
|
+
dom.classList.remove(...prevProps.className.split(/\s+/));
|
|
105
|
+
dom.classList.add(...nextProps.className.split(/\s+/));
|
|
106
|
+
} else {
|
|
107
|
+
dom[name] = nextProps[name];
|
|
108
|
+
}
|
|
101
109
|
});
|
|
102
110
|
|
|
103
111
|
Object.keys(nextProps)
|
|
@@ -109,6 +117,18 @@ function updateDom(dom, prevProps, nextProps) {
|
|
|
109
117
|
});
|
|
110
118
|
}
|
|
111
119
|
|
|
120
|
+
const reg = /[A-Z]/g;
|
|
121
|
+
function DomStyle(dom, style) {
|
|
122
|
+
dom.style = Object.keys(style).reduce((acc, styleName) => {
|
|
123
|
+
const key = styleName.replace(reg, function (v) {
|
|
124
|
+
return "-" + v.toLowerCase();
|
|
125
|
+
});
|
|
126
|
+
acc += `${key}: ${style[styleName]};`;
|
|
127
|
+
return acc;
|
|
128
|
+
}, "");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
112
132
|
/**
|
|
113
133
|
* The function commits changes made to the virtual DOM to the actual DOM.
|
|
114
134
|
*/
|
|
@@ -210,6 +230,7 @@ function commitDeletion(fiber, domParent) {
|
|
|
210
230
|
let containerRoot = null;
|
|
211
231
|
|
|
212
232
|
/**
|
|
233
|
+
* @deprecated use Ryunix.init(root) instead.
|
|
213
234
|
* The function creates a root container for a web application.
|
|
214
235
|
* @param root - The parameter `root` is likely referring to an HTML element that will serve as the
|
|
215
236
|
* root or container for a web application or component. The `createRoot` function takes this element
|
|
@@ -220,6 +241,17 @@ function createRoot(root) {
|
|
|
220
241
|
containerRoot = root;
|
|
221
242
|
}
|
|
222
243
|
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* The function creates a reference to a DOM element with the specified ID. This will be used to initialize the app.
|
|
247
|
+
* @param root - The parameter "root" is the id of the HTML element that will serve as the container
|
|
248
|
+
* for the root element.
|
|
249
|
+
* @example createRoot("root") -> <div id="root" />
|
|
250
|
+
*/
|
|
251
|
+
function init(root) {
|
|
252
|
+
containerRoot = document.getElementById(root);
|
|
253
|
+
}
|
|
254
|
+
|
|
223
255
|
/**
|
|
224
256
|
* The function renders an element into a container using a work-in-progress root.
|
|
225
257
|
* @param element - The element parameter is the component or element that needs to be rendered in the
|
|
@@ -485,7 +517,13 @@ export {
|
|
|
485
517
|
createElement,
|
|
486
518
|
render,
|
|
487
519
|
createRoot,
|
|
520
|
+
init,
|
|
488
521
|
// Hooks
|
|
489
522
|
useStore,
|
|
490
523
|
useEffect,
|
|
491
524
|
};
|
|
525
|
+
|
|
526
|
+
export default {
|
|
527
|
+
createElement,
|
|
528
|
+
render,
|
|
529
|
+
};
|
package/lib/main.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useStore, useEffect } from "./dom";
|
|
1
|
+
import Ryunix from "./dom";
|
|
3
2
|
|
|
4
|
-
export { useStore, useEffect, createElement, render, createRoot };
|
|
3
|
+
export { useStore, useEffect, createElement, render, createRoot } from "./dom";
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
createRoot,
|
|
10
|
-
};
|
|
5
|
+
window.Ryunix = Ryunix;
|
|
6
|
+
|
|
7
|
+
export default Ryunix;
|
package/package.json
CHANGED