@unsetsoft/ryunixjs 0.4.13-nightly.0 → 0.4.13-nightly.16

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.
@@ -286,7 +286,30 @@
286
286
  return currentPath === path ? component() : null
287
287
  };
288
288
 
289
- const Navigate = (props) => {
289
+ const Navigate = () => {
290
+ /**
291
+ * The function `push` is used to push a new state to the browser's history and trigger a custom
292
+ * event called 'pushstate'.
293
+ * @param to - The `to` parameter is a string representing the URL path to which you want to
294
+ * navigate.
295
+ * @param [state] - The `state` parameter is an optional object that represents the state associated
296
+ * with the new history entry. It can be used to store any data that you want to associate with the
297
+ * new URL. When you navigate back or forward in the browser history, this state object will be
298
+ * passed to the `popstate
299
+ * @returns The function `push` does not have a return statement, so it returns `undefined` by
300
+ * default.
301
+ */
302
+ const push = (to, state = {}) => {
303
+ if (window.location.pathname === to) return
304
+ window.history.pushState(state, '', to);
305
+ const navigationEvent = new Event('pushsatate');
306
+ window.dispatchEvent(navigationEvent);
307
+ };
308
+
309
+ return { push }
310
+ };
311
+
312
+ const Link = (props) => {
290
313
  if (props.style) {
291
314
  throw new Error(
292
315
  'The style attribute is not supported on internal components, use className.',
@@ -307,11 +330,8 @@
307
330
  }
308
331
  const preventReload = (event) => {
309
332
  event.preventDefault();
310
- if (window.location.pathname !== props.to) {
311
- window.history.pushState({}, '', props.to);
312
- const navigationEvent = new Event('pushsatate');
313
- window.dispatchEvent(navigationEvent);
314
- }
333
+ const { push } = Navigate();
334
+ push(props.to);
315
335
  };
316
336
 
317
337
  const anchor = {
@@ -659,6 +679,7 @@
659
679
  window.Ryunix = Ryunix;
660
680
 
661
681
  exports.Fragments = Fragments;
682
+ exports.Link = Link;
662
683
  exports.Navigate = Navigate;
663
684
  exports.Router = Router;
664
685
  exports.default = Ryunix;
package/package.json CHANGED
@@ -1,22 +1,32 @@
1
1
  {
2
2
  "name": "@unsetsoft/ryunixjs",
3
- "version": "0.4.13-nightly.0",
3
+ "version": "0.4.13-nightly.16",
4
4
  "license": "MIT",
5
5
  "main": "./dist/Ryunix.js",
6
+ "types": "./dist/Ryunix.d.ts",
6
7
  "private": false,
7
8
  "bugs": {
8
9
  "url": "https://github.com/UnSetSoft/Ryunixjs/issues"
9
10
  },
10
11
  "homepage": "https://github.com/UnSetSoft/Ryunixjs#readme",
11
12
  "scripts": {
12
- "build": "rollup ./src/main.js --file ./dist/Ryunix.js --format umd --name Ryunix",
13
- "prepublishOnly": "npm run build",
14
- "postinstall": "npm run build",
13
+ "build:ts": "npm run lint && tsc",
14
+ "build:js": "rollup ./src/main.js --file ./dist/cj/Ryunix.js --format umd --name Ryunix",
15
+ "prepublishOnly": "npm run build:js",
16
+ "postinstall": "npm run build:js",
15
17
  "nightly:release": "npm publish --tag nightly",
16
- "release": "npm publish"
18
+ "release": "npm publish",
19
+ "lint": "eslint . --ext .ts --fix --max-warnings=0 --config .eslintrc.js --no-eslintrc"
17
20
  },
18
21
  "dependencies": {
19
- "rollup": "3.24.0"
22
+ "eslint": "8.56.0",
23
+ "@typescript-eslint/parser": "6.17.0",
24
+ "@typescript-eslint/eslint-plugin": "6.17.0",
25
+ "rollup": "4.9.2",
26
+ "ts-node": "10.9.2",
27
+ "tsup": "8.0.1",
28
+ "typescript": "5.3.3",
29
+ "tslint": "6.1.3"
20
30
  },
21
31
  "engines": {
22
32
  "node": ">=18.16.0"
@@ -26,5 +36,8 @@
26
36
  ],
27
37
  "publishConfig": {
28
38
  "registry": "https://registry.npmjs.org"
29
- }
39
+ },
40
+ "files": [
41
+ "dist"
42
+ ]
30
43
  }
@@ -1,69 +0,0 @@
1
- import { updateDom } from './dom'
2
- import { cancelEffects, runEffects } from './effects'
3
- import { EFFECT_TAGS, vars } from '../utils/index'
4
-
5
- /**
6
- * The function commits changes made to the virtual DOM to the actual DOM.
7
- */
8
- const commitRoot = () => {
9
- vars.deletions.forEach(commitWork)
10
- commitWork(vars.wipRoot.child)
11
- vars.currentRoot = vars.wipRoot
12
- vars.wipRoot = null
13
- }
14
-
15
- /**
16
- * The function commits changes made to the DOM based on the effect tag of the fiber.
17
- * @param fiber - A fiber is a unit of work in Ryunix's reconciliation process. It represents a
18
- * component and its state at a particular point in time. The `commitWork` function takes a fiber as a
19
- * parameter to commit the changes made during the reconciliation process to the actual DOM.
20
- * @returns The function does not return anything, it performs side effects by manipulating the DOM.
21
- */
22
- const commitWork = (fiber) => {
23
- if (!fiber) {
24
- return
25
- }
26
-
27
- let domParentFiber = fiber.parent
28
- while (!domParentFiber.dom) {
29
- domParentFiber = domParentFiber.parent
30
- }
31
- const domParent = domParentFiber.dom
32
-
33
- if (fiber.effectTag === EFFECT_TAGS.PLACEMENT) {
34
- if (fiber.dom != null) {
35
- domParent.appendChild(fiber.dom)
36
- }
37
- runEffects(fiber)
38
- } else if (fiber.effectTag === EFFECT_TAGS.UPDATE) {
39
- cancelEffects(fiber)
40
- if (fiber.dom != null) {
41
- updateDom(fiber.dom, fiber.alternate.props, fiber.props)
42
- }
43
- runEffects(fiber)
44
- } else if (fiber.effectTag === EFFECT_TAGS.DELETION) {
45
- cancelEffects(fiber)
46
- commitDeletion(fiber, domParent)
47
- return
48
- }
49
-
50
- commitWork(fiber.child)
51
- commitWork(fiber.sibling)
52
- }
53
-
54
- /**
55
- * The function removes a fiber's corresponding DOM node from its parent node or recursively removes
56
- * its child's DOM node until it finds a node to remove.
57
- * @param fiber - a fiber node in a fiber tree, which represents a component or an element in the Ryunix
58
- * application.
59
- * @param domParent - The parent DOM element from which the fiber's DOM element needs to be removed.
60
- */
61
- const commitDeletion = (fiber, domParent) => {
62
- if (fiber.dom) {
63
- domParent.removeChild(fiber.dom)
64
- } else {
65
- commitDeletion(fiber.child, domParent)
66
- }
67
- }
68
-
69
- export { commitDeletion, commitWork, commitRoot }
@@ -1,33 +0,0 @@
1
- import { createDom } from './dom'
2
- import { reconcileChildren } from './reconciler'
3
- import { vars } from '../utils/index'
4
-
5
- /**
6
- * This function updates a function component by setting up a work-in-progress fiber, resetting the
7
- * hook index, creating an empty hooks array, rendering the component, and reconciling its children.
8
- * @param fiber - The fiber parameter is an object that represents a node in the fiber tree. It
9
- * contains information about the component, its props, state, and children. In this function, it is
10
- * used to update the state of the component and its children.
11
- */
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
- }
19
-
20
- /**
21
- * This function updates a host component's DOM element and reconciles its children.
22
- * @param fiber - A fiber is a unit of work in Ryunix that represents a component and its state. It
23
- * contains information about the component's type, props, and children, as well as pointers to other
24
- * fibers in the tree.
25
- */
26
- const updateHostComponent = (fiber) => {
27
- if (!fiber.dom) {
28
- fiber.dom = createDom(fiber)
29
- }
30
- reconcileChildren(fiber, fiber.props.children.flat())
31
- }
32
-
33
- export { updateFunctionComponent, updateHostComponent }
@@ -1,61 +0,0 @@
1
- import { RYUNIX_TYPES, STRINGS } from '../utils/index'
2
-
3
- /**
4
- * The function creates a new element with the given type, props, and children.
5
- * @param type - The type of the element to be created, such as "div", "span", "h1", etc.
6
- * @param props - The `props` parameter is an object that contains the properties or attributes of the
7
- * element being created. These properties can include things like `className`, `id`, `style`, and any
8
- * other custom attributes that the user wants to add to the element. The `props` object is spread
9
- * using the spread
10
- * @param children - The `children` parameter is a rest parameter that allows the function to accept
11
- * any number of arguments after the `props` parameter. These arguments will be treated as children
12
- * elements of the created element. The `map` function is used to iterate over each child and create a
13
- * new element if it is not
14
- * @returns A JavaScript object with a `type` property and a `props` property. The `type` property is
15
- * set to the `type` argument passed into the function, and the `props` property is an object that
16
- * includes any additional properties passed in the `props` argument, as well as a `children` property
17
- * that is an array of any child elements passed in the `...children` argument
18
- */
19
-
20
- const createElement = (type, props, ...children) => {
21
- return {
22
- type,
23
- props: {
24
- ...props,
25
- children: children
26
- .flat()
27
- .map((child) =>
28
- typeof child === STRINGS.object ? child : createTextElement(child),
29
- ),
30
- },
31
- }
32
- }
33
-
34
- /**
35
- * The function creates a text element with a given text value.
36
- * @param text - The text content that will be used to create a new text element.
37
- * @returns A JavaScript object with a `type` property set to `"TEXT_ELEMENT"` and a `props` property
38
- * that contains a `nodeValue` property set to the `text` parameter and an empty `children` array.
39
- */
40
-
41
- const createTextElement = (text) => {
42
- return {
43
- type: RYUNIX_TYPES.TEXT_ELEMENT,
44
- props: {
45
- nodeValue: text,
46
- children: [],
47
- },
48
- }
49
- }
50
-
51
- const Fragments = (props) => {
52
- if (props.style) {
53
- throw new Error('The style attribute is not supported')
54
- }
55
- if (props.className === '') {
56
- throw new Error('className cannot be empty.')
57
- }
58
- return createElement('div', props, props.children)
59
- }
60
-
61
- export { createElement, createTextElement, Fragments }
package/src/lib/dom.js DELETED
@@ -1,85 +0,0 @@
1
- import { isEvent, isGone, isNew, isProperty } from './effects'
2
- import { RYUNIX_TYPES, STRINGS, reg } from '../utils/index'
3
-
4
- /**
5
- * The function creates a new DOM element based on the given fiber object and updates its properties.
6
- * @param fiber - The fiber parameter is an object that represents a node in the fiber tree. It
7
- * contains information about the element type, props, and children of the node.
8
- * @returns The `createDom` function returns a newly created DOM element based on the `fiber` object
9
- * passed as an argument. If the `fiber` object represents a text element, a text node is created using
10
- * `document.createTextNode("")`. Otherwise, a new element is created using
11
- * `document.createElement(fiber.type)`. The function then calls the `updateDom` function to update the
12
- * properties of the newly created
13
- */
14
- const createDom = (fiber) => {
15
- const dom =
16
- fiber.type == RYUNIX_TYPES.TEXT_ELEMENT
17
- ? document.createTextNode('')
18
- : document.createElement(fiber.type)
19
-
20
- updateDom(dom, {}, fiber.props)
21
-
22
- return dom
23
- }
24
-
25
- /**
26
- * The function updates the DOM by removing old event listeners and properties, and adding new ones
27
- * based on the previous and next props.
28
- * @param dom - The DOM element that needs to be updated with new props.
29
- * @param prevProps - An object representing the previous props (properties) of a DOM element.
30
- * @param nextProps - An object containing the new props that need to be updated in the DOM.
31
- */
32
- const updateDom = (dom, prevProps, nextProps) => {
33
- Object.keys(prevProps)
34
- .filter(isEvent)
35
- .filter((key) => isGone(nextProps)(key) || isNew(prevProps, nextProps)(key))
36
- .forEach((name) => {
37
- const eventType = name.toLowerCase().substring(2)
38
- dom.removeEventListener(eventType, prevProps[name])
39
- })
40
-
41
- Object.keys(prevProps)
42
- .filter(isProperty)
43
- .filter(isGone(nextProps))
44
- .forEach((name) => {
45
- dom[name] = ''
46
- })
47
-
48
- Object.keys(nextProps)
49
- .filter(isProperty)
50
- .filter(isNew(prevProps, nextProps))
51
- .forEach((name) => {
52
- if (name === STRINGS.style) {
53
- DomStyle(dom, nextProps.style)
54
- } else if (name === STRINGS.className) {
55
- if (nextProps.className === '') {
56
- throw new Error('className cannot be empty.')
57
- }
58
- prevProps.className &&
59
- dom.classList.remove(...prevProps.className.split(/\s+/))
60
- dom.classList.add(...nextProps.className.split(/\s+/))
61
- } else {
62
- dom[name] = nextProps[name]
63
- }
64
- })
65
-
66
- Object.keys(nextProps)
67
- .filter(isEvent)
68
- .filter(isNew(prevProps, nextProps))
69
- .forEach((name) => {
70
- const eventType = name.toLowerCase().substring(2)
71
- dom.addEventListener(eventType, nextProps[name])
72
- })
73
- }
74
-
75
- const DomStyle = (dom, style) => {
76
- dom.style = Object.keys(style).reduce((acc, styleName) => {
77
- const key = styleName.replace(reg, function (v) {
78
- return '-' + v.toLowerCase()
79
- })
80
- acc += `${key}: ${style[styleName]};`
81
- return acc
82
- }, '')
83
- }
84
-
85
- export { DomStyle, createDom, updateDom }
@@ -1,55 +0,0 @@
1
- import { RYUNIX_TYPES, STRINGS } from '../utils/index'
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)
7
- const hasDepsChanged = (prevDeps, nextDeps) =>
8
- !prevDeps ||
9
- !nextDeps ||
10
- prevDeps.length !== nextDeps.length ||
11
- prevDeps.some((dep, index) => dep !== nextDeps[index])
12
-
13
- /**
14
- * The function cancels all effect hooks in a given fiber.
15
- * @param fiber - The "fiber" parameter is likely referring to a data structure used in React.js to
16
- * represent a component and its state. It contains information about the component's props, state, and
17
- * children, as well as metadata used by React to manage updates and rendering. The function
18
- * "cancelEffects" is likely intended
19
- */
20
- const cancelEffects = (fiber) => {
21
- if (fiber.hooks) {
22
- fiber.hooks
23
- .filter((hook) => hook.tag === RYUNIX_TYPES.RYUNIX_EFFECT && hook.cancel)
24
- .forEach((effectHook) => {
25
- effectHook.cancel()
26
- })
27
- }
28
- }
29
-
30
- /**
31
- * The function runs all effect hooks in a given fiber.
32
- * @param fiber - The "fiber" parameter is likely referring to a data structure used in the
33
- * implementation of a fiber-based reconciliation algorithm, such as the one used in React. A fiber
34
- * represents a unit of work that needs to be performed by the reconciliation algorithm, and it
35
- * contains information about a component and its children, as
36
- */
37
- const runEffects = (fiber) => {
38
- if (fiber.hooks) {
39
- fiber.hooks
40
- .filter((hook) => hook.tag === RYUNIX_TYPES.RYUNIX_EFFECT && hook.effect)
41
- .forEach((effectHook) => {
42
- effectHook.cancel = effectHook.effect()
43
- })
44
- }
45
- }
46
-
47
- export {
48
- runEffects,
49
- cancelEffects,
50
- isEvent,
51
- isProperty,
52
- isNew,
53
- isGone,
54
- hasDepsChanged,
55
- }
package/src/lib/hooks.js DELETED
@@ -1,101 +0,0 @@
1
- import { hasDepsChanged } from './effects'
2
- import { RYUNIX_TYPES, STRINGS, vars } from '../utils/index'
3
-
4
- /**
5
- * @description The function creates a state.
6
- * @param initial - The initial value of the state for the hook.
7
- * @returns The `useStore` function returns an array with two elements: the current state value and a
8
- * `setState` function that can be used to update the state.
9
- */
10
- const useStore = (initial) => {
11
- const oldHook =
12
- vars.wipFiber.alternate &&
13
- vars.wipFiber.alternate.hooks &&
14
- vars.wipFiber.alternate.hooks[vars.hookIndex]
15
- const hook = {
16
- state: oldHook ? oldHook.state : initial,
17
- queue: [],
18
- }
19
-
20
- const actions = oldHook ? oldHook.queue : []
21
- actions.forEach((action) => {
22
- hook.state =
23
- typeof action === STRINGS.function ? action(hook.state) : action
24
- })
25
-
26
- /**
27
- * The function `setState` updates the state of a component in Ryunix by adding an action to a queue
28
- * and setting up a new work-in-progress root.
29
- * @param action - The `action` parameter is an object that represents a state update to be performed
30
- * on a component. It contains information about the type of update to be performed and any new data
31
- * that needs to be applied to the component's state.
32
- */
33
- const setState = (action) => {
34
- hook.queue.push(action)
35
- vars.wipRoot = {
36
- dom: vars.currentRoot.dom,
37
- props: vars.currentRoot.props,
38
- alternate: vars.currentRoot,
39
- }
40
- vars.nextUnitOfWork = vars.wipRoot
41
- vars.deletions = []
42
- }
43
-
44
- vars.wipFiber.hooks.push(hook)
45
- vars.hookIndex++
46
- return [hook.state, setState]
47
- }
48
-
49
- /**
50
- * This is a function that creates a hook for managing side effects in Ryunix components.
51
- * @param effect - The effect function that will be executed after the component has rendered or when
52
- * the dependencies have changed. It can perform side effects such as fetching data, updating the DOM,
53
- * or subscribing to events.
54
- * @param deps - An array of dependencies that the effect depends on. If any of the dependencies change
55
- * between renders, the effect will be re-run. If the array is empty, the effect will only run once on
56
- * mount and never again.
57
- */
58
- const useEffect = (effect, deps) => {
59
- const oldHook =
60
- vars.wipFiber.alternate &&
61
- vars.wipFiber.alternate.hooks &&
62
- vars.wipFiber.alternate.hooks[vars.hookIndex]
63
-
64
- const hasChanged = hasDepsChanged(oldHook ? oldHook.deps : undefined, deps)
65
-
66
- const hook = {
67
- tag: RYUNIX_TYPES.RYUNIX_EFFECT,
68
- effect: hasChanged ? effect : null,
69
- cancel: hasChanged && oldHook && oldHook.cancel,
70
- deps,
71
- }
72
-
73
- vars.wipFiber.hooks.push(hook)
74
- vars.hookIndex++
75
- }
76
-
77
- const useQuery = () => {
78
- vars.hookIndex++
79
-
80
- const oldHook =
81
- vars.wipFiber.alternate &&
82
- vars.wipFiber.alternate.hooks &&
83
- vars.wipFiber.alternate.hooks[vars.hookIndex]
84
-
85
- const hasOld = oldHook ? oldHook : undefined
86
-
87
- const urlSearchParams = new URLSearchParams(window.location.search)
88
- const params = Object.fromEntries(urlSearchParams.entries())
89
- const Query = hasOld ? hasOld : params
90
-
91
- const hook = {
92
- tag: RYUNIX_TYPES.RYUNIX_EFFECT,
93
- query: Query,
94
- }
95
-
96
- vars.wipFiber.hooks.push(hook)
97
-
98
- return hook.query
99
- }
100
-
101
- export { useStore, useEffect, useQuery }
package/src/lib/index.js DELETED
@@ -1,23 +0,0 @@
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
-
11
- export { useStore, useEffect, useQuery, Fragments, Router, Navigate }
12
-
13
- export default {
14
- createElement,
15
- render,
16
- init,
17
- Fragments,
18
- Dom,
19
- Workers,
20
- Reconciler,
21
- Components,
22
- Commits,
23
- }
@@ -1,64 +0,0 @@
1
- import { useStore, useEffect } from './hooks'
2
- import { createElement } from './createElement'
3
- const Router = ({ path, component }) => {
4
- const [currentPath, setCurrentPath] = useStore(window.location.pathname)
5
-
6
- useEffect(() => {
7
- const onLocationChange = () => {
8
- setCurrentPath(() => window.location.pathname)
9
- }
10
-
11
- window.addEventListener('navigate', onLocationChange)
12
- window.addEventListener('pushsatate', onLocationChange)
13
- window.addEventListener('popstate', onLocationChange)
14
-
15
- return () => {
16
- window.removeEventListener('navigate', onLocationChange)
17
- window.removeEventListener('pushsatate', onLocationChange)
18
- window.removeEventListener('popstate', onLocationChange)
19
- }
20
- }, [currentPath])
21
-
22
- return currentPath === path ? component() : null
23
- }
24
-
25
- const Navigate = (props) => {
26
- if (props.style) {
27
- throw new Error(
28
- 'The style attribute is not supported on internal components, use className.',
29
- )
30
- }
31
- if (props.to === '') {
32
- throw new Error("'to=' cannot be empty.")
33
- }
34
- if (props.className === '') {
35
- throw new Error('className cannot be empty.')
36
- }
37
- if (props.label === '' && !props.children) {
38
- throw new Error("'label=' cannot be empty.")
39
- }
40
-
41
- if (!props.to) {
42
- throw new Error("Missig 'to' param.")
43
- }
44
- const preventReload = (event) => {
45
- event.preventDefault()
46
- if (window.location.pathname !== props.to) {
47
- window.history.pushState({}, '', props.to)
48
- const navigationEvent = new Event('pushsatate')
49
- window.dispatchEvent(navigationEvent)
50
- }
51
- }
52
-
53
- const anchor = {
54
- href: props.to,
55
- onClick: preventReload,
56
- ...props,
57
- }
58
-
59
- const children = props.label ? props.label : props.children
60
-
61
- return createElement('a', anchor, children)
62
- }
63
-
64
- export { Router, Navigate }
@@ -1,62 +0,0 @@
1
- import { EFFECT_TAGS, vars } from '../utils/index'
2
-
3
- /**
4
- * This function reconciles the children of a fiber node with a new set of elements, creating new
5
- * fibers for new elements, updating existing fibers for elements with the same type, and marking old
6
- * fibers for deletion if they are not present in the new set of elements.
7
- * @param wipFiber - A work-in-progress fiber object representing a component or element in the virtual
8
- * DOM tree.
9
- * @param elements - an array of elements representing the new children to be rendered in the current
10
- * fiber's subtree
11
- */
12
- const reconcileChildren = (wipFiber, elements) => {
13
- let index = 0
14
- let oldFiber = wipFiber.alternate && wipFiber.alternate.child
15
- let prevSibling
16
-
17
- while (index < elements.length || oldFiber != null) {
18
- const element = elements[index]
19
- let newFiber
20
-
21
- const sameType = oldFiber && element && element.type == oldFiber.type
22
-
23
- if (sameType) {
24
- newFiber = {
25
- type: oldFiber.type,
26
- props: element.props,
27
- dom: oldFiber.dom,
28
- parent: wipFiber,
29
- alternate: oldFiber,
30
- effectTag: EFFECT_TAGS.UPDATE,
31
- }
32
- }
33
- if (element && !sameType) {
34
- newFiber = {
35
- type: element.type,
36
- props: element.props,
37
- dom: null,
38
- parent: wipFiber,
39
- alternate: null,
40
- effectTag: EFFECT_TAGS.PLACEMENT,
41
- }
42
- }
43
- if (oldFiber && !sameType) {
44
- oldFiber.effectTag = EFFECT_TAGS.DELETION
45
- vars.deletions.push(oldFiber)
46
- }
47
-
48
- if (oldFiber) {
49
- oldFiber = oldFiber.sibling
50
- }
51
-
52
- if (index === 0) {
53
- wipFiber.child = newFiber
54
- } else if (element) {
55
- prevSibling.sibling = newFiber
56
- }
57
-
58
- prevSibling = newFiber
59
- index++
60
- }
61
- }
62
- export { reconcileChildren }
package/src/lib/render.js DELETED
@@ -1,33 +0,0 @@
1
- import { vars } from '../utils/index'
2
-
3
- /**
4
- * The function renders an element into a container using a work-in-progress root.
5
- * @param element - The element parameter is the component or element that needs to be rendered in the
6
- * container. It could be a Ryunix component or a DOM element.
7
- * @param container - The container parameter is the DOM element where the rendered element will be
8
- * appended to. this parameter is optional if you use createRoot().
9
- */
10
- const render = (element, container) => {
11
- vars.wipRoot = {
12
- dom: vars.containerRoot || container,
13
- props: {
14
- children: [element],
15
- },
16
- alternate: vars.currentRoot,
17
- }
18
- vars.deletions = []
19
- vars.nextUnitOfWork = vars.wipRoot
20
- }
21
-
22
- /**
23
- * @description The function creates a reference to a DOM element with the specified ID. This will be used to initialize the app.
24
- * @example Ryunix.init("root") -> <div id="root" />
25
- * @param root - The parameter "root" is the id of the HTML element that will serve as the container
26
- * for the root element.
27
- */
28
- const init = (root) => {
29
- const rootElement = root || '__ryunix'
30
- vars.containerRoot = document.getElementById(rootElement)
31
- }
32
-
33
- export { render, init }
@@ -1,60 +0,0 @@
1
- import { commitRoot } from './commits'
2
- import { updateFunctionComponent, updateHostComponent } from './components'
3
- import { vars } from '../utils/index'
4
-
5
- /**
6
- * This function uses requestIdleCallback to perform work on a fiber tree until it is complete or the
7
- * browser needs to yield to other tasks.
8
- * @param deadline - The `deadline` parameter is an object that represents the amount of time the
9
- * browser has to perform work before it needs to handle other tasks. It has a `timeRemaining()` method
10
- * that returns the amount of time remaining before the deadline is reached. The `shouldYield` variable
11
- * is used to determine
12
- */
13
- const workLoop = (deadline) => {
14
- let shouldYield = false
15
- while (vars.nextUnitOfWork && !shouldYield) {
16
- vars.nextUnitOfWork = performUnitOfWork(vars.nextUnitOfWork)
17
- shouldYield = deadline.timeRemaining() < 1
18
- }
19
-
20
- if (!vars.nextUnitOfWork && vars.wipRoot) {
21
- commitRoot()
22
- }
23
-
24
- requestIdleCallback(workLoop)
25
- }
26
-
27
- requestIdleCallback(workLoop)
28
-
29
- /**
30
- * The function performs a unit of work by updating either a function component or a host component and
31
- * returns the next fiber to be processed.
32
- * @param fiber - A fiber is a unit of work in Ryunix that represents a component and its state. It
33
- * contains information about the component's type, props, and children, as well as pointers to its
34
- * parent, child, and sibling fibers. The `performUnitOfWork` function takes a fiber as a parameter and
35
- * performs work
36
- * @returns The function `performUnitOfWork` returns the next fiber to be processed. If the current
37
- * fiber has a child, it returns the child. Otherwise, it looks for the next sibling of the current
38
- * fiber. If there are no more siblings, it goes up the tree to the parent and looks for the next
39
- * sibling of the parent. The function returns `null` if there are no more fibers to process.
40
- */
41
- const performUnitOfWork = (fiber) => {
42
- const isFunctionComponent = fiber.type instanceof Function
43
- if (isFunctionComponent) {
44
- updateFunctionComponent(fiber)
45
- } else {
46
- updateHostComponent(fiber)
47
- }
48
- if (fiber.child) {
49
- return fiber.child
50
- }
51
- let nextFiber = fiber
52
- while (nextFiber) {
53
- if (nextFiber.sibling) {
54
- return nextFiber.sibling
55
- }
56
- nextFiber = nextFiber.parent
57
- }
58
- }
59
-
60
- export { performUnitOfWork, workLoop }
package/src/main.js DELETED
@@ -1,13 +0,0 @@
1
- import Ryunix from './lib/index.js'
2
- export {
3
- useStore,
4
- useEffect,
5
- useQuery,
6
- Fragments,
7
- Navigate,
8
- Router,
9
- } from './lib/index.js'
10
-
11
- window.Ryunix = Ryunix
12
-
13
- export default Ryunix
@@ -1,32 +0,0 @@
1
- const vars = {
2
- containerRoot: null,
3
- nextUnitOfWork: null,
4
- currentRoot: null,
5
- wipRoot: null,
6
- deletions: null,
7
- wipFiber: null,
8
- hookIndex: null,
9
- }
10
-
11
- const reg = /[A-Z]/g
12
-
13
- const RYUNIX_TYPES = Object.freeze({
14
- TEXT_ELEMENT: Symbol('text.element'),
15
- RYUNIX_EFFECT: Symbol('ryunix.effect'),
16
- })
17
-
18
- const STRINGS = Object.freeze({
19
- object: 'object',
20
- function: 'function',
21
- style: 'style',
22
- className: 'className',
23
- children: 'children',
24
- })
25
-
26
- const EFFECT_TAGS = Object.freeze({
27
- PLACEMENT: Symbol(),
28
- UPDATE: Symbol(),
29
- DELETION: Symbol(),
30
- })
31
-
32
- export { vars, reg, RYUNIX_TYPES, EFFECT_TAGS, STRINGS }