@unsetsoft/ryunixjs 0.2.26-nightly.4 → 0.2.26-nightly.6

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 CHANGED
@@ -423,8 +423,48 @@ function reconcileChildren(wipFiber, elements) {
423
423
  }
424
424
  }
425
425
 
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
+ const EMPTY_CONTEXT = Symbol();
436
+
437
+ function createContext(defaultValue) {
438
+ let contextValue = defaultValue || EMPTY_CONTEXT;
439
+
440
+ const context = {
441
+ tag: "RYUNIX_CONTEXT",
442
+ __currentValue: contextValue,
443
+ Provider: null,
444
+ Consumer: null,
445
+ };
446
+
447
+ context.Provider = {
448
+ _context: context,
449
+ };
450
+
451
+ context.Consumer = context;
452
+
453
+ return context;
454
+ }
455
+
426
456
  // Hooks
427
457
 
458
+ /**
459
+ * The useContext function returns the Consumer component of a given reference.
460
+ * @param ref - The "ref" parameter is a reference to a Ryunix context object.
461
+ * @returns The `useContext` function is returning the result of calling the `Consumer` method on the
462
+ * `ref` object.
463
+ */
464
+ function useContext(ref) {
465
+ return ref.Consumer();
466
+ }
467
+
428
468
  /**
429
469
  * @description The function creates a state.
430
470
  * @param initial - The initial value of the state for the hook.
@@ -513,7 +553,7 @@ function useEffect(effect, deps) {
513
553
 
514
554
  // export
515
555
 
516
- export { useStore, useEffect };
556
+ export { useStore, useEffect, createContext, useContext };
517
557
 
518
558
  export default {
519
559
  createElement,
package/lib/main.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import Ryunix from "./dom";
2
2
 
3
- export { useStore, useEffect } from "./dom";
3
+ export { useStore, useEffect, createContext, useContext } from "./dom";
4
4
 
5
5
  window.Ryunix = Ryunix;
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unsetsoft/ryunixjs",
3
- "version": "0.2.26-nightly.4",
3
+ "version": "0.2.26-nightly.6",
4
4
  "license": "MIT",
5
5
  "main": "./dist/Ryunix.js",
6
6
  "private": false,