@unsetsoft/ryunixjs 0.4.10-nightly.0 → 0.4.11-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/README.md CHANGED
@@ -2,10 +2,9 @@
2
2
 
3
3
  [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FUnSetSoft%2FRyunixjs%2Ftree%2Fmaster%2Fvercel%2Fryunix-jsx&project-name=ryunix-jsx-project&repository-name=ryunix-jsx-project)
4
4
 
5
-
6
5
  ## What is RyunixJS?
7
6
 
8
- Is a ReactJS Clone! Even lighter, however, at a very early stage for production use.
7
+ Is a ReactJS Clone! Even lighter, however, at a very early stage for production use.
9
8
 
10
9
  ## Usage
11
10
 
package/dist/Ryunix.js CHANGED
@@ -17,17 +17,17 @@
17
17
  const reg = /[A-Z]/g;
18
18
 
19
19
  const RYUNIX_TYPES = Object.freeze({
20
- TEXT_ELEMENT: Symbol("text.element"),
21
- RYUNIX_EFFECT: Symbol("ryunix.effect"),
22
- RYUNIX_CONTEXT: Symbol("ryunix.context"),
20
+ TEXT_ELEMENT: Symbol('text.element'),
21
+ RYUNIX_EFFECT: Symbol('ryunix.effect'),
22
+ RYUNIX_CONTEXT: Symbol('ryunix.context'),
23
23
  });
24
24
 
25
25
  const STRINGS = Object.freeze({
26
- object: "object",
27
- function: "function",
28
- style: "style",
29
- className: "className",
30
- children: "children",
26
+ object: 'object',
27
+ function: 'function',
28
+ style: 'style',
29
+ className: 'className',
30
+ children: 'children',
31
31
  });
32
32
 
33
33
  const EFFECT_TAGS = Object.freeze({
@@ -61,10 +61,10 @@
61
61
  children: children
62
62
  .flat()
63
63
  .map((child) =>
64
- typeof child === STRINGS.object ? child : createTextElement(child)
64
+ typeof child === STRINGS.object ? child : createTextElement(child),
65
65
  ),
66
66
  },
67
- };
67
+ }
68
68
  };
69
69
 
70
70
  /**
@@ -81,17 +81,17 @@
81
81
  nodeValue: text,
82
82
  children: [],
83
83
  },
84
- };
84
+ }
85
85
  };
86
86
 
87
87
  const Fragments = (props) => {
88
88
  if (props.style) {
89
- throw new Error("The style attribute is not supported");
89
+ throw new Error('The style attribute is not supported')
90
90
  }
91
- if (props.className === "") {
92
- throw new Error("className cannot be empty.");
91
+ if (props.className === '') {
92
+ throw new Error('className cannot be empty.')
93
93
  }
94
- return createElement("div", props, props.children);
94
+ return createElement('div', props, props.children)
95
95
  };
96
96
 
97
97
  /**
@@ -120,11 +120,11 @@
120
120
  * for the root element.
121
121
  */
122
122
  const init = (root) => {
123
- const rootElement = root || "__ryunix";
123
+ const rootElement = root || '__ryunix';
124
124
  vars.containerRoot = document.getElementById(rootElement);
125
125
  };
126
126
 
127
- const isEvent = (key) => key.startsWith("on");
127
+ const isEvent = (key) => key.startsWith('on');
128
128
  const isProperty = (key) => key !== STRINGS.children && !isEvent(key);
129
129
  const isNew = (prev, next) => (key) => prev[key] !== next[key];
130
130
  const isGone = (next) => (key) => !(key in next);
@@ -210,7 +210,7 @@
210
210
 
211
211
  vars.wipFiber.hooks.push(hook);
212
212
  vars.hookIndex++;
213
- return [hook.state, setState];
213
+ return [hook.state, setState]
214
214
  };
215
215
 
216
216
  /**
@@ -262,7 +262,7 @@
262
262
 
263
263
  vars.wipFiber.hooks.push(hook);
264
264
 
265
- return hook.query;
265
+ return hook.query
266
266
  };
267
267
 
268
268
  const Router = ({ path, component }) => {
@@ -273,44 +273,44 @@
273
273
  setCurrentPath(() => window.location.pathname);
274
274
  };
275
275
 
276
- window.addEventListener("navigate", onLocationChange);
277
- window.addEventListener("pushsatate", onLocationChange);
278
- window.addEventListener("popstate", onLocationChange);
276
+ window.addEventListener('navigate', onLocationChange);
277
+ window.addEventListener('pushsatate', onLocationChange);
278
+ window.addEventListener('popstate', onLocationChange);
279
279
 
280
280
  return () => {
281
- window.removeEventListener("navigate", onLocationChange);
282
- window.removeEventListener("pushsatate", onLocationChange);
283
- window.removeEventListener("popstate", onLocationChange);
284
- };
281
+ window.removeEventListener('navigate', onLocationChange);
282
+ window.removeEventListener('pushsatate', onLocationChange);
283
+ window.removeEventListener('popstate', onLocationChange);
284
+ }
285
285
  }, [currentPath]);
286
286
 
287
- return currentPath === path ? component() : null;
287
+ return currentPath === path ? component() : null
288
288
  };
289
289
 
290
290
  const Navigate = (props) => {
291
291
  if (props.style) {
292
292
  throw new Error(
293
- "The style attribute is not supported on internal components, use className."
294
- );
293
+ 'The style attribute is not supported on internal components, use className.',
294
+ )
295
295
  }
296
- if (props.to === "") {
297
- throw new Error("'to=' cannot be empty.");
296
+ if (props.to === '') {
297
+ throw new Error("'to=' cannot be empty.")
298
298
  }
299
- if (props.className === "") {
300
- throw new Error("className cannot be empty.");
299
+ if (props.className === '') {
300
+ throw new Error('className cannot be empty.')
301
301
  }
302
- if (props.label === "" && !props.children) {
303
- throw new Error("'label=' cannot be empty.");
302
+ if (props.label === '' && !props.children) {
303
+ throw new Error("'label=' cannot be empty.")
304
304
  }
305
305
 
306
306
  if (!props.to) {
307
- throw new Error("Missig 'to' param.");
307
+ throw new Error("Missig 'to' param.")
308
308
  }
309
309
  const preventReload = (event) => {
310
310
  event.preventDefault();
311
311
  if (window.location.pathname !== props.to) {
312
- window.history.pushState({}, "", props.to);
313
- const navigationEvent = new Event("pushsatate");
312
+ window.history.pushState({}, '', props.to);
313
+ const navigationEvent = new Event('pushsatate');
314
314
  window.dispatchEvent(navigationEvent);
315
315
  }
316
316
  };
@@ -323,7 +323,7 @@
323
323
 
324
324
  const children = props.label ? props.label : props.children;
325
325
 
326
- return createElement("a", anchor, children);
326
+ return createElement('a', anchor, children)
327
327
  };
328
328
 
329
329
  /**
@@ -339,12 +339,12 @@
339
339
  const createDom = (fiber) => {
340
340
  const dom =
341
341
  fiber.type == RYUNIX_TYPES.TEXT_ELEMENT
342
- ? document.createTextNode("")
342
+ ? document.createTextNode('')
343
343
  : document.createElement(fiber.type);
344
344
 
345
345
  updateDom(dom, {}, fiber.props);
346
346
 
347
- return dom;
347
+ return dom
348
348
  };
349
349
 
350
350
  /**
@@ -367,7 +367,7 @@
367
367
  .filter(isProperty)
368
368
  .filter(isGone(nextProps))
369
369
  .forEach((name) => {
370
- dom[name] = "";
370
+ dom[name] = '';
371
371
  });
372
372
 
373
373
  Object.keys(nextProps)
@@ -377,8 +377,8 @@
377
377
  if (name === STRINGS.style) {
378
378
  DomStyle(dom, nextProps.style);
379
379
  } else if (name === STRINGS.className) {
380
- if (nextProps.className === "") {
381
- throw new Error("className cannot be empty.");
380
+ if (nextProps.className === '') {
381
+ throw new Error('className cannot be empty.')
382
382
  }
383
383
  prevProps.className &&
384
384
  dom.classList.remove(...prevProps.className.split(/\s+/));
@@ -400,11 +400,11 @@
400
400
  const DomStyle = (dom, style) => {
401
401
  dom.style = Object.keys(style).reduce((acc, styleName) => {
402
402
  const key = styleName.replace(reg, function (v) {
403
- return "-" + v.toLowerCase();
403
+ return '-' + v.toLowerCase()
404
404
  });
405
405
  acc += `${key}: ${style[styleName]};`;
406
- return acc;
407
- }, "");
406
+ return acc
407
+ }, '');
408
408
  };
409
409
 
410
410
  var Dom = /*#__PURE__*/Object.freeze({
@@ -433,7 +433,7 @@
433
433
  */
434
434
  const commitWork = (fiber) => {
435
435
  if (!fiber) {
436
- return;
436
+ return
437
437
  }
438
438
 
439
439
  let domParentFiber = fiber.parent;
@@ -456,7 +456,7 @@
456
456
  } else if (fiber.effectTag === EFFECT_TAGS.DELETION) {
457
457
  cancelEffects(fiber);
458
458
  commitDeletion(fiber, domParent);
459
- return;
459
+ return
460
460
  }
461
461
 
462
462
  commitWork(fiber.child);
@@ -628,12 +628,12 @@
628
628
  updateHostComponent(fiber);
629
629
  }
630
630
  if (fiber.child) {
631
- return fiber.child;
631
+ return fiber.child
632
632
  }
633
633
  let nextFiber = fiber;
634
634
  while (nextFiber) {
635
635
  if (nextFiber.sibling) {
636
- return nextFiber.sibling;
636
+ return nextFiber.sibling
637
637
  }
638
638
  nextFiber = nextFiber.parent;
639
639
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unsetsoft/ryunixjs",
3
- "version": "0.4.10-nightly.0",
3
+ "version": "0.4.11-nightly.0",
4
4
  "license": "MIT",
5
5
  "main": "./dist/Ryunix.js",
6
6
  "private": false,
@@ -10,7 +10,7 @@
10
10
  "homepage": "https://github.com/UnSetSoft/Ryunixjs#readme",
11
11
  "scripts": {
12
12
  "build": "rollup ./src/main.js --file ./dist/Ryunix.js --format umd --name Ryunix",
13
- "prepublish": "npm run build",
13
+ "prepublishOnly": "npm run build",
14
14
  "postinstall": "npm run build",
15
15
  "nightly:release": "npm publish --tag nightly",
16
16
  "release": "npm publish"
@@ -27,4 +27,4 @@
27
27
  "publishConfig": {
28
28
  "registry": "https://registry.npmjs.org"
29
29
  }
30
- }
30
+ }
@@ -1,16 +1,16 @@
1
- import { updateDom } from "./dom";
2
- import { cancelEffects, runEffects } from "./effects";
3
- import { EFFECT_TAGS, vars } from "../utils/index";
1
+ import { updateDom } from './dom'
2
+ import { cancelEffects, runEffects } from './effects'
3
+ import { EFFECT_TAGS, vars } from '../utils/index'
4
4
 
5
5
  /**
6
6
  * The function commits changes made to the virtual DOM to the actual DOM.
7
7
  */
8
8
  const commitRoot = () => {
9
- vars.deletions.forEach(commitWork);
10
- commitWork(vars.wipRoot.child);
11
- vars.currentRoot = vars.wipRoot;
12
- vars.wipRoot = null;
13
- };
9
+ vars.deletions.forEach(commitWork)
10
+ commitWork(vars.wipRoot.child)
11
+ vars.currentRoot = vars.wipRoot
12
+ vars.wipRoot = null
13
+ }
14
14
 
15
15
  /**
16
16
  * The function commits changes made to the DOM based on the effect tag of the fiber.
@@ -21,35 +21,35 @@ const commitRoot = () => {
21
21
  */
22
22
  const commitWork = (fiber) => {
23
23
  if (!fiber) {
24
- return;
24
+ return
25
25
  }
26
26
 
27
- let domParentFiber = fiber.parent;
27
+ let domParentFiber = fiber.parent
28
28
  while (!domParentFiber.dom) {
29
- domParentFiber = domParentFiber.parent;
29
+ domParentFiber = domParentFiber.parent
30
30
  }
31
- const domParent = domParentFiber.dom;
31
+ const domParent = domParentFiber.dom
32
32
 
33
33
  if (fiber.effectTag === EFFECT_TAGS.PLACEMENT) {
34
34
  if (fiber.dom != null) {
35
- domParent.appendChild(fiber.dom);
35
+ domParent.appendChild(fiber.dom)
36
36
  }
37
- runEffects(fiber);
37
+ runEffects(fiber)
38
38
  } else if (fiber.effectTag === EFFECT_TAGS.UPDATE) {
39
- cancelEffects(fiber);
39
+ cancelEffects(fiber)
40
40
  if (fiber.dom != null) {
41
- updateDom(fiber.dom, fiber.alternate.props, fiber.props);
41
+ updateDom(fiber.dom, fiber.alternate.props, fiber.props)
42
42
  }
43
- runEffects(fiber);
43
+ runEffects(fiber)
44
44
  } else if (fiber.effectTag === EFFECT_TAGS.DELETION) {
45
- cancelEffects(fiber);
46
- commitDeletion(fiber, domParent);
47
- return;
45
+ cancelEffects(fiber)
46
+ commitDeletion(fiber, domParent)
47
+ return
48
48
  }
49
49
 
50
- commitWork(fiber.child);
51
- commitWork(fiber.sibling);
52
- };
50
+ commitWork(fiber.child)
51
+ commitWork(fiber.sibling)
52
+ }
53
53
 
54
54
  /**
55
55
  * The function removes a fiber's corresponding DOM node from its parent node or recursively removes
@@ -60,10 +60,10 @@ const commitWork = (fiber) => {
60
60
  */
61
61
  const commitDeletion = (fiber, domParent) => {
62
62
  if (fiber.dom) {
63
- domParent.removeChild(fiber.dom);
63
+ domParent.removeChild(fiber.dom)
64
64
  } else {
65
- commitDeletion(fiber.child, domParent);
65
+ commitDeletion(fiber.child, domParent)
66
66
  }
67
- };
67
+ }
68
68
 
69
- export { commitDeletion, commitWork, commitRoot };
69
+ export { commitDeletion, commitWork, commitRoot }
@@ -1,6 +1,6 @@
1
- import { createDom } from "./dom";
2
- import { reconcileChildren } from "./reconciler";
3
- import { vars } from "../utils/index";
1
+ import { createDom } from './dom'
2
+ import { reconcileChildren } from './reconciler'
3
+ import { vars } from '../utils/index'
4
4
 
5
5
  /**
6
6
  * This function updates a function component by setting up a work-in-progress fiber, resetting the
@@ -10,12 +10,12 @@ import { vars } from "../utils/index";
10
10
  * used to update the state of the component and its children.
11
11
  */
12
12
  const updateFunctionComponent = (fiber) => {
13
- vars.wipFiber = fiber;
14
- vars.hookIndex = 0;
15
- vars.wipFiber.hooks = [];
16
- const children = [fiber.type(fiber.props)];
17
- reconcileChildren(fiber, children);
18
- };
13
+ vars.wipFiber = fiber
14
+ vars.hookIndex = 0
15
+ vars.wipFiber.hooks = []
16
+ const children = [fiber.type(fiber.props)]
17
+ reconcileChildren(fiber, children)
18
+ }
19
19
 
20
20
  /**
21
21
  * This function updates a host component's DOM element and reconciles its children.
@@ -25,9 +25,9 @@ const updateFunctionComponent = (fiber) => {
25
25
  */
26
26
  const updateHostComponent = (fiber) => {
27
27
  if (!fiber.dom) {
28
- fiber.dom = createDom(fiber);
28
+ fiber.dom = createDom(fiber)
29
29
  }
30
- reconcileChildren(fiber, fiber.props.children.flat());
31
- };
30
+ reconcileChildren(fiber, fiber.props.children.flat())
31
+ }
32
32
 
33
- export { updateFunctionComponent, updateHostComponent };
33
+ export { updateFunctionComponent, updateHostComponent }
@@ -1,4 +1,4 @@
1
- import { RYUNIX_TYPES, STRINGS } from "../utils/index";
1
+ import { RYUNIX_TYPES, STRINGS } from '../utils/index'
2
2
 
3
3
  /**
4
4
  * The function creates a new element with the given type, props, and children.
@@ -25,11 +25,11 @@ const createElement = (type, props, ...children) => {
25
25
  children: children
26
26
  .flat()
27
27
  .map((child) =>
28
- typeof child === STRINGS.object ? child : createTextElement(child)
28
+ typeof child === STRINGS.object ? child : createTextElement(child),
29
29
  ),
30
30
  },
31
- };
32
- };
31
+ }
32
+ }
33
33
 
34
34
  /**
35
35
  * The function creates a text element with a given text value.
@@ -45,19 +45,17 @@ const createTextElement = (text) => {
45
45
  nodeValue: text,
46
46
  children: [],
47
47
  },
48
- };
49
- };
48
+ }
49
+ }
50
50
 
51
51
  const Fragments = (props) => {
52
52
  if (props.style) {
53
- throw new Error("The style attribute is not supported");
53
+ throw new Error('The style attribute is not supported')
54
54
  }
55
- if (props.className === "") {
56
- throw new Error("className cannot be empty.");
55
+ if (props.className === '') {
56
+ throw new Error('className cannot be empty.')
57
57
  }
58
- return createElement("div", props, props.children);
59
- };
60
-
61
-
58
+ return createElement('div', props, props.children)
59
+ }
62
60
 
63
- export { createElement, createTextElement, Fragments };
61
+ export { createElement, createTextElement, Fragments }
package/src/lib/dom.js CHANGED
@@ -1,5 +1,5 @@
1
- import { isEvent, isGone, isNew, isProperty } from "./effects";
2
- import { RYUNIX_TYPES, STRINGS, reg } from "../utils/index";
1
+ import { isEvent, isGone, isNew, isProperty } from './effects'
2
+ import { RYUNIX_TYPES, STRINGS, reg } from '../utils/index'
3
3
 
4
4
  /**
5
5
  * The function creates a new DOM element based on the given fiber object and updates its properties.
@@ -14,13 +14,13 @@ import { RYUNIX_TYPES, STRINGS, reg } from "../utils/index";
14
14
  const createDom = (fiber) => {
15
15
  const dom =
16
16
  fiber.type == RYUNIX_TYPES.TEXT_ELEMENT
17
- ? document.createTextNode("")
18
- : document.createElement(fiber.type);
17
+ ? document.createTextNode('')
18
+ : document.createElement(fiber.type)
19
19
 
20
- updateDom(dom, {}, fiber.props);
20
+ updateDom(dom, {}, fiber.props)
21
21
 
22
- return dom;
23
- };
22
+ return dom
23
+ }
24
24
 
25
25
  /**
26
26
  * The function updates the DOM by removing old event listeners and properties, and adding new ones
@@ -34,52 +34,52 @@ const updateDom = (dom, prevProps, nextProps) => {
34
34
  .filter(isEvent)
35
35
  .filter((key) => isGone(nextProps)(key) || isNew(prevProps, nextProps)(key))
36
36
  .forEach((name) => {
37
- const eventType = name.toLowerCase().substring(2);
38
- dom.removeEventListener(eventType, prevProps[name]);
39
- });
37
+ const eventType = name.toLowerCase().substring(2)
38
+ dom.removeEventListener(eventType, prevProps[name])
39
+ })
40
40
 
41
41
  Object.keys(prevProps)
42
42
  .filter(isProperty)
43
43
  .filter(isGone(nextProps))
44
44
  .forEach((name) => {
45
- dom[name] = "";
46
- });
45
+ dom[name] = ''
46
+ })
47
47
 
48
48
  Object.keys(nextProps)
49
49
  .filter(isProperty)
50
50
  .filter(isNew(prevProps, nextProps))
51
51
  .forEach((name) => {
52
52
  if (name === STRINGS.style) {
53
- DomStyle(dom, nextProps.style);
53
+ DomStyle(dom, nextProps.style)
54
54
  } else if (name === STRINGS.className) {
55
- if (nextProps.className === "") {
56
- throw new Error("className cannot be empty.");
55
+ if (nextProps.className === '') {
56
+ throw new Error('className cannot be empty.')
57
57
  }
58
58
  prevProps.className &&
59
- dom.classList.remove(...prevProps.className.split(/\s+/));
60
- dom.classList.add(...nextProps.className.split(/\s+/));
59
+ dom.classList.remove(...prevProps.className.split(/\s+/))
60
+ dom.classList.add(...nextProps.className.split(/\s+/))
61
61
  } else {
62
- dom[name] = nextProps[name];
62
+ dom[name] = nextProps[name]
63
63
  }
64
- });
64
+ })
65
65
 
66
66
  Object.keys(nextProps)
67
67
  .filter(isEvent)
68
68
  .filter(isNew(prevProps, nextProps))
69
69
  .forEach((name) => {
70
- const eventType = name.toLowerCase().substring(2);
71
- dom.addEventListener(eventType, nextProps[name]);
72
- });
73
- };
70
+ const eventType = name.toLowerCase().substring(2)
71
+ dom.addEventListener(eventType, nextProps[name])
72
+ })
73
+ }
74
74
 
75
75
  const DomStyle = (dom, style) => {
76
76
  dom.style = Object.keys(style).reduce((acc, styleName) => {
77
77
  const key = styleName.replace(reg, function (v) {
78
- return "-" + v.toLowerCase();
79
- });
80
- acc += `${key}: ${style[styleName]};`;
81
- return acc;
82
- }, "");
83
- };
78
+ return '-' + v.toLowerCase()
79
+ })
80
+ acc += `${key}: ${style[styleName]};`
81
+ return acc
82
+ }, '')
83
+ }
84
84
 
85
- export { DomStyle, createDom, updateDom };
85
+ export { DomStyle, createDom, updateDom }
@@ -1,14 +1,14 @@
1
- import { RYUNIX_TYPES, STRINGS } from "../utils/index";
1
+ import { RYUNIX_TYPES, STRINGS } from '../utils/index'
2
2
 
3
- const isEvent = (key) => key.startsWith("on");
4
- const isProperty = (key) => key !== STRINGS.children && !isEvent(key);
5
- const isNew = (prev, next) => (key) => prev[key] !== next[key];
6
- const isGone = (next) => (key) => !(key in next);
3
+ const isEvent = (key) => key.startsWith('on')
4
+ const isProperty = (key) => key !== STRINGS.children && !isEvent(key)
5
+ const isNew = (prev, next) => (key) => prev[key] !== next[key]
6
+ const isGone = (next) => (key) => !(key in next)
7
7
  const hasDepsChanged = (prevDeps, nextDeps) =>
8
8
  !prevDeps ||
9
9
  !nextDeps ||
10
10
  prevDeps.length !== nextDeps.length ||
11
- prevDeps.some((dep, index) => dep !== nextDeps[index]);
11
+ prevDeps.some((dep, index) => dep !== nextDeps[index])
12
12
 
13
13
  /**
14
14
  * The function cancels all effect hooks in a given fiber.
@@ -22,10 +22,10 @@ const cancelEffects = (fiber) => {
22
22
  fiber.hooks
23
23
  .filter((hook) => hook.tag === RYUNIX_TYPES.RYUNIX_EFFECT && hook.cancel)
24
24
  .forEach((effectHook) => {
25
- effectHook.cancel();
26
- });
25
+ effectHook.cancel()
26
+ })
27
27
  }
28
- };
28
+ }
29
29
 
30
30
  /**
31
31
  * The function runs all effect hooks in a given fiber.
@@ -39,10 +39,10 @@ const runEffects = (fiber) => {
39
39
  fiber.hooks
40
40
  .filter((hook) => hook.tag === RYUNIX_TYPES.RYUNIX_EFFECT && hook.effect)
41
41
  .forEach((effectHook) => {
42
- effectHook.cancel = effectHook.effect();
43
- });
42
+ effectHook.cancel = effectHook.effect()
43
+ })
44
44
  }
45
- };
45
+ }
46
46
 
47
47
  export {
48
48
  runEffects,
@@ -52,4 +52,4 @@ export {
52
52
  isNew,
53
53
  isGone,
54
54
  hasDepsChanged,
55
- };
55
+ }
package/src/lib/hooks.js CHANGED
@@ -1,6 +1,5 @@
1
- import { hasDepsChanged } from "./effects";
2
- import { RYUNIX_TYPES, STRINGS, vars } from "../utils/index";
3
-
1
+ import { hasDepsChanged } from './effects'
2
+ import { RYUNIX_TYPES, STRINGS, vars } from '../utils/index'
4
3
 
5
4
  /**
6
5
  * @description The function creates a state.
@@ -12,17 +11,17 @@ const useStore = (initial) => {
12
11
  const oldHook =
13
12
  vars.wipFiber.alternate &&
14
13
  vars.wipFiber.alternate.hooks &&
15
- vars.wipFiber.alternate.hooks[vars.hookIndex];
14
+ vars.wipFiber.alternate.hooks[vars.hookIndex]
16
15
  const hook = {
17
16
  state: oldHook ? oldHook.state : initial,
18
17
  queue: [],
19
- };
18
+ }
20
19
 
21
- const actions = oldHook ? oldHook.queue : [];
20
+ const actions = oldHook ? oldHook.queue : []
22
21
  actions.forEach((action) => {
23
22
  hook.state =
24
- typeof action === STRINGS.function ? action(hook.state) : action;
25
- });
23
+ typeof action === STRINGS.function ? action(hook.state) : action
24
+ })
26
25
 
27
26
  /**
28
27
  * The function `setState` updates the state of a component in Ryunix by adding an action to a queue
@@ -32,20 +31,20 @@ const useStore = (initial) => {
32
31
  * that needs to be applied to the component's state.
33
32
  */
34
33
  const setState = (action) => {
35
- hook.queue.push(action);
34
+ hook.queue.push(action)
36
35
  vars.wipRoot = {
37
36
  dom: vars.currentRoot.dom,
38
37
  props: vars.currentRoot.props,
39
38
  alternate: vars.currentRoot,
40
- };
41
- vars.nextUnitOfWork = vars.wipRoot;
42
- vars.deletions = [];
43
- };
39
+ }
40
+ vars.nextUnitOfWork = vars.wipRoot
41
+ vars.deletions = []
42
+ }
44
43
 
45
- vars.wipFiber.hooks.push(hook);
46
- vars.hookIndex++;
47
- return [hook.state, setState];
48
- };
44
+ vars.wipFiber.hooks.push(hook)
45
+ vars.hookIndex++
46
+ return [hook.state, setState]
47
+ }
49
48
 
50
49
  /**
51
50
  * This is a function that creates a hook for managing side effects in Ryunix components.
@@ -60,43 +59,43 @@ const useEffect = (effect, deps) => {
60
59
  const oldHook =
61
60
  vars.wipFiber.alternate &&
62
61
  vars.wipFiber.alternate.hooks &&
63
- vars.wipFiber.alternate.hooks[vars.hookIndex];
62
+ vars.wipFiber.alternate.hooks[vars.hookIndex]
64
63
 
65
- const hasChanged = hasDepsChanged(oldHook ? oldHook.deps : undefined, deps);
64
+ const hasChanged = hasDepsChanged(oldHook ? oldHook.deps : undefined, deps)
66
65
 
67
66
  const hook = {
68
67
  tag: RYUNIX_TYPES.RYUNIX_EFFECT,
69
68
  effect: hasChanged ? effect : null,
70
69
  cancel: hasChanged && oldHook && oldHook.cancel,
71
70
  deps,
72
- };
71
+ }
73
72
 
74
- vars.wipFiber.hooks.push(hook);
75
- vars.hookIndex++;
76
- };
73
+ vars.wipFiber.hooks.push(hook)
74
+ vars.hookIndex++
75
+ }
77
76
 
78
77
  const useQuery = () => {
79
- vars.hookIndex++;
78
+ vars.hookIndex++
80
79
 
81
80
  const oldHook =
82
81
  vars.wipFiber.alternate &&
83
82
  vars.wipFiber.alternate.hooks &&
84
- vars.wipFiber.alternate.hooks[vars.hookIndex];
83
+ vars.wipFiber.alternate.hooks[vars.hookIndex]
85
84
 
86
- const hasOld = oldHook ? oldHook : undefined;
85
+ const hasOld = oldHook ? oldHook : undefined
87
86
 
88
- const urlSearchParams = new URLSearchParams(window.location.search);
89
- const params = Object.fromEntries(urlSearchParams.entries());
90
- const Query = hasOld ? hasOld : params;
87
+ const urlSearchParams = new URLSearchParams(window.location.search)
88
+ const params = Object.fromEntries(urlSearchParams.entries())
89
+ const Query = hasOld ? hasOld : params
91
90
 
92
91
  const hook = {
93
92
  tag: RYUNIX_TYPES.RYUNIX_EFFECT,
94
93
  query: Query,
95
- };
94
+ }
96
95
 
97
- vars.wipFiber.hooks.push(hook);
96
+ vars.wipFiber.hooks.push(hook)
98
97
 
99
- return hook.query;
100
- };
98
+ return hook.query
99
+ }
101
100
 
102
- export { useStore, useEffect, useQuery };
101
+ export { useStore, useEffect, useQuery }
package/src/lib/index.js CHANGED
@@ -1,14 +1,14 @@
1
- import { createElement, Fragments } from "./createElement";
2
- import { render, init } from "./render";
3
- import { useStore, useEffect, useQuery } from "./hooks";
4
- import { Router, Navigate } from "./navigation";
5
- import * as Dom from "./dom";
6
- import * as Workers from "./workers";
7
- import * as Reconciler from "./reconciler";
8
- import * as Components from "./components";
9
- import * as Commits from "./commits";
1
+ import { createElement, Fragments } from './createElement'
2
+ import { render, init } from './render'
3
+ import { useStore, useEffect, useQuery } from './hooks'
4
+ import { Router, Navigate } from './navigation'
5
+ import * as Dom from './dom'
6
+ import * as Workers from './workers'
7
+ import * as Reconciler from './reconciler'
8
+ import * as Components from './components'
9
+ import * as Commits from './commits'
10
10
 
11
- export { useStore, useEffect, useQuery, Fragments, Router, Navigate };
11
+ export { useStore, useEffect, useQuery, Fragments, Router, Navigate }
12
12
 
13
13
  export default {
14
14
  createElement,
@@ -20,4 +20,4 @@ export default {
20
20
  Reconciler,
21
21
  Components,
22
22
  Commits,
23
- };
23
+ }
@@ -1,64 +1,64 @@
1
- import { useStore, useEffect } from "./hooks";
2
- import { createElement } from "./createElement";
1
+ import { useStore, useEffect } from './hooks'
2
+ import { createElement } from './createElement'
3
3
  const Router = ({ path, component }) => {
4
- const [currentPath, setCurrentPath] = useStore(window.location.pathname);
4
+ const [currentPath, setCurrentPath] = useStore(window.location.pathname)
5
5
 
6
6
  useEffect(() => {
7
7
  const onLocationChange = () => {
8
- setCurrentPath(() => window.location.pathname);
9
- };
8
+ setCurrentPath(() => window.location.pathname)
9
+ }
10
10
 
11
- window.addEventListener("navigate", onLocationChange);
12
- window.addEventListener("pushsatate", onLocationChange);
13
- window.addEventListener("popstate", onLocationChange);
11
+ window.addEventListener('navigate', onLocationChange)
12
+ window.addEventListener('pushsatate', onLocationChange)
13
+ window.addEventListener('popstate', onLocationChange)
14
14
 
15
15
  return () => {
16
- window.removeEventListener("navigate", onLocationChange);
17
- window.removeEventListener("pushsatate", onLocationChange);
18
- window.removeEventListener("popstate", onLocationChange);
19
- };
20
- }, [currentPath]);
16
+ window.removeEventListener('navigate', onLocationChange)
17
+ window.removeEventListener('pushsatate', onLocationChange)
18
+ window.removeEventListener('popstate', onLocationChange)
19
+ }
20
+ }, [currentPath])
21
21
 
22
- return currentPath === path ? component() : null;
23
- };
22
+ return currentPath === path ? component() : null
23
+ }
24
24
 
25
25
  const Navigate = (props) => {
26
26
  if (props.style) {
27
27
  throw new Error(
28
- "The style attribute is not supported on internal components, use className."
29
- );
28
+ 'The style attribute is not supported on internal components, use className.',
29
+ )
30
30
  }
31
- if (props.to === "") {
32
- throw new Error("'to=' cannot be empty.");
31
+ if (props.to === '') {
32
+ throw new Error("'to=' cannot be empty.")
33
33
  }
34
- if (props.className === "") {
35
- throw new Error("className cannot be empty.");
34
+ if (props.className === '') {
35
+ throw new Error('className cannot be empty.')
36
36
  }
37
- if (props.label === "" && !props.children) {
38
- throw new Error("'label=' cannot be empty.");
37
+ if (props.label === '' && !props.children) {
38
+ throw new Error("'label=' cannot be empty.")
39
39
  }
40
40
 
41
41
  if (!props.to) {
42
- throw new Error("Missig 'to' param.");
42
+ throw new Error("Missig 'to' param.")
43
43
  }
44
44
  const preventReload = (event) => {
45
- event.preventDefault();
45
+ event.preventDefault()
46
46
  if (window.location.pathname !== props.to) {
47
- window.history.pushState({}, "", props.to);
48
- const navigationEvent = new Event("pushsatate");
49
- window.dispatchEvent(navigationEvent);
47
+ window.history.pushState({}, '', props.to)
48
+ const navigationEvent = new Event('pushsatate')
49
+ window.dispatchEvent(navigationEvent)
50
50
  }
51
- };
51
+ }
52
52
 
53
53
  const anchor = {
54
54
  href: props.to,
55
55
  onClick: preventReload,
56
56
  ...props,
57
- };
57
+ }
58
58
 
59
- const children = props.label ? props.label : props.children;
59
+ const children = props.label ? props.label : props.children
60
60
 
61
- return createElement("a", anchor, children);
62
- };
61
+ return createElement('a', anchor, children)
62
+ }
63
63
 
64
- export { Router, Navigate };
64
+ export { Router, Navigate }
@@ -1,4 +1,4 @@
1
- import { EFFECT_TAGS, vars } from "../utils/index";
1
+ import { EFFECT_TAGS, vars } from '../utils/index'
2
2
 
3
3
  /**
4
4
  * This function reconciles the children of a fiber node with a new set of elements, creating new
@@ -10,15 +10,15 @@ import { EFFECT_TAGS, vars } from "../utils/index";
10
10
  * fiber's subtree
11
11
  */
12
12
  const reconcileChildren = (wipFiber, elements) => {
13
- let index = 0;
14
- let oldFiber = wipFiber.alternate && wipFiber.alternate.child;
15
- let prevSibling;
13
+ let index = 0
14
+ let oldFiber = wipFiber.alternate && wipFiber.alternate.child
15
+ let prevSibling
16
16
 
17
17
  while (index < elements.length || oldFiber != null) {
18
- const element = elements[index];
19
- let newFiber;
18
+ const element = elements[index]
19
+ let newFiber
20
20
 
21
- const sameType = oldFiber && element && element.type == oldFiber.type;
21
+ const sameType = oldFiber && element && element.type == oldFiber.type
22
22
 
23
23
  if (sameType) {
24
24
  newFiber = {
@@ -28,7 +28,7 @@ const reconcileChildren = (wipFiber, elements) => {
28
28
  parent: wipFiber,
29
29
  alternate: oldFiber,
30
30
  effectTag: EFFECT_TAGS.UPDATE,
31
- };
31
+ }
32
32
  }
33
33
  if (element && !sameType) {
34
34
  newFiber = {
@@ -38,25 +38,25 @@ const reconcileChildren = (wipFiber, elements) => {
38
38
  parent: wipFiber,
39
39
  alternate: null,
40
40
  effectTag: EFFECT_TAGS.PLACEMENT,
41
- };
41
+ }
42
42
  }
43
43
  if (oldFiber && !sameType) {
44
- oldFiber.effectTag = EFFECT_TAGS.DELETION;
45
- vars.deletions.push(oldFiber);
44
+ oldFiber.effectTag = EFFECT_TAGS.DELETION
45
+ vars.deletions.push(oldFiber)
46
46
  }
47
47
 
48
48
  if (oldFiber) {
49
- oldFiber = oldFiber.sibling;
49
+ oldFiber = oldFiber.sibling
50
50
  }
51
51
 
52
52
  if (index === 0) {
53
- wipFiber.child = newFiber;
53
+ wipFiber.child = newFiber
54
54
  } else if (element) {
55
- prevSibling.sibling = newFiber;
55
+ prevSibling.sibling = newFiber
56
56
  }
57
57
 
58
- prevSibling = newFiber;
59
- index++;
58
+ prevSibling = newFiber
59
+ index++
60
60
  }
61
- };
62
- export { reconcileChildren };
61
+ }
62
+ export { reconcileChildren }
package/src/lib/render.js CHANGED
@@ -1,4 +1,4 @@
1
- import { vars } from "../utils/index";
1
+ import { vars } from '../utils/index'
2
2
 
3
3
  /**
4
4
  * The function renders an element into a container using a work-in-progress root.
@@ -14,10 +14,10 @@ const render = (element, container) => {
14
14
  children: [element],
15
15
  },
16
16
  alternate: vars.currentRoot,
17
- };
18
- vars.deletions = [];
19
- vars.nextUnitOfWork = vars.wipRoot;
20
- };
17
+ }
18
+ vars.deletions = []
19
+ vars.nextUnitOfWork = vars.wipRoot
20
+ }
21
21
 
22
22
  /**
23
23
  * @description The function creates a reference to a DOM element with the specified ID. This will be used to initialize the app.
@@ -26,8 +26,8 @@ const render = (element, container) => {
26
26
  * for the root element.
27
27
  */
28
28
  const init = (root) => {
29
- const rootElement = root || "__ryunix";
30
- vars.containerRoot = document.getElementById(rootElement);
31
- };
29
+ const rootElement = root || '__ryunix'
30
+ vars.containerRoot = document.getElementById(rootElement)
31
+ }
32
32
 
33
- export { render, init };
33
+ export { render, init }
@@ -1,6 +1,6 @@
1
- import { commitRoot } from "./commits";
2
- import { updateFunctionComponent, updateHostComponent } from "./components";
3
- import { vars } from "../utils/index";
1
+ import { commitRoot } from './commits'
2
+ import { updateFunctionComponent, updateHostComponent } from './components'
3
+ import { vars } from '../utils/index'
4
4
 
5
5
  /**
6
6
  * This function uses requestIdleCallback to perform work on a fiber tree until it is complete or the
@@ -11,20 +11,20 @@ import { vars } from "../utils/index";
11
11
  * is used to determine
12
12
  */
13
13
  const workLoop = (deadline) => {
14
- let shouldYield = false;
14
+ let shouldYield = false
15
15
  while (vars.nextUnitOfWork && !shouldYield) {
16
- vars.nextUnitOfWork = performUnitOfWork(vars.nextUnitOfWork);
17
- shouldYield = deadline.timeRemaining() < 1;
16
+ vars.nextUnitOfWork = performUnitOfWork(vars.nextUnitOfWork)
17
+ shouldYield = deadline.timeRemaining() < 1
18
18
  }
19
19
 
20
20
  if (!vars.nextUnitOfWork && vars.wipRoot) {
21
- commitRoot();
21
+ commitRoot()
22
22
  }
23
23
 
24
- requestIdleCallback(workLoop);
25
- };
24
+ requestIdleCallback(workLoop)
25
+ }
26
26
 
27
- requestIdleCallback(workLoop);
27
+ requestIdleCallback(workLoop)
28
28
 
29
29
  /**
30
30
  * The function performs a unit of work by updating either a function component or a host component and
@@ -39,22 +39,22 @@ requestIdleCallback(workLoop);
39
39
  * sibling of the parent. The function returns `null` if there are no more fibers to process.
40
40
  */
41
41
  const performUnitOfWork = (fiber) => {
42
- const isFunctionComponent = fiber.type instanceof Function;
42
+ const isFunctionComponent = fiber.type instanceof Function
43
43
  if (isFunctionComponent) {
44
- updateFunctionComponent(fiber);
44
+ updateFunctionComponent(fiber)
45
45
  } else {
46
- updateHostComponent(fiber);
46
+ updateHostComponent(fiber)
47
47
  }
48
48
  if (fiber.child) {
49
- return fiber.child;
49
+ return fiber.child
50
50
  }
51
- let nextFiber = fiber;
51
+ let nextFiber = fiber
52
52
  while (nextFiber) {
53
53
  if (nextFiber.sibling) {
54
- return nextFiber.sibling;
54
+ return nextFiber.sibling
55
55
  }
56
- nextFiber = nextFiber.parent;
56
+ nextFiber = nextFiber.parent
57
57
  }
58
- };
58
+ }
59
59
 
60
- export { performUnitOfWork, workLoop };
60
+ export { performUnitOfWork, workLoop }
package/src/main.js CHANGED
@@ -1,4 +1,4 @@
1
- import Ryunix from "./lib/index.js";
1
+ import Ryunix from './lib/index.js'
2
2
  export {
3
3
  useStore,
4
4
  useEffect,
@@ -6,8 +6,8 @@ export {
6
6
  Fragments,
7
7
  Navigate,
8
8
  Router,
9
- } from "./lib/index.js";
9
+ } from './lib/index.js'
10
10
 
11
- window.Ryunix = Ryunix;
11
+ window.Ryunix = Ryunix
12
12
 
13
- export default Ryunix;
13
+ export default Ryunix
@@ -6,28 +6,28 @@ const vars = {
6
6
  deletions: null,
7
7
  wipFiber: null,
8
8
  hookIndex: null,
9
- };
9
+ }
10
10
 
11
- const reg = /[A-Z]/g;
11
+ const reg = /[A-Z]/g
12
12
 
13
13
  const RYUNIX_TYPES = Object.freeze({
14
- TEXT_ELEMENT: Symbol("text.element"),
15
- RYUNIX_EFFECT: Symbol("ryunix.effect"),
16
- RYUNIX_CONTEXT: Symbol("ryunix.context"),
17
- });
14
+ TEXT_ELEMENT: Symbol('text.element'),
15
+ RYUNIX_EFFECT: Symbol('ryunix.effect'),
16
+ RYUNIX_CONTEXT: Symbol('ryunix.context'),
17
+ })
18
18
 
19
19
  const STRINGS = Object.freeze({
20
- object: "object",
21
- function: "function",
22
- style: "style",
23
- className: "className",
24
- children: "children",
25
- });
20
+ object: 'object',
21
+ function: 'function',
22
+ style: 'style',
23
+ className: 'className',
24
+ children: 'children',
25
+ })
26
26
 
27
27
  const EFFECT_TAGS = Object.freeze({
28
28
  PLACEMENT: Symbol(),
29
29
  UPDATE: Symbol(),
30
30
  DELETION: Symbol(),
31
- });
31
+ })
32
32
 
33
- export { vars, reg, RYUNIX_TYPES, EFFECT_TAGS, STRINGS };
33
+ export { vars, reg, RYUNIX_TYPES, EFFECT_TAGS, STRINGS }