@unsetsoft/ryunixjs 0.2.26-nightly.5 → 0.2.26-nightly.7
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/lib/dom.js +29 -27
- package/package.json +1 -1
package/lib/dom.js
CHANGED
|
@@ -424,46 +424,48 @@ function reconcileChildren(wipFiber, elements) {
|
|
|
424
424
|
}
|
|
425
425
|
|
|
426
426
|
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* The above function creates a context in JavaScript that allows for sharing data between components.
|
|
430
|
-
* @param defaultValue - The `defaultValue` parameter is the initial value of the context. If no value
|
|
431
|
-
* is provided, the `EMPTY_CONTEXT` symbol is used as the default value.
|
|
432
|
-
* @returns The `createContext` function returns an object with two properties: `Provider` and
|
|
433
|
-
* `Consumer`.
|
|
434
|
-
*/
|
|
435
427
|
const EMPTY_CONTEXT = Symbol();
|
|
436
428
|
|
|
429
|
+
/**
|
|
430
|
+
* The function createContext creates a context object with a default value and methods to set and get
|
|
431
|
+
* the context value.
|
|
432
|
+
* @param defaultValue - The `defaultValue` parameter is the initial value that will be assigned to the
|
|
433
|
+
* `contextValue` variable if no value is provided when creating the context.
|
|
434
|
+
* @returns a context object.
|
|
435
|
+
*/
|
|
437
436
|
function createContext(defaultValue) {
|
|
438
437
|
let contextValue = defaultValue || EMPTY_CONTEXT;
|
|
439
438
|
|
|
440
|
-
const
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
439
|
+
const context = {
|
|
440
|
+
tag: "RYUNIX_CONTEXT",
|
|
441
|
+
Value: contextValue,
|
|
442
|
+
Provider: null,
|
|
443
|
+
Consumer: null,
|
|
445
444
|
};
|
|
446
445
|
|
|
447
|
-
|
|
448
|
-
return contextValue;
|
|
449
|
-
};
|
|
446
|
+
context.Provider = (value) => (context.Value = value);
|
|
450
447
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
};
|
|
448
|
+
context.Consumer = context.Value;
|
|
449
|
+
|
|
450
|
+
return context;
|
|
455
451
|
}
|
|
456
452
|
|
|
457
453
|
// Hooks
|
|
458
454
|
|
|
459
|
-
/**
|
|
460
|
-
* The useContext function returns the Consumer component of a given reference.
|
|
461
|
-
* @param ref - The "ref" parameter is a reference to a Ryunix context object.
|
|
462
|
-
* @returns The `useContext` function is returning the result of calling the `Consumer` method on the
|
|
463
|
-
* `ref` object.
|
|
464
|
-
*/
|
|
465
455
|
function useContext(ref) {
|
|
466
|
-
|
|
456
|
+
const oldHook =
|
|
457
|
+
wipFiber.alternate &&
|
|
458
|
+
wipFiber.alternate.hooks &&
|
|
459
|
+
wipFiber.alternate.hooks[hookIndex];
|
|
460
|
+
|
|
461
|
+
const hook = {
|
|
462
|
+
value: oldHook ? oldHook.value : ref.Consumer,
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
wipFiber.hooks.push(hook);
|
|
466
|
+
hookIndex++;
|
|
467
|
+
|
|
468
|
+
return hook.value;
|
|
467
469
|
}
|
|
468
470
|
|
|
469
471
|
/**
|