@unsetsoft/ryunixjs 0.4.9 → 0.4.10
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 +1 -2
- package/dist/Ryunix.js +239 -229
- package/package.json +1 -1
- package/src/lib/commits.js +27 -27
- package/src/lib/components.js +13 -13
- package/src/lib/createElement.js +12 -14
- package/src/lib/dom.js +30 -30
- package/src/lib/effects.js +13 -13
- package/src/lib/hooks.js +33 -34
- package/src/lib/index.js +11 -11
- package/src/lib/navigation.js +34 -34
- package/src/lib/reconciler.js +18 -18
- package/src/lib/render.js +9 -9
- package/src/lib/workers.js +19 -19
- package/src/main.js +4 -4
- package/src/utils/index.js +14 -14
package/package.json
CHANGED
package/src/lib/commits.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { updateDom } from
|
|
2
|
-
import { cancelEffects, runEffects } from
|
|
3
|
-
import { EFFECT_TAGS, vars } from
|
|
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 }
|
package/src/lib/components.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createDom } from
|
|
2
|
-
import { reconcileChildren } from
|
|
3
|
-
import { vars } from
|
|
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 }
|
package/src/lib/createElement.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RYUNIX_TYPES, STRINGS } from
|
|
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(
|
|
53
|
+
throw new Error('The style attribute is not supported')
|
|
54
54
|
}
|
|
55
|
-
if (props.className ===
|
|
56
|
-
throw new Error(
|
|
55
|
+
if (props.className === '') {
|
|
56
|
+
throw new Error('className cannot be empty.')
|
|
57
57
|
}
|
|
58
|
-
return createElement(
|
|
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
|
|
2
|
-
import { RYUNIX_TYPES, STRINGS, reg } from
|
|
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(
|
|
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
|
|
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 }
|
package/src/lib/effects.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { RYUNIX_TYPES, STRINGS } from
|
|
1
|
+
import { RYUNIX_TYPES, STRINGS } from '../utils/index'
|
|
2
2
|
|
|
3
|
-
const isEvent = (key) => key.startsWith(
|
|
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
|
|
2
|
-
import { RYUNIX_TYPES, STRINGS, vars } from
|
|
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
|
|
2
|
-
import { render, init } from
|
|
3
|
-
import { useStore, useEffect, useQuery } from
|
|
4
|
-
import { Router, Navigate } from
|
|
5
|
-
import * as Dom from
|
|
6
|
-
import * as Workers from
|
|
7
|
-
import * as Reconciler from
|
|
8
|
-
import * as Components from
|
|
9
|
-
import * as Commits from
|
|
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
|
+
}
|
package/src/lib/navigation.js
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import { useStore, useEffect } from
|
|
2
|
-
import { createElement } from
|
|
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(
|
|
12
|
-
window.addEventListener(
|
|
13
|
-
window.addEventListener(
|
|
11
|
+
window.addEventListener('navigate', onLocationChange)
|
|
12
|
+
window.addEventListener('pushsatate', onLocationChange)
|
|
13
|
+
window.addEventListener('popstate', onLocationChange)
|
|
14
14
|
|
|
15
15
|
return () => {
|
|
16
|
-
window.removeEventListener(
|
|
17
|
-
window.removeEventListener(
|
|
18
|
-
window.removeEventListener(
|
|
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
|
-
|
|
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(
|
|
34
|
+
if (props.className === '') {
|
|
35
|
+
throw new Error('className cannot be empty.')
|
|
36
36
|
}
|
|
37
|
-
if (props.label ===
|
|
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({},
|
|
48
|
-
const navigationEvent = new Event(
|
|
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(
|
|
62
|
-
}
|
|
61
|
+
return createElement('a', anchor, children)
|
|
62
|
+
}
|
|
63
63
|
|
|
64
|
-
export { Router, Navigate }
|
|
64
|
+
export { Router, Navigate }
|
package/src/lib/reconciler.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EFFECT_TAGS, vars } from
|
|
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 }
|