@unsetsoft/ryunixjs 0.2.26-nightly.0 → 0.2.26-nightly.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/lib/dom.js CHANGED
@@ -423,8 +423,48 @@ function reconcileChildren(wipFiber, elements) {
423
423
  }
424
424
  }
425
425
 
426
+
427
+ /**
428
+ * The function createContext creates a context object with a default value and methods to set and get
429
+ * the context value.
430
+ * @param defaultValue - The `defaultValue` parameter is the initial value that will be assigned to the
431
+ * `contextValue` variable if no value is provided when creating the context.
432
+ * @returns a context object.
433
+ */
434
+ function createContext(defaultValue) {
435
+ let contextValue = defaultValue || null;
436
+
437
+ const context = {
438
+ tag: "RYUNIX_CREATE_CONTEXT",
439
+ Value: contextValue,
440
+ Provider: null,
441
+ };
442
+
443
+ context.Provider = (value) => (context.Value = value);
444
+
445
+ return context;
446
+ }
447
+
426
448
  // Hooks
427
449
 
450
+ function useContext(ref) {
451
+ const Context = oldHook ? oldHook : ref;
452
+
453
+ const hook = {
454
+ tag: "RYUNIX_USE_CONTEXT",
455
+ __context: Context,
456
+ };
457
+
458
+ wipFiber.hooks.push(hook);
459
+ hookIndex++;
460
+ const oldHook =
461
+ wipFiber.alternate &&
462
+ wipFiber.alternate.hooks &&
463
+ wipFiber.alternate.hooks[hookIndex];
464
+
465
+ return hook.__context.Value;
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.0",
3
+ "version": "0.2.26-nightly.10",
4
4
  "license": "MIT",
5
5
  "main": "./dist/Ryunix.js",
6
6
  "private": false,
package/webpack.config.js CHANGED
@@ -71,14 +71,10 @@ module.exports = {
71
71
  loader: "url-loader",
72
72
  options: { limit: false },
73
73
  },
74
- {
75
- test: /\.mdx$/,
76
- use: ["@mdx-js/loader"],
77
- },
78
74
  ],
79
75
  },
80
76
  resolve: {
81
- extensions: ["*", ".js", ".jsx", ".ts", ".tsx", ".ryx"],
77
+ extensions: [".*", ".js", ".jsx", ".ts", ".tsx", ".ryx"],
82
78
  },
83
79
  plugins: [
84
80
  new HtmlWebpackPlugin({