@unsetsoft/ryunixjs 0.2.7 → 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.
Files changed (2) hide show
  1. package/lib/dom.js +37 -4
  2. package/package.json +1 -1
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 = (prev, next) => (key) => !(key in next);
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) => !(key in nextProps) || isNew(prevProps, nextProps)(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(prevProps, nextProps))
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
- dom[name] = nextProps[name];
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,6 +517,7 @@ export {
485
517
  createElement,
486
518
  render,
487
519
  createRoot,
520
+ init,
488
521
  // Hooks
489
522
  useStore,
490
523
  useEffect,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unsetsoft/ryunixjs",
3
- "version": "0.2.7",
3
+ "version": "0.2.8-nightly.0",
4
4
  "license": "MIT",
5
5
  "main": "./dist/Ryunix.js",
6
6
  "private": false,