@unsetsoft/ryunixjs 1.2.3-canary.12 → 1.2.3-canary.13

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.
@@ -70,7 +70,12 @@ const is = {
70
70
  };
71
71
 
72
72
  /**
73
- * Create text element
73
+ * The `createTextElement` function creates a text element with the specified text content.
74
+ * @param text - The `text` parameter in the `createTextElement` function is the text content that you
75
+ * want to create a text element for. This text will be set as the `nodeValue` of the text element in
76
+ * the returned object.
77
+ * @returns A text element object is being returned with a type of RYUNIX_TYPES.TEXT_ELEMENT and props
78
+ * containing the text value provided in the function argument.
74
79
  */
75
80
  const createTextElement = (text) => {
76
81
  return {
@@ -83,7 +88,21 @@ const createTextElement = (text) => {
83
88
  };
84
89
 
85
90
  /**
86
- * Create element
91
+ * The `createElement` function creates a virtual DOM element with specified type, properties, and
92
+ * children.
93
+ * @param type - The `type` parameter in the `createElement` function represents the type of element
94
+ * you want to create, such as a HTML tag like 'div', 'span', 'p', etc.
95
+ * @param props - The `props` parameter in the `createElement` function is an object that contains the
96
+ * properties or attributes for the element being created. These properties can include things like
97
+ * class names, styles, event handlers, and any other custom attributes you want to assign to the
98
+ * element. In the code snippet you provided,
99
+ * @param children - The `children` parameter in the `createElement` function represents the child
100
+ * elements or text content that will be nested within the created element. These children can be
101
+ * passed as arguments to the `createElement` function and will be rendered as part of the element's
102
+ * content.
103
+ * @returns An object is being returned with a `type` property representing the type of element, and a
104
+ * `props` property containing the element's properties. The `props` object includes the children of
105
+ * the element, which are processed to ensure they are in the correct format.
87
106
  */
88
107
  const createElement = (type, props, ...children) => {
89
108
  const safeProps = props || {};
@@ -102,7 +121,14 @@ const createElement = (type, props, ...children) => {
102
121
  };
103
122
 
104
123
  /**
105
- * Fragment component
124
+ * The `Fragment` function in JavaScript creates a fragment element with the given children.
125
+ * @param props - The `props` parameter in the `Fragment` function is an object that contains the
126
+ * properties passed to the `Fragment` component. These properties can include `children`, which
127
+ * represents the child elements or components nested within the `Fragment`.
128
+ * @returns The `Fragment` component is returning a Ryunix fragment element created using the
129
+ * `createElement` function. The element is of type `RYUNIX_TYPES.RYUNIX_FRAGMENT` and contains the
130
+ * children passed to the `Fragment` component. If `props.children` is not an array, it is converted
131
+ * into an array before being spread into the `createElement` function.
106
132
  */
107
133
  const Fragment = (props) => {
108
134
  const children = Array.isArray(props.children)
@@ -450,6 +476,9 @@ const updateDom = (dom, prevProps = {}, nextProps = {}) => {
450
476
  });
451
477
  };
452
478
 
479
+ /**
480
+ * The `commitRoot` function commits the changes made to the virtual DOM by updating the actual DOM.
481
+ */
453
482
  const commitRoot = () => {
454
483
  const state = getState();
455
484
  state.deletions.forEach(commitWork);
@@ -618,12 +647,35 @@ const haveDepsChanged = (oldDeps, newDeps) => {
618
647
  return oldDeps.some((dep, i) => !Object.is(dep, newDeps[i]))
619
648
  };
620
649
 
650
+ /**
651
+ * The `useStore` function in JavaScript is a custom hook that uses a reducer to manage state updates
652
+ * based on actions provided.
653
+ * @param initialState - The `initialState` parameter in the `useStore` function is the initial state
654
+ * of the store that will be used with the `useReducer` hook. It represents the starting state of the
655
+ * store before any actions are dispatched to update it.
656
+ * @returns The `useStore` function is returning the result of calling the `useReducer` hook with the
657
+ * `reducer` function and the `initialState` as arguments.
658
+ */
621
659
  const useStore = (initialState) => {
622
660
  const reducer = (state, action) =>
623
661
  is.function(action) ? action(state) : action;
624
662
  return useReducer(reducer, initialState)
625
663
  };
626
664
 
665
+ /**
666
+ * The `useReducer` function in JavaScript is used to manage state and actions.
667
+ *
668
+ * @param reducer - The `reducer` parameter in the `useReducer` function is a function that specifies
669
+ * how the state should be updated in response to an action. It takes the current state and an action
670
+ * as arguments and returns the new state based on the action.
671
+ * @param initialState - The `initialState` parameter in the `useReducer` function represents the
672
+ * initial state of the reducer. It is the state that will be used when the reducer is first called or
673
+ * when the state needs to be reset. This initial state can be a simple value, an object, an array, or
674
+ * @param init - The `init` parameter in the `useReducer` function is an optional function that can be
675
+ * used to initialize the state. If provided, it will be called with the `initialState` as its argument
676
+ * and the return value will be used as the initial state for the reducer. If `init`
677
+ * @returns An array containing the current state and the dispatch function is being returned.
678
+ */
627
679
  const useReducer = (reducer, initialState, init) => {
628
680
  validateHookCall();
629
681
 
@@ -635,10 +687,9 @@ const useReducer = (reducer, initialState, init) => {
635
687
  hookID: hookIndex,
636
688
  type: RYUNIX_TYPES.RYUNIX_STORE,
637
689
  state: oldHook ? oldHook.state : init ? init(initialState) : initialState,
638
- queue: [], // Siempre nueva cola vacía
690
+ queue: [],
639
691
  };
640
692
 
641
- // Procesar acciones del render anterior
642
693
  if (oldHook?.queue) {
643
694
  oldHook.queue.forEach((action) => {
644
695
  try {
@@ -677,6 +728,16 @@ const useReducer = (reducer, initialState, init) => {
677
728
  return [hook.state, dispatch]
678
729
  };
679
730
 
731
+ /**
732
+ * The `useEffect` function in JavaScript is used to manage side effects in functional components by
733
+ * comparing dependencies and executing a callback function when dependencies change.
734
+ * @param callback - The `callback` parameter in the `useEffect` function is a function that will be
735
+ * executed as the effect. This function can perform side effects like data fetching, subscriptions, or
736
+ * DOM manipulations.
737
+ * @param deps - The `deps` parameter in the `useEffect` function stands for dependencies. It is an
738
+ * optional array that contains values that the effect depends on. The effect will only re-run if any
739
+ * of the values in the `deps` array have changed since the last render. If the `deps` array
740
+ */
680
741
  const useEffect = (callback, deps) => {
681
742
  validateHookCall();
682
743
 
@@ -704,6 +765,14 @@ const useEffect = (callback, deps) => {
704
765
  state.hookIndex++;
705
766
  };
706
767
 
768
+ /**
769
+ * The useRef function in JavaScript creates a reference object with an initial value for use in functional components.
770
+ * @param initialValue - The `initialValue` parameter in the `useRef` function represents the initial
771
+ * value that will be assigned to the `current` property of the reference object. This initial value
772
+ * will be used if there is no previous value stored in the hook.
773
+ * @returns The `useRef` function is returning the `current` property of the `hook.value` object, which
774
+ * contains the initial value passed to the `useRef` function.
775
+ */
707
776
  const useRef = (initialValue) => {
708
777
  validateHookCall();
709
778
 
@@ -722,6 +791,18 @@ const useRef = (initialValue) => {
722
791
  return hook.value
723
792
  };
724
793
 
794
+ /**
795
+ * The useMemo function in JavaScript is used to memoize the result of a computation based on
796
+ * dependencies.
797
+ * @param compute - The `compute` parameter in the `useMemo` function is a callback function that
798
+ * calculates the value that `useMemo` will memoize and return. This function will be called to compute
799
+ * the memoized value when necessary.
800
+ * @param deps - The `deps` parameter in the `useMemo` function refers to an array of dependencies.
801
+ * These dependencies are used to determine whether the memoized value needs to be recalculated or if
802
+ * the previously calculated value can be reused. The `useMemo` hook will recompute the memoized value
803
+ * only if
804
+ * @returns The `useMemo` function is returning the `value` calculated by the `compute` function.
805
+ */
725
806
  const useMemo = (compute, deps) => {
726
807
  validateHookCall();
727
808
 
@@ -762,6 +843,17 @@ const useMemo = (compute, deps) => {
762
843
  return value
763
844
  };
764
845
 
846
+ /**
847
+ * The useCallback function in JavaScript ensures that a callback function is memoized based on its
848
+ * dependencies.
849
+ * @param callback - A function that you want to memoize and return for later use.
850
+ * @param deps - The `deps` parameter in the `useCallback` function refers to an array of dependencies.
851
+ * These dependencies are used to determine when the callback function should be re-evaluated and
852
+ * memoized. If any of the dependencies change, the callback function will be re-executed and the
853
+ * memoized value will
854
+ * @returns The useCallback function is returning the memoized version of the callback function passed
855
+ * as the first argument, based on the dependencies array provided as the second argument.
856
+ */
765
857
  const useCallback = (callback, deps) => {
766
858
  if (!is.function(callback)) {
767
859
  throw new Error('useCallback requires a function as first argument')
@@ -769,6 +861,20 @@ const useCallback = (callback, deps) => {
769
861
  return useMemo(() => callback, deps)
770
862
  };
771
863
 
864
+ /**
865
+ * The createContext function creates a context provider and useContext hook in JavaScript.
866
+ * @param [contextId] - The `contextId` parameter in the `createContext` function is used to specify
867
+ * the unique identifier for the context being created. It defaults to `RYUNIX_TYPES.RYUNIX_CONTEXT` if
868
+ * not provided.
869
+ * @param [defaultValue] - The `defaultValue` parameter in the `createContext` function is used to
870
+ * specify the default value that will be returned by the `useContext` hook if no provider is found in
871
+ * the component tree. It is an optional parameter, and if not provided, an empty object `{}` will be
872
+ * used as
873
+ * @returns The `createContext` function returns an object with two properties: `Provider` and
874
+ * `useContext`. The `Provider` property is a component that accepts `children` and `value` props, and
875
+ * sets the `_contextId` and `_contextValue` properties on the element. The `useContext` property is a
876
+ * hook function that retrieves the context value based on the context ID provided, or
877
+ */
772
878
  const createContext = (
773
879
  contextId = RYUNIX_TYPES.RYUNIX_CONTEXT,
774
880
  defaultValue = {},
@@ -806,6 +912,10 @@ const createContext = (
806
912
  return { Provider, useContext }
807
913
  };
808
914
 
915
+ /**
916
+ * The `useQuery` function extracts query parameters from the URL in a browser environment.
917
+ * @returns An object containing the query parameters from the current URL is being returned.
918
+ */
809
919
  const useQuery = () => {
810
920
  if (typeof window === 'undefined') return {}
811
921
 
@@ -817,6 +927,14 @@ const useQuery = () => {
817
927
  return query
818
928
  };
819
929
 
930
+ /**
931
+ * The function `useHash` in JavaScript is used to manage and update the hash portion of the URL in a
932
+ * web application.
933
+ * @returns The `useHash` function returns the current hash value from the window's location. If the
934
+ * window is undefined (e.g., in a server-side environment), it returns an empty string. The function
935
+ * also sets up an event listener to update the hash value when the hash in the URL changes and removes
936
+ * the event listener when the component unmounts.
937
+ */
820
938
  const useHash = () => {
821
939
  if (typeof window === 'undefined') return ''
822
940
 
@@ -829,6 +947,25 @@ const useHash = () => {
829
947
  return hash
830
948
  };
831
949
 
950
+ /**
951
+ * The `useMetadata` function in JavaScript is used to dynamically update metadata tags in the document
952
+ * head based on provided tags and options.
953
+ * @param [tags] - The `tags` parameter in the `useMetadata` function is an object that contains
954
+ * metadata information for the webpage. It can include properties like `pageTitle`, `canonical`, and
955
+ * other custom metadata tags like `og:title`, `og:description`, `twitter:title`,
956
+ * `twitter:description`, etc. These tags
957
+ * @param [options] - The `options` parameter in the `useMetadata` function is an object that can
958
+ * contain the following properties:
959
+ * - `title`: An object that can have the following properties:
960
+ * - `template`: A string that defines the template for the page title. It can include a placeholder
961
+ * `%s` that will be replaced with the actual page title.
962
+ * - `prefix`: A string that will be used as the default title if no specific page title is provided.
963
+ * @returns The `useMetadata` function does not return anything. It is a custom hook that updates the
964
+ * document's metadata (such as title and meta tags) based on the provided `tags` and `options` whenever
965
+ * they change.
966
+ * This hook can't be reached by google crawler.
967
+ */
968
+
832
969
  const useMetadata = (tags = {}, options = {}) => {
833
970
  useEffect(() => {
834
971
  if (typeof document === 'undefined') return
@@ -919,6 +1056,12 @@ const findRoute = (routes, path) => {
919
1056
  return notFound
920
1057
  };
921
1058
 
1059
+ /**
1060
+ * The `RouterProvider` component manages routing in a Ryunix application by updating the location based
1061
+ * on window events and providing context for the current route.
1062
+ * @returns The `RouterProvider` component is returning a `RouterContext.Provider` component with a
1063
+ * `value` prop set to `contextValue`, and wrapping the `children` within a `Fragment`.
1064
+ */
922
1065
  const RouterProvider = ({ routes, children }) => {
923
1066
  const [location, setLocation] = useStore(window.location.pathname);
924
1067
 
@@ -955,10 +1098,24 @@ const RouterProvider = ({ routes, children }) => {
955
1098
  )
956
1099
  };
957
1100
 
1101
+ /**
1102
+ * The function `useRouter` returns the context of the Router for navigation in a Ryunix application.
1103
+ * @returns The `useRouter` function is returning the result of calling
1104
+ * `RouterContext.useContext('ryunix.navigation')`. This function is likely attempting to retrieve the
1105
+ * navigation context from the RouterContext.
1106
+ */
958
1107
  const useRouter = () => {
959
1108
  return RouterContext.useContext('ryunix.navigation')
960
1109
  };
961
1110
 
1111
+ /**
1112
+ * The `Children` function in JavaScript uses router hooks to handle scrolling to a specific element
1113
+ * based on the hash in the URL.
1114
+ * @returns The `Children` component is returning the result of calling `createElement` with
1115
+ * `route.component` as the first argument and an object with `key`, `params`, `query`, and `hash`
1116
+ * properties as the second argument. The `key` property is set to `location`, and the `params`,
1117
+ * `query`, and `hash` properties are passed as values from the component's props.
1118
+ */
962
1119
  const Children = () => {
963
1120
  const { route, params, query, location } = useRouter();
964
1121
  if (!route || !route.component) return null
@@ -980,6 +1137,12 @@ const Children = () => {
980
1137
  })
981
1138
  };
982
1139
 
1140
+ /**
1141
+ * The NavLink function in JavaScript is a component that generates a link element with customizable
1142
+ * classes and active state based on the current location.
1143
+ * @returns The `NavLink` component is returning a JSX element representing an anchor (`<a>`) tag with
1144
+ * the following attributes and properties:
1145
+ */
983
1146
  const NavLink = ({ to, exact = false, ...props }) => {
984
1147
  const { location, navigate } = useRouter();
985
1148
  const isActive = exact ? location === to : location.startsWith(to);
@@ -1116,7 +1279,12 @@ const updateHostComponent = (fiber) => {
1116
1279
  reconcileChildren(fiber, children);
1117
1280
  };
1118
1281
 
1119
- /* Image component */
1282
+ /**
1283
+ * The Component `Image` takes in a `src` and other props, and returns an `img` element with the
1284
+ * specified `src` and props.
1285
+ * @returns The `Image` component is being returned. It is a functional component that renders an `img`
1286
+ * element with the specified `src` and other props passed to it.
1287
+ */
1120
1288
  const Image = ({ src, ...props }) => {
1121
1289
  return createElement('img', { ...props, src })
1122
1290
  };
@@ -1400,6 +1568,17 @@ const scheduleWork = (root, priority = Priority.NORMAL) => {
1400
1568
  }
1401
1569
  };
1402
1570
 
1571
+ /**
1572
+ * The `render` function in JavaScript updates the DOM with a new element and schedules work to be done
1573
+ * on the element.
1574
+ * @param element - The `element` parameter in the `render` function is the element that you want to
1575
+ * render in the specified container. It could be a DOM element, a component, or any other valid
1576
+ * element that you want to display on the screen.
1577
+ * @param container - The `container` parameter in the `render` function is the DOM element where the
1578
+ * `element` will be rendered. It is the target container where the element will be appended as a
1579
+ * child.
1580
+ * @returns The `render` function is returning the `state.wipRoot` object.
1581
+ */
1403
1582
  const render = (element, container) => {
1404
1583
  const state = getState();
1405
1584
  state.wipRoot = {
@@ -1416,6 +1595,17 @@ const render = (element, container) => {
1416
1595
  return state.wipRoot
1417
1596
  };
1418
1597
 
1598
+ /**
1599
+ * The `init` function initializes a rendering process for a main element within a specified container
1600
+ * root element.
1601
+ * @param MainElement - MainElement is the main component or element that you want to render on the
1602
+ * webpage. It could be a React component, a DOM element, or any other element that you want to display
1603
+ * on the page.
1604
+ * @param [root=__ryunix] - The `root` parameter in the `init` function is a default parameter with the
1605
+ * value `'__ryunix'`. If no value is provided for `root` when calling the `init` function, it will
1606
+ * default to `'__ryunix'`.
1607
+ * @returns The `renderProcess` function is being returned from the `init` function.
1608
+ */
1419
1609
  const init = (MainElement, root = '__ryunix') => {
1420
1610
  const state = getState();
1421
1611
  state.containerRoot = document.getElementById(root);
@@ -1505,7 +1695,11 @@ let isBatching = false;
1505
1695
  let pendingUpdates = [];
1506
1696
 
1507
1697
  /**
1508
- * Batch multiple state updates into single render
1698
+ * The `batchUpdates` function in JavaScript allows for batching multiple updates and flushing them all
1699
+ * at once.
1700
+ * @param callback - The `callback` parameter in the `batchUpdates` function is a function that will be
1701
+ * executed within a batch update. This function can contain multiple updates that need to be processed
1702
+ * together in a batch to improve performance and avoid unnecessary re-renders.
1509
1703
  */
1510
1704
  const batchUpdates = (callback) => {
1511
1705
  const wasBatching = isBatching;
@@ -1523,7 +1717,9 @@ const batchUpdates = (callback) => {
1523
1717
  };
1524
1718
 
1525
1719
  /**
1526
- * Flush all pending updates
1720
+ * The `flushUpdates` function processes and executes pending updates stored in an array.
1721
+ * @returns If the `pendingUpdates` array is empty, the `flushUpdates` function will return nothing
1722
+ * (undefined).
1527
1723
  */
1528
1724
  const flushUpdates = () => {
1529
1725
  if (pendingUpdates.length === 0) return