@unsetsoft/ryunixjs 0.4.13-nightly.5 → 0.4.14

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.
@@ -0,0 +1,33 @@
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 }
@@ -0,0 +1,60 @@
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.ts ADDED
@@ -0,0 +1,12 @@
1
+ import Ryunix from './lib/index.js'
2
+ export {
3
+ useStore,
4
+ useEffect,
5
+ useQuery,
6
+ Fragments,
7
+ Navigate,
8
+ Router,
9
+ Link,
10
+ } from './lib/index.js'
11
+
12
+ export default Ryunix
@@ -18,9 +18,14 @@ const RYUNIX_TYPES = Object.freeze({
18
18
  const STRINGS = Object.freeze({
19
19
  object: 'object',
20
20
  function: 'function',
21
+ style: 'ryunix-style',
22
+ className: 'ryunix-class',
23
+ children: 'children',
24
+ })
25
+
26
+ const OLD_STRINGS = Object.freeze({
21
27
  style: 'style',
22
28
  className: 'className',
23
- children: 'children',
24
29
  })
25
30
 
26
31
  const EFFECT_TAGS = Object.freeze({
@@ -29,4 +34,4 @@ const EFFECT_TAGS = Object.freeze({
29
34
  DELETION: Symbol(),
30
35
  })
31
36
 
32
- export { vars, reg, RYUNIX_TYPES, EFFECT_TAGS, STRINGS }
37
+ export { vars, reg, RYUNIX_TYPES, EFFECT_TAGS, STRINGS, OLD_STRINGS }
@@ -0,0 +1,32 @@
1
+ const vars = Object.freeze({
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 }