@unsetsoft/ryunixjs 0.2.28 → 0.2.29-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/dist/Ryunix.js +95 -441
- package/package.json +2 -2
- package/src/lib/commits.js +69 -0
- package/src/lib/components.js +33 -0
- package/src/lib/createContext.js +24 -0
- package/src/lib/createElement.js +61 -0
- package/src/lib/dom.js +85 -0
- package/src/lib/effects.js +55 -0
- package/src/lib/hooks.js +101 -0
- package/src/lib/index.js +14 -0
- package/src/lib/reconciler.js +62 -0
- package/src/lib/render.js +32 -0
- package/src/lib/workers.js +60 -0
- package/{lib → src}/main.js +2 -2
- package/src/utils/index.js +33 -0
- package/lib/dom.js +0 -592
package/dist/Ryunix.js
CHANGED
|
@@ -4,44 +4,29 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Ryunix = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
const vars = {
|
|
8
|
+
containerRoot: null,
|
|
9
|
+
nextUnitOfWork: null,
|
|
10
|
+
currentRoot: null,
|
|
11
|
+
wipRoot: null,
|
|
12
|
+
deletions: null,
|
|
13
|
+
wipFiber: null,
|
|
14
|
+
hookIndex: null,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const RYUNIX_TYPES = Object.freeze({
|
|
16
18
|
TEXT_ELEMENT: Symbol("text.element"),
|
|
17
19
|
RYUNIX_EFFECT: Symbol("ryunix.effect"),
|
|
18
20
|
RYUNIX_CONTEXT: Symbol("ryunix.context"),
|
|
19
|
-
};
|
|
21
|
+
});
|
|
20
22
|
|
|
21
|
-
const STRINGS = {
|
|
23
|
+
const STRINGS = Object.freeze({
|
|
22
24
|
object: "object",
|
|
23
25
|
function: "function",
|
|
24
26
|
style: "style",
|
|
25
27
|
className: "className",
|
|
26
28
|
children: "children",
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const EFFECT_TAGS = {
|
|
30
|
-
PLACEMENT: Symbol(),
|
|
31
|
-
UPDATE: Symbol(),
|
|
32
|
-
DELETION: Symbol(),
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const isEvent = (key) => key.startsWith("on");
|
|
36
|
-
const isProperty = (key) => key !== STRINGS.children && !isEvent(key);
|
|
37
|
-
const isNew = (prev, next) => (key) => prev[key] !== next[key];
|
|
38
|
-
const isGone = (next) => (key) => !(key in next);
|
|
39
|
-
const reg = /[A-Z]/g;
|
|
40
|
-
const hasDepsChanged = (prevDeps, nextDeps) =>
|
|
41
|
-
!prevDeps ||
|
|
42
|
-
!nextDeps ||
|
|
43
|
-
prevDeps.length !== nextDeps.length ||
|
|
44
|
-
prevDeps.some((dep, index) => dep !== nextDeps[index]);
|
|
29
|
+
});
|
|
45
30
|
|
|
46
31
|
/**
|
|
47
32
|
* The function creates a new element with the given type, props, and children.
|
|
@@ -59,7 +44,8 @@
|
|
|
59
44
|
* includes any additional properties passed in the `props` argument, as well as a `children` property
|
|
60
45
|
* that is an array of any child elements passed in the `...children` argument
|
|
61
46
|
*/
|
|
62
|
-
|
|
47
|
+
|
|
48
|
+
const createElement = (type, props, ...children) => {
|
|
63
49
|
return {
|
|
64
50
|
type,
|
|
65
51
|
props: {
|
|
@@ -71,7 +57,7 @@
|
|
|
71
57
|
),
|
|
72
58
|
},
|
|
73
59
|
};
|
|
74
|
-
}
|
|
60
|
+
};
|
|
75
61
|
|
|
76
62
|
/**
|
|
77
63
|
* The function creates a text element with a given text value.
|
|
@@ -79,7 +65,8 @@
|
|
|
79
65
|
* @returns A JavaScript object with a `type` property set to `"TEXT_ELEMENT"` and a `props` property
|
|
80
66
|
* that contains a `nodeValue` property set to the `text` parameter and an empty `children` array.
|
|
81
67
|
*/
|
|
82
|
-
|
|
68
|
+
|
|
69
|
+
const createTextElement = (text) => {
|
|
83
70
|
return {
|
|
84
71
|
type: RYUNIX_TYPES.TEXT_ELEMENT,
|
|
85
72
|
props: {
|
|
@@ -87,211 +74,17 @@
|
|
|
87
74
|
children: [],
|
|
88
75
|
},
|
|
89
76
|
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* The function creates a new DOM element based on the given fiber object and updates its properties.
|
|
94
|
-
* @param fiber - The fiber parameter is an object that represents a node in the fiber tree. It
|
|
95
|
-
* contains information about the element type, props, and children of the node.
|
|
96
|
-
* @returns The `createDom` function returns a newly created DOM element based on the `fiber` object
|
|
97
|
-
* passed as an argument. If the `fiber` object represents a text element, a text node is created using
|
|
98
|
-
* `document.createTextNode("")`. Otherwise, a new element is created using
|
|
99
|
-
* `document.createElement(fiber.type)`. The function then calls the `updateDom` function to update the
|
|
100
|
-
* properties of the newly created
|
|
101
|
-
*/
|
|
102
|
-
function createDom(fiber) {
|
|
103
|
-
const dom =
|
|
104
|
-
fiber.type == RYUNIX_TYPES.TEXT_ELEMENT
|
|
105
|
-
? document.createTextNode("")
|
|
106
|
-
: document.createElement(fiber.type);
|
|
107
|
-
|
|
108
|
-
updateDom(dom, {}, fiber.props);
|
|
109
|
-
|
|
110
|
-
return dom;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* The function updates the DOM by removing old event listeners and properties, and adding new ones
|
|
115
|
-
* based on the previous and next props.
|
|
116
|
-
* @param dom - The DOM element that needs to be updated with new props.
|
|
117
|
-
* @param prevProps - An object representing the previous props (properties) of a DOM element.
|
|
118
|
-
* @param nextProps - An object containing the new props that need to be updated in the DOM.
|
|
119
|
-
*/
|
|
120
|
-
function updateDom(dom, prevProps, nextProps) {
|
|
121
|
-
Object.keys(prevProps)
|
|
122
|
-
.filter(isEvent)
|
|
123
|
-
.filter((key) => isGone(nextProps)(key) || isNew(prevProps, nextProps)(key))
|
|
124
|
-
.forEach((name) => {
|
|
125
|
-
const eventType = name.toLowerCase().substring(2);
|
|
126
|
-
dom.removeEventListener(eventType, prevProps[name]);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
Object.keys(prevProps)
|
|
130
|
-
.filter(isProperty)
|
|
131
|
-
.filter(isGone(nextProps))
|
|
132
|
-
.forEach((name) => {
|
|
133
|
-
dom[name] = "";
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
Object.keys(nextProps)
|
|
137
|
-
.filter(isProperty)
|
|
138
|
-
.filter(isNew(prevProps, nextProps))
|
|
139
|
-
.forEach((name) => {
|
|
140
|
-
if (name === STRINGS.style) {
|
|
141
|
-
DomStyle(dom, nextProps.style);
|
|
142
|
-
} else if (name === STRINGS.className) {
|
|
143
|
-
if (nextProps.className === "") {
|
|
144
|
-
throw new Error("className cannot be empty.");
|
|
145
|
-
}
|
|
146
|
-
prevProps.className &&
|
|
147
|
-
dom.classList.remove(...prevProps.className.split(/\s+/));
|
|
148
|
-
dom.classList.add(...nextProps.className.split(/\s+/));
|
|
149
|
-
} else {
|
|
150
|
-
dom[name] = nextProps[name];
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
Object.keys(nextProps)
|
|
155
|
-
.filter(isEvent)
|
|
156
|
-
.filter(isNew(prevProps, nextProps))
|
|
157
|
-
.forEach((name) => {
|
|
158
|
-
const eventType = name.toLowerCase().substring(2);
|
|
159
|
-
dom.addEventListener(eventType, nextProps[name]);
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function DomStyle(dom, style) {
|
|
164
|
-
dom.style = Object.keys(style).reduce((acc, styleName) => {
|
|
165
|
-
const key = styleName.replace(reg, function (v) {
|
|
166
|
-
return "-" + v.toLowerCase();
|
|
167
|
-
});
|
|
168
|
-
acc += `${key}: ${style[styleName]};`;
|
|
169
|
-
return acc;
|
|
170
|
-
}, "");
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* The function commits changes made to the virtual DOM to the actual DOM.
|
|
175
|
-
*/
|
|
176
|
-
function commitRoot() {
|
|
177
|
-
deletions.forEach(commitWork);
|
|
178
|
-
commitWork(wipRoot.child);
|
|
179
|
-
currentRoot = wipRoot;
|
|
180
|
-
wipRoot = null;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* The function cancels all effect hooks in a given fiber.
|
|
185
|
-
* @param fiber - The "fiber" parameter is likely referring to a data structure used in React.js to
|
|
186
|
-
* represent a component and its state. It contains information about the component's props, state, and
|
|
187
|
-
* children, as well as metadata used by React to manage updates and rendering. The function
|
|
188
|
-
* "cancelEffects" is likely intended
|
|
189
|
-
*/
|
|
190
|
-
function cancelEffects(fiber) {
|
|
191
|
-
if (fiber.hooks) {
|
|
192
|
-
fiber.hooks
|
|
193
|
-
.filter((hook) => hook.tag === RYUNIX_TYPES.RYUNIX_EFFECT && hook.cancel)
|
|
194
|
-
.forEach((effectHook) => {
|
|
195
|
-
effectHook.cancel();
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* The function runs all effect hooks in a given fiber.
|
|
202
|
-
* @param fiber - The "fiber" parameter is likely referring to a data structure used in the
|
|
203
|
-
* implementation of a fiber-based reconciliation algorithm, such as the one used in React. A fiber
|
|
204
|
-
* represents a unit of work that needs to be performed by the reconciliation algorithm, and it
|
|
205
|
-
* contains information about a component and its children, as
|
|
206
|
-
*/
|
|
207
|
-
function runEffects(fiber) {
|
|
208
|
-
if (fiber.hooks) {
|
|
209
|
-
fiber.hooks
|
|
210
|
-
.filter((hook) => hook.tag === RYUNIX_TYPES.RYUNIX_EFFECT && hook.effect)
|
|
211
|
-
.forEach((effectHook) => {
|
|
212
|
-
effectHook.cancel = effectHook.effect();
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* The function commits changes made to the DOM based on the effect tag of the fiber.
|
|
219
|
-
* @param fiber - A fiber is a unit of work in Ryunix's reconciliation process. It represents a
|
|
220
|
-
* component and its state at a particular point in time. The `commitWork` function takes a fiber as a
|
|
221
|
-
* parameter to commit the changes made during the reconciliation process to the actual DOM.
|
|
222
|
-
* @returns The function does not return anything, it performs side effects by manipulating the DOM.
|
|
223
|
-
*/
|
|
224
|
-
function commitWork(fiber) {
|
|
225
|
-
if (!fiber) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
77
|
+
};
|
|
228
78
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
const domParent = domParentFiber.dom;
|
|
234
|
-
|
|
235
|
-
if (fiber.effectTag === EFFECT_TAGS.PLACEMENT) {
|
|
236
|
-
if (fiber.dom != null) {
|
|
237
|
-
domParent.appendChild(fiber.dom);
|
|
238
|
-
}
|
|
239
|
-
runEffects(fiber);
|
|
240
|
-
} else if (fiber.effectTag === EFFECT_TAGS.UPDATE) {
|
|
241
|
-
cancelEffects(fiber);
|
|
242
|
-
if (fiber.dom != null) {
|
|
243
|
-
updateDom(fiber.dom, fiber.alternate.props, fiber.props);
|
|
244
|
-
}
|
|
245
|
-
runEffects(fiber);
|
|
246
|
-
} else if (fiber.effectTag === EFFECT_TAGS.DELETION) {
|
|
247
|
-
cancelEffects(fiber);
|
|
248
|
-
commitDeletion(fiber, domParent);
|
|
249
|
-
return;
|
|
79
|
+
const Fragments = (props) => {
|
|
80
|
+
if (props.style) {
|
|
81
|
+
throw new Error("The style attribute is not supported");
|
|
250
82
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
commitWork(fiber.sibling);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* The function removes a fiber's corresponding DOM node from its parent node or recursively removes
|
|
258
|
-
* its child's DOM node until it finds a node to remove.
|
|
259
|
-
* @param fiber - a fiber node in a fiber tree, which represents a component or an element in the Ryunix
|
|
260
|
-
* application.
|
|
261
|
-
* @param domParent - The parent DOM element from which the fiber's DOM element needs to be removed.
|
|
262
|
-
*/
|
|
263
|
-
function commitDeletion(fiber, domParent) {
|
|
264
|
-
if (fiber.dom) {
|
|
265
|
-
domParent.removeChild(fiber.dom);
|
|
266
|
-
} else {
|
|
267
|
-
commitDeletion(fiber.child, domParent);
|
|
83
|
+
if (props.className === "") {
|
|
84
|
+
throw new Error("className cannot be empty.");
|
|
268
85
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* @deprecated use Ryunix.init(root) instead.
|
|
273
|
-
*
|
|
274
|
-
* @description The function creates a root container for a web application.
|
|
275
|
-
* @example Ryunix.createRoot(document.getElementById("root")) -> <div id="root" />
|
|
276
|
-
* @param root - The parameter `root` is likely referring to an HTML element that will serve as the
|
|
277
|
-
* root or container for a web application or component. The `createRoot` function takes this element
|
|
278
|
-
* as an argument and assigns it to a variable called `containerRoot`. This variable can then be used
|
|
279
|
-
* to manipulate the contents
|
|
280
|
-
*
|
|
281
|
-
*/
|
|
282
|
-
function createRoot(root) {
|
|
283
|
-
containerRoot = root;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* @description The function creates a reference to a DOM element with the specified ID. This will be used to initialize the app.
|
|
288
|
-
* @example Ryunix.init("root") -> <div id="root" />
|
|
289
|
-
* @param root - The parameter "root" is the id of the HTML element that will serve as the container
|
|
290
|
-
* for the root element.
|
|
291
|
-
*/
|
|
292
|
-
function init(root) {
|
|
293
|
-
containerRoot = document.getElementById(root);
|
|
294
|
-
}
|
|
86
|
+
return createElement("div", props, props.children);
|
|
87
|
+
};
|
|
295
88
|
|
|
296
89
|
/**
|
|
297
90
|
* The function renders an element into a container using a work-in-progress root.
|
|
@@ -300,206 +93,46 @@
|
|
|
300
93
|
* @param container - The container parameter is the DOM element where the rendered element will be
|
|
301
94
|
* appended to. this parameter is optional if you use createRoot().
|
|
302
95
|
*/
|
|
303
|
-
|
|
304
|
-
wipRoot = {
|
|
305
|
-
dom: containerRoot || container,
|
|
96
|
+
const render = (element, container) => {
|
|
97
|
+
vars.wipRoot = {
|
|
98
|
+
dom: vars.containerRoot || container,
|
|
306
99
|
props: {
|
|
307
100
|
children: [element],
|
|
308
101
|
},
|
|
309
|
-
alternate: currentRoot,
|
|
102
|
+
alternate: vars.currentRoot,
|
|
310
103
|
};
|
|
311
|
-
deletions = [];
|
|
312
|
-
nextUnitOfWork = wipRoot;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* This function uses requestIdleCallback to perform work on a fiber tree until it is complete or the
|
|
317
|
-
* browser needs to yield to other tasks.
|
|
318
|
-
* @param deadline - The `deadline` parameter is an object that represents the amount of time the
|
|
319
|
-
* browser has to perform work before it needs to handle other tasks. It has a `timeRemaining()` method
|
|
320
|
-
* that returns the amount of time remaining before the deadline is reached. The `shouldYield` variable
|
|
321
|
-
* is used to determine
|
|
322
|
-
*/
|
|
323
|
-
function workLoop(deadline) {
|
|
324
|
-
let shouldYield = false;
|
|
325
|
-
while (nextUnitOfWork && !shouldYield) {
|
|
326
|
-
nextUnitOfWork = performUnitOfWork(nextUnitOfWork);
|
|
327
|
-
shouldYield = deadline.timeRemaining() < 1;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
if (!nextUnitOfWork && wipRoot) {
|
|
331
|
-
commitRoot();
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
requestIdleCallback(workLoop);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
requestIdleCallback(workLoop);
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* The function performs a unit of work by updating either a function component or a host component and
|
|
341
|
-
* returns the next fiber to be processed.
|
|
342
|
-
* @param fiber - A fiber is a unit of work in Ryunix that represents a component and its state. It
|
|
343
|
-
* contains information about the component's type, props, and children, as well as pointers to its
|
|
344
|
-
* parent, child, and sibling fibers. The `performUnitOfWork` function takes a fiber as a parameter and
|
|
345
|
-
* performs work
|
|
346
|
-
* @returns The function `performUnitOfWork` returns the next fiber to be processed. If the current
|
|
347
|
-
* fiber has a child, it returns the child. Otherwise, it looks for the next sibling of the current
|
|
348
|
-
* fiber. If there are no more siblings, it goes up the tree to the parent and looks for the next
|
|
349
|
-
* sibling of the parent. The function returns `null` if there are no more fibers to process.
|
|
350
|
-
*/
|
|
351
|
-
function performUnitOfWork(fiber) {
|
|
352
|
-
const isFunctionComponent = fiber.type instanceof Function;
|
|
353
|
-
if (isFunctionComponent) {
|
|
354
|
-
updateFunctionComponent(fiber);
|
|
355
|
-
} else {
|
|
356
|
-
updateHostComponent(fiber);
|
|
357
|
-
}
|
|
358
|
-
if (fiber.child) {
|
|
359
|
-
return fiber.child;
|
|
360
|
-
}
|
|
361
|
-
let nextFiber = fiber;
|
|
362
|
-
while (nextFiber) {
|
|
363
|
-
if (nextFiber.sibling) {
|
|
364
|
-
return nextFiber.sibling;
|
|
365
|
-
}
|
|
366
|
-
nextFiber = nextFiber.parent;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* This function updates a function component by setting up a work-in-progress fiber, resetting the
|
|
372
|
-
* hook index, creating an empty hooks array, rendering the component, and reconciling its children.
|
|
373
|
-
* @param fiber - The fiber parameter is an object that represents a node in the fiber tree. It
|
|
374
|
-
* contains information about the component, its props, state, and children. In this function, it is
|
|
375
|
-
* used to update the state of the component and its children.
|
|
376
|
-
*/
|
|
377
|
-
function updateFunctionComponent(fiber) {
|
|
378
|
-
wipFiber = fiber;
|
|
379
|
-
hookIndex = 0;
|
|
380
|
-
wipFiber.hooks = [];
|
|
381
|
-
const children = [fiber.type(fiber.props)];
|
|
382
|
-
reconcileChildren(fiber, children);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
/**
|
|
386
|
-
* This function updates a host component's DOM element and reconciles its children.
|
|
387
|
-
* @param fiber - A fiber is a unit of work in Ryunix that represents a component and its state. It
|
|
388
|
-
* contains information about the component's type, props, and children, as well as pointers to other
|
|
389
|
-
* fibers in the tree.
|
|
390
|
-
*/
|
|
391
|
-
function updateHostComponent(fiber) {
|
|
392
|
-
if (!fiber.dom) {
|
|
393
|
-
fiber.dom = createDom(fiber);
|
|
394
|
-
}
|
|
395
|
-
reconcileChildren(fiber, fiber.props.children.flat());
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* This function reconciles the children of a fiber node with a new set of elements, creating new
|
|
400
|
-
* fibers for new elements, updating existing fibers for elements with the same type, and marking old
|
|
401
|
-
* fibers for deletion if they are not present in the new set of elements.
|
|
402
|
-
* @param wipFiber - A work-in-progress fiber object representing a component or element in the virtual
|
|
403
|
-
* DOM tree.
|
|
404
|
-
* @param elements - an array of elements representing the new children to be rendered in the current
|
|
405
|
-
* fiber's subtree
|
|
406
|
-
*/
|
|
407
|
-
function reconcileChildren(wipFiber, elements) {
|
|
408
|
-
let index = 0;
|
|
409
|
-
let oldFiber = wipFiber.alternate && wipFiber.alternate.child;
|
|
410
|
-
let prevSibling = null;
|
|
411
|
-
|
|
412
|
-
while (index < elements.length || oldFiber != null) {
|
|
413
|
-
const element = elements[index];
|
|
414
|
-
let newFiber = null;
|
|
415
|
-
|
|
416
|
-
const sameType = oldFiber && element && element.type == oldFiber.type;
|
|
417
|
-
|
|
418
|
-
if (sameType) {
|
|
419
|
-
newFiber = {
|
|
420
|
-
type: oldFiber.type,
|
|
421
|
-
props: element.props,
|
|
422
|
-
dom: oldFiber.dom,
|
|
423
|
-
parent: wipFiber,
|
|
424
|
-
alternate: oldFiber,
|
|
425
|
-
effectTag: EFFECT_TAGS.UPDATE,
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
if (element && !sameType) {
|
|
429
|
-
newFiber = {
|
|
430
|
-
type: element.type,
|
|
431
|
-
props: element.props,
|
|
432
|
-
dom: null,
|
|
433
|
-
parent: wipFiber,
|
|
434
|
-
alternate: null,
|
|
435
|
-
effectTag: EFFECT_TAGS.PLACEMENT,
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
|
-
if (oldFiber && !sameType) {
|
|
439
|
-
oldFiber.effectTag = EFFECT_TAGS.DELETION;
|
|
440
|
-
deletions.push(oldFiber);
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
if (oldFiber) {
|
|
444
|
-
oldFiber = oldFiber.sibling;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
if (index === 0) {
|
|
448
|
-
wipFiber.child = newFiber;
|
|
449
|
-
} else if (element) {
|
|
450
|
-
prevSibling.sibling = newFiber;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
prevSibling = newFiber;
|
|
454
|
-
index++;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
104
|
+
vars.deletions = [];
|
|
105
|
+
vars.nextUnitOfWork = vars.wipRoot;
|
|
106
|
+
};
|
|
457
107
|
|
|
458
108
|
/**
|
|
459
|
-
* The function
|
|
460
|
-
*
|
|
461
|
-
* @param
|
|
462
|
-
*
|
|
463
|
-
* @returns a context object.
|
|
109
|
+
* @description The function creates a reference to a DOM element with the specified ID. This will be used to initialize the app.
|
|
110
|
+
* @example Ryunix.init("root") -> <div id="root" />
|
|
111
|
+
* @param root - The parameter "root" is the id of the HTML element that will serve as the container
|
|
112
|
+
* for the root element.
|
|
464
113
|
*/
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
const context = {
|
|
469
|
-
tag: RYUNIX_TYPES.RYUNIX_CONTEXT,
|
|
470
|
-
Value: contextValue,
|
|
471
|
-
Provider: null,
|
|
472
|
-
};
|
|
473
|
-
|
|
474
|
-
context.Provider = (value) => (context.Value = value);
|
|
475
|
-
|
|
476
|
-
return context;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
function Fragments(props) {
|
|
480
|
-
if (props.style) {
|
|
481
|
-
throw new Error("The style attribute is not supported");
|
|
482
|
-
}
|
|
483
|
-
if (props.className === "") {
|
|
484
|
-
throw new Error("className cannot be empty.");
|
|
485
|
-
}
|
|
486
|
-
return createElement("div", props, props.children);
|
|
487
|
-
}
|
|
114
|
+
const init = (root) => {
|
|
115
|
+
vars.containerRoot = document.getElementById(root);
|
|
116
|
+
};
|
|
488
117
|
|
|
489
|
-
|
|
118
|
+
const hasDepsChanged = (prevDeps, nextDeps) =>
|
|
119
|
+
!prevDeps ||
|
|
120
|
+
!nextDeps ||
|
|
121
|
+
prevDeps.length !== nextDeps.length ||
|
|
122
|
+
prevDeps.some((dep, index) => dep !== nextDeps[index]);
|
|
490
123
|
|
|
491
124
|
/**
|
|
492
125
|
* The function `useContext` is used to read and subscribe to context from your component.
|
|
493
126
|
* @param ref - The `ref` parameter is a reference to a context object.
|
|
494
127
|
* @returns The `Value` property of the `hook` object is being returned.
|
|
495
128
|
*/
|
|
496
|
-
|
|
497
|
-
hookIndex++;
|
|
129
|
+
const useContext = (ref) => {
|
|
130
|
+
vars.hookIndex++;
|
|
498
131
|
|
|
499
132
|
const oldHook =
|
|
500
|
-
wipFiber.alternate &&
|
|
501
|
-
wipFiber.alternate.hooks &&
|
|
502
|
-
wipFiber.alternate.hooks[hookIndex];
|
|
133
|
+
vars.wipFiber.alternate &&
|
|
134
|
+
vars.wipFiber.alternate.hooks &&
|
|
135
|
+
vars.wipFiber.alternate.hooks[vars.hookIndex];
|
|
503
136
|
|
|
504
137
|
const hasOld = oldHook ? oldHook : undefined;
|
|
505
138
|
const Context = hasOld ? hasOld : ref;
|
|
@@ -507,10 +140,10 @@
|
|
|
507
140
|
...Context,
|
|
508
141
|
};
|
|
509
142
|
|
|
510
|
-
wipFiber.hooks.push(hook);
|
|
143
|
+
vars.wipFiber.hooks.push(hook);
|
|
511
144
|
|
|
512
145
|
return hook.Value;
|
|
513
|
-
}
|
|
146
|
+
};
|
|
514
147
|
|
|
515
148
|
/**
|
|
516
149
|
* @description The function creates a state.
|
|
@@ -518,11 +151,11 @@
|
|
|
518
151
|
* @returns The `useStore` function returns an array with two elements: the current state value and a
|
|
519
152
|
* `setState` function that can be used to update the state.
|
|
520
153
|
*/
|
|
521
|
-
|
|
154
|
+
const useStore = (initial) => {
|
|
522
155
|
const oldHook =
|
|
523
|
-
wipFiber.alternate &&
|
|
524
|
-
wipFiber.alternate.hooks &&
|
|
525
|
-
wipFiber.alternate.hooks[hookIndex];
|
|
156
|
+
vars.wipFiber.alternate &&
|
|
157
|
+
vars.wipFiber.alternate.hooks &&
|
|
158
|
+
vars.wipFiber.alternate.hooks[vars.hookIndex];
|
|
526
159
|
const hook = {
|
|
527
160
|
state: oldHook ? oldHook.state : initial,
|
|
528
161
|
queue: [],
|
|
@@ -543,19 +176,19 @@
|
|
|
543
176
|
*/
|
|
544
177
|
const setState = (action) => {
|
|
545
178
|
hook.queue.push(action);
|
|
546
|
-
wipRoot = {
|
|
547
|
-
dom: currentRoot.dom,
|
|
548
|
-
props: currentRoot.props,
|
|
549
|
-
alternate: currentRoot,
|
|
179
|
+
vars.wipRoot = {
|
|
180
|
+
dom: vars.currentRoot.dom,
|
|
181
|
+
props: vars.currentRoot.props,
|
|
182
|
+
alternate: vars.currentRoot,
|
|
550
183
|
};
|
|
551
|
-
nextUnitOfWork = wipRoot;
|
|
552
|
-
deletions = [];
|
|
184
|
+
vars.nextUnitOfWork = vars.wipRoot;
|
|
185
|
+
vars.deletions = [];
|
|
553
186
|
};
|
|
554
187
|
|
|
555
|
-
wipFiber.hooks.push(hook);
|
|
556
|
-
hookIndex++;
|
|
188
|
+
vars.wipFiber.hooks.push(hook);
|
|
189
|
+
vars.hookIndex++;
|
|
557
190
|
return [hook.state, setState];
|
|
558
|
-
}
|
|
191
|
+
};
|
|
559
192
|
|
|
560
193
|
/**
|
|
561
194
|
* This is a function that creates a hook for managing side effects in Ryunix components.
|
|
@@ -566,11 +199,11 @@
|
|
|
566
199
|
* between renders, the effect will be re-run. If the array is empty, the effect will only run once on
|
|
567
200
|
* mount and never again.
|
|
568
201
|
*/
|
|
569
|
-
|
|
202
|
+
const useEffect = (effect, deps) => {
|
|
570
203
|
const oldHook =
|
|
571
|
-
wipFiber.alternate &&
|
|
572
|
-
wipFiber.alternate.hooks &&
|
|
573
|
-
wipFiber.alternate.hooks[hookIndex];
|
|
204
|
+
vars.wipFiber.alternate &&
|
|
205
|
+
vars.wipFiber.alternate.hooks &&
|
|
206
|
+
vars.wipFiber.alternate.hooks[vars.hookIndex];
|
|
574
207
|
|
|
575
208
|
const hasChanged = hasDepsChanged(oldHook ? oldHook.deps : undefined, deps);
|
|
576
209
|
|
|
@@ -581,14 +214,35 @@
|
|
|
581
214
|
deps,
|
|
582
215
|
};
|
|
583
216
|
|
|
584
|
-
wipFiber.hooks.push(hook);
|
|
585
|
-
hookIndex++;
|
|
586
|
-
}
|
|
217
|
+
vars.wipFiber.hooks.push(hook);
|
|
218
|
+
vars.hookIndex++;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* The function createContext creates a context object with a default value and methods to set and get
|
|
223
|
+
* the context value.
|
|
224
|
+
* @param defaultValue - The `defaultValue` parameter is the initial value that will be assigned to the
|
|
225
|
+
* `contextValue` variable if no value is provided when creating the context.
|
|
226
|
+
* @returns a context object.
|
|
227
|
+
*/
|
|
228
|
+
const createContext = (defaultValue) => {
|
|
229
|
+
let contextValue = defaultValue || null;
|
|
230
|
+
|
|
231
|
+
const context = {
|
|
232
|
+
tag: RYUNIX_TYPES.RYUNIX_CONTEXT,
|
|
233
|
+
Value: contextValue,
|
|
234
|
+
Provider: null,
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
context.Provider = (value) => (context.Value = value);
|
|
238
|
+
|
|
239
|
+
return context;
|
|
240
|
+
};
|
|
587
241
|
|
|
588
242
|
var Ryunix = {
|
|
589
243
|
createElement,
|
|
590
244
|
render,
|
|
591
|
-
|
|
245
|
+
|
|
592
246
|
init,
|
|
593
247
|
Fragments,
|
|
594
248
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unsetsoft/ryunixjs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.29-nightly.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/Ryunix.js",
|
|
6
6
|
"private": false,
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"homepage": "https://github.com/UnSetSoft/Ryunixjs#readme",
|
|
11
11
|
"scripts": {
|
|
12
|
-
"build": "rollup ./
|
|
12
|
+
"build": "rollup ./src/main.js --file ./dist/Ryunix.js --format umd --name Ryunix",
|
|
13
13
|
"prepublish": "npm run build",
|
|
14
14
|
"postinstall": "npm run build",
|
|
15
15
|
"cli": "node ./bin/index.js",
|