@unsetsoft/ryunixjs 0.2.26-nightly.3 → 0.2.26-nightly.5

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,49 @@ 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 Provider = (value, callback) => {
441
+ contextValue = value;
442
+ const currentValue = contextValue;
443
+ callback();
444
+ contextValue = currentValue;
445
+ };
446
+
447
+ const Consumer = () => {
448
+ return contextValue;
449
+ };
450
+
451
+ return {
452
+ Provider,
453
+ Consumer,
454
+ };
455
+ }
456
+
426
457
  // Hooks
427
458
 
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
+ function useContext(ref) {
466
+ return ref.Consumer();
467
+ }
468
+
428
469
  /**
429
470
  * @description The function creates a state.
430
471
  * @param initial - The initial value of the state for the hook.
@@ -513,7 +554,7 @@ function useEffect(effect, deps) {
513
554
 
514
555
  // export
515
556
 
516
- export { useStore, useEffect };
557
+ export { useStore, useEffect, createContext, useContext };
517
558
 
518
559
  export default {
519
560
  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.3",
3
+ "version": "0.2.26-nightly.5",
4
4
  "license": "MIT",
5
5
  "main": "./dist/Ryunix.js",
6
6
  "private": false,
package/webpack.config.js CHANGED
@@ -41,19 +41,14 @@ module.exports = {
41
41
  module: {
42
42
  rules: [
43
43
  {
44
- test: /\.(js|jsx|ts|tsx|ryx|mdx)$/,
44
+ test: /\.(js|jsx|ts|tsx|ryx|)$/,
45
45
  exclude: /node_modules/,
46
- use: [
47
- {
48
- loader: "babel-loader",
49
- options: {
50
- presets: ["@babel/preset-env", "@babel/preset-react"],
51
- },
46
+ use: {
47
+ loader: "babel-loader",
48
+ options: {
49
+ presets: ["@babel/preset-env", "@babel/preset-react"],
52
50
  },
53
- {
54
- loader: "@mdx-js/loader",
55
- },
56
- ],
51
+ },
57
52
  },
58
53
  {
59
54
  test: /\.sass|css$/,