@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.
@@ -76,7 +76,12 @@
76
76
  };
77
77
 
78
78
  /**
79
- * Create text element
79
+ * The `createTextElement` function creates a text element with the specified text content.
80
+ * @param text - The `text` parameter in the `createTextElement` function is the text content that you
81
+ * want to create a text element for. This text will be set as the `nodeValue` of the text element in
82
+ * the returned object.
83
+ * @returns A text element object is being returned with a type of RYUNIX_TYPES.TEXT_ELEMENT and props
84
+ * containing the text value provided in the function argument.
80
85
  */
81
86
  const createTextElement = (text) => {
82
87
  return {
@@ -89,7 +94,21 @@
89
94
  };
90
95
 
91
96
  /**
92
- * Create element
97
+ * The `createElement` function creates a virtual DOM element with specified type, properties, and
98
+ * children.
99
+ * @param type - The `type` parameter in the `createElement` function represents the type of element
100
+ * you want to create, such as a HTML tag like 'div', 'span', 'p', etc.
101
+ * @param props - The `props` parameter in the `createElement` function is an object that contains the
102
+ * properties or attributes for the element being created. These properties can include things like
103
+ * class names, styles, event handlers, and any other custom attributes you want to assign to the
104
+ * element. In the code snippet you provided,
105
+ * @param children - The `children` parameter in the `createElement` function represents the child
106
+ * elements or text content that will be nested within the created element. These children can be
107
+ * passed as arguments to the `createElement` function and will be rendered as part of the element's
108
+ * content.
109
+ * @returns An object is being returned with a `type` property representing the type of element, and a
110
+ * `props` property containing the element's properties. The `props` object includes the children of
111
+ * the element, which are processed to ensure they are in the correct format.
93
112
  */
94
113
  const createElement = (type, props, ...children) => {
95
114
  const safeProps = props || {};
@@ -108,7 +127,14 @@
108
127
  };
109
128
 
110
129
  /**
111
- * Fragment component
130
+ * The `Fragment` function in JavaScript creates a fragment element with the given children.
131
+ * @param props - The `props` parameter in the `Fragment` function is an object that contains the
132
+ * properties passed to the `Fragment` component. These properties can include `children`, which
133
+ * represents the child elements or components nested within the `Fragment`.
134
+ * @returns The `Fragment` component is returning a Ryunix fragment element created using the
135
+ * `createElement` function. The element is of type `RYUNIX_TYPES.RYUNIX_FRAGMENT` and contains the
136
+ * children passed to the `Fragment` component. If `props.children` is not an array, it is converted
137
+ * into an array before being spread into the `createElement` function.
112
138
  */
113
139
  const Fragment = (props) => {
114
140
  const children = Array.isArray(props.children)
@@ -456,6 +482,9 @@
456
482
  });
457
483
  };
458
484
 
485
+ /**
486
+ * The `commitRoot` function commits the changes made to the virtual DOM by updating the actual DOM.
487
+ */
459
488
  const commitRoot = () => {
460
489
  const state = getState();
461
490
  state.deletions.forEach(commitWork);
@@ -624,12 +653,35 @@
624
653
  return oldDeps.some((dep, i) => !Object.is(dep, newDeps[i]))
625
654
  };
626
655
 
656
+ /**
657
+ * The `useStore` function in JavaScript is a custom hook that uses a reducer to manage state updates
658
+ * based on actions provided.
659
+ * @param initialState - The `initialState` parameter in the `useStore` function is the initial state
660
+ * of the store that will be used with the `useReducer` hook. It represents the starting state of the
661
+ * store before any actions are dispatched to update it.
662
+ * @returns The `useStore` function is returning the result of calling the `useReducer` hook with the
663
+ * `reducer` function and the `initialState` as arguments.
664
+ */
627
665
  const useStore = (initialState) => {
628
666
  const reducer = (state, action) =>
629
667
  is.function(action) ? action(state) : action;
630
668
  return useReducer(reducer, initialState)
631
669
  };
632
670
 
671
+ /**
672
+ * The `useReducer` function in JavaScript is used to manage state and actions.
673
+ *
674
+ * @param reducer - The `reducer` parameter in the `useReducer` function is a function that specifies
675
+ * how the state should be updated in response to an action. It takes the current state and an action
676
+ * as arguments and returns the new state based on the action.
677
+ * @param initialState - The `initialState` parameter in the `useReducer` function represents the
678
+ * initial state of the reducer. It is the state that will be used when the reducer is first called or
679
+ * when the state needs to be reset. This initial state can be a simple value, an object, an array, or
680
+ * @param init - The `init` parameter in the `useReducer` function is an optional function that can be
681
+ * used to initialize the state. If provided, it will be called with the `initialState` as its argument
682
+ * and the return value will be used as the initial state for the reducer. If `init`
683
+ * @returns An array containing the current state and the dispatch function is being returned.
684
+ */
633
685
  const useReducer = (reducer, initialState, init) => {
634
686
  validateHookCall();
635
687
 
@@ -641,10 +693,9 @@
641
693
  hookID: hookIndex,
642
694
  type: RYUNIX_TYPES.RYUNIX_STORE,
643
695
  state: oldHook ? oldHook.state : init ? init(initialState) : initialState,
644
- queue: [], // Siempre nueva cola vacía
696
+ queue: [],
645
697
  };
646
698
 
647
- // Procesar acciones del render anterior
648
699
  if (oldHook?.queue) {
649
700
  oldHook.queue.forEach((action) => {
650
701
  try {
@@ -683,6 +734,16 @@
683
734
  return [hook.state, dispatch]
684
735
  };
685
736
 
737
+ /**
738
+ * The `useEffect` function in JavaScript is used to manage side effects in functional components by
739
+ * comparing dependencies and executing a callback function when dependencies change.
740
+ * @param callback - The `callback` parameter in the `useEffect` function is a function that will be
741
+ * executed as the effect. This function can perform side effects like data fetching, subscriptions, or
742
+ * DOM manipulations.
743
+ * @param deps - The `deps` parameter in the `useEffect` function stands for dependencies. It is an
744
+ * optional array that contains values that the effect depends on. The effect will only re-run if any
745
+ * of the values in the `deps` array have changed since the last render. If the `deps` array
746
+ */
686
747
  const useEffect = (callback, deps) => {
687
748
  validateHookCall();
688
749
 
@@ -710,6 +771,14 @@
710
771
  state.hookIndex++;
711
772
  };
712
773
 
774
+ /**
775
+ * The useRef function in JavaScript creates a reference object with an initial value for use in functional components.
776
+ * @param initialValue - The `initialValue` parameter in the `useRef` function represents the initial
777
+ * value that will be assigned to the `current` property of the reference object. This initial value
778
+ * will be used if there is no previous value stored in the hook.
779
+ * @returns The `useRef` function is returning the `current` property of the `hook.value` object, which
780
+ * contains the initial value passed to the `useRef` function.
781
+ */
713
782
  const useRef = (initialValue) => {
714
783
  validateHookCall();
715
784
 
@@ -728,6 +797,18 @@
728
797
  return hook.value
729
798
  };
730
799
 
800
+ /**
801
+ * The useMemo function in JavaScript is used to memoize the result of a computation based on
802
+ * dependencies.
803
+ * @param compute - The `compute` parameter in the `useMemo` function is a callback function that
804
+ * calculates the value that `useMemo` will memoize and return. This function will be called to compute
805
+ * the memoized value when necessary.
806
+ * @param deps - The `deps` parameter in the `useMemo` function refers to an array of dependencies.
807
+ * These dependencies are used to determine whether the memoized value needs to be recalculated or if
808
+ * the previously calculated value can be reused. The `useMemo` hook will recompute the memoized value
809
+ * only if
810
+ * @returns The `useMemo` function is returning the `value` calculated by the `compute` function.
811
+ */
731
812
  const useMemo = (compute, deps) => {
732
813
  validateHookCall();
733
814
 
@@ -768,6 +849,17 @@
768
849
  return value
769
850
  };
770
851
 
852
+ /**
853
+ * The useCallback function in JavaScript ensures that a callback function is memoized based on its
854
+ * dependencies.
855
+ * @param callback - A function that you want to memoize and return for later use.
856
+ * @param deps - The `deps` parameter in the `useCallback` function refers to an array of dependencies.
857
+ * These dependencies are used to determine when the callback function should be re-evaluated and
858
+ * memoized. If any of the dependencies change, the callback function will be re-executed and the
859
+ * memoized value will
860
+ * @returns The useCallback function is returning the memoized version of the callback function passed
861
+ * as the first argument, based on the dependencies array provided as the second argument.
862
+ */
771
863
  const useCallback = (callback, deps) => {
772
864
  if (!is.function(callback)) {
773
865
  throw new Error('useCallback requires a function as first argument')
@@ -775,6 +867,20 @@
775
867
  return useMemo(() => callback, deps)
776
868
  };
777
869
 
870
+ /**
871
+ * The createContext function creates a context provider and useContext hook in JavaScript.
872
+ * @param [contextId] - The `contextId` parameter in the `createContext` function is used to specify
873
+ * the unique identifier for the context being created. It defaults to `RYUNIX_TYPES.RYUNIX_CONTEXT` if
874
+ * not provided.
875
+ * @param [defaultValue] - The `defaultValue` parameter in the `createContext` function is used to
876
+ * specify the default value that will be returned by the `useContext` hook if no provider is found in
877
+ * the component tree. It is an optional parameter, and if not provided, an empty object `{}` will be
878
+ * used as
879
+ * @returns The `createContext` function returns an object with two properties: `Provider` and
880
+ * `useContext`. The `Provider` property is a component that accepts `children` and `value` props, and
881
+ * sets the `_contextId` and `_contextValue` properties on the element. The `useContext` property is a
882
+ * hook function that retrieves the context value based on the context ID provided, or
883
+ */
778
884
  const createContext = (
779
885
  contextId = RYUNIX_TYPES.RYUNIX_CONTEXT,
780
886
  defaultValue = {},
@@ -812,6 +918,10 @@
812
918
  return { Provider, useContext }
813
919
  };
814
920
 
921
+ /**
922
+ * The `useQuery` function extracts query parameters from the URL in a browser environment.
923
+ * @returns An object containing the query parameters from the current URL is being returned.
924
+ */
815
925
  const useQuery = () => {
816
926
  if (typeof window === 'undefined') return {}
817
927
 
@@ -823,6 +933,14 @@
823
933
  return query
824
934
  };
825
935
 
936
+ /**
937
+ * The function `useHash` in JavaScript is used to manage and update the hash portion of the URL in a
938
+ * web application.
939
+ * @returns The `useHash` function returns the current hash value from the window's location. If the
940
+ * window is undefined (e.g., in a server-side environment), it returns an empty string. The function
941
+ * also sets up an event listener to update the hash value when the hash in the URL changes and removes
942
+ * the event listener when the component unmounts.
943
+ */
826
944
  const useHash = () => {
827
945
  if (typeof window === 'undefined') return ''
828
946
 
@@ -835,6 +953,25 @@
835
953
  return hash
836
954
  };
837
955
 
956
+ /**
957
+ * The `useMetadata` function in JavaScript is used to dynamically update metadata tags in the document
958
+ * head based on provided tags and options.
959
+ * @param [tags] - The `tags` parameter in the `useMetadata` function is an object that contains
960
+ * metadata information for the webpage. It can include properties like `pageTitle`, `canonical`, and
961
+ * other custom metadata tags like `og:title`, `og:description`, `twitter:title`,
962
+ * `twitter:description`, etc. These tags
963
+ * @param [options] - The `options` parameter in the `useMetadata` function is an object that can
964
+ * contain the following properties:
965
+ * - `title`: An object that can have the following properties:
966
+ * - `template`: A string that defines the template for the page title. It can include a placeholder
967
+ * `%s` that will be replaced with the actual page title.
968
+ * - `prefix`: A string that will be used as the default title if no specific page title is provided.
969
+ * @returns The `useMetadata` function does not return anything. It is a custom hook that updates the
970
+ * document's metadata (such as title and meta tags) based on the provided `tags` and `options` whenever
971
+ * they change.
972
+ * This hook can't be reached by google crawler.
973
+ */
974
+
838
975
  const useMetadata = (tags = {}, options = {}) => {
839
976
  useEffect(() => {
840
977
  if (typeof document === 'undefined') return
@@ -925,6 +1062,12 @@
925
1062
  return notFound
926
1063
  };
927
1064
 
1065
+ /**
1066
+ * The `RouterProvider` component manages routing in a Ryunix application by updating the location based
1067
+ * on window events and providing context for the current route.
1068
+ * @returns The `RouterProvider` component is returning a `RouterContext.Provider` component with a
1069
+ * `value` prop set to `contextValue`, and wrapping the `children` within a `Fragment`.
1070
+ */
928
1071
  const RouterProvider = ({ routes, children }) => {
929
1072
  const [location, setLocation] = useStore(window.location.pathname);
930
1073
 
@@ -961,10 +1104,24 @@
961
1104
  )
962
1105
  };
963
1106
 
1107
+ /**
1108
+ * The function `useRouter` returns the context of the Router for navigation in a Ryunix application.
1109
+ * @returns The `useRouter` function is returning the result of calling
1110
+ * `RouterContext.useContext('ryunix.navigation')`. This function is likely attempting to retrieve the
1111
+ * navigation context from the RouterContext.
1112
+ */
964
1113
  const useRouter = () => {
965
1114
  return RouterContext.useContext('ryunix.navigation')
966
1115
  };
967
1116
 
1117
+ /**
1118
+ * The `Children` function in JavaScript uses router hooks to handle scrolling to a specific element
1119
+ * based on the hash in the URL.
1120
+ * @returns The `Children` component is returning the result of calling `createElement` with
1121
+ * `route.component` as the first argument and an object with `key`, `params`, `query`, and `hash`
1122
+ * properties as the second argument. The `key` property is set to `location`, and the `params`,
1123
+ * `query`, and `hash` properties are passed as values from the component's props.
1124
+ */
968
1125
  const Children = () => {
969
1126
  const { route, params, query, location } = useRouter();
970
1127
  if (!route || !route.component) return null
@@ -986,6 +1143,12 @@
986
1143
  })
987
1144
  };
988
1145
 
1146
+ /**
1147
+ * The NavLink function in JavaScript is a component that generates a link element with customizable
1148
+ * classes and active state based on the current location.
1149
+ * @returns The `NavLink` component is returning a JSX element representing an anchor (`<a>`) tag with
1150
+ * the following attributes and properties:
1151
+ */
989
1152
  const NavLink = ({ to, exact = false, ...props }) => {
990
1153
  const { location, navigate } = useRouter();
991
1154
  const isActive = exact ? location === to : location.startsWith(to);
@@ -1122,7 +1285,12 @@
1122
1285
  reconcileChildren(fiber, children);
1123
1286
  };
1124
1287
 
1125
- /* Image component */
1288
+ /**
1289
+ * The Component `Image` takes in a `src` and other props, and returns an `img` element with the
1290
+ * specified `src` and props.
1291
+ * @returns The `Image` component is being returned. It is a functional component that renders an `img`
1292
+ * element with the specified `src` and other props passed to it.
1293
+ */
1126
1294
  const Image = ({ src, ...props }) => {
1127
1295
  return createElement('img', { ...props, src })
1128
1296
  };
@@ -1406,6 +1574,17 @@
1406
1574
  }
1407
1575
  };
1408
1576
 
1577
+ /**
1578
+ * The `render` function in JavaScript updates the DOM with a new element and schedules work to be done
1579
+ * on the element.
1580
+ * @param element - The `element` parameter in the `render` function is the element that you want to
1581
+ * render in the specified container. It could be a DOM element, a component, or any other valid
1582
+ * element that you want to display on the screen.
1583
+ * @param container - The `container` parameter in the `render` function is the DOM element where the
1584
+ * `element` will be rendered. It is the target container where the element will be appended as a
1585
+ * child.
1586
+ * @returns The `render` function is returning the `state.wipRoot` object.
1587
+ */
1409
1588
  const render = (element, container) => {
1410
1589
  const state = getState();
1411
1590
  state.wipRoot = {
@@ -1422,6 +1601,17 @@
1422
1601
  return state.wipRoot
1423
1602
  };
1424
1603
 
1604
+ /**
1605
+ * The `init` function initializes a rendering process for a main element within a specified container
1606
+ * root element.
1607
+ * @param MainElement - MainElement is the main component or element that you want to render on the
1608
+ * webpage. It could be a React component, a DOM element, or any other element that you want to display
1609
+ * on the page.
1610
+ * @param [root=__ryunix] - The `root` parameter in the `init` function is a default parameter with the
1611
+ * value `'__ryunix'`. If no value is provided for `root` when calling the `init` function, it will
1612
+ * default to `'__ryunix'`.
1613
+ * @returns The `renderProcess` function is being returned from the `init` function.
1614
+ */
1425
1615
  const init = (MainElement, root = '__ryunix') => {
1426
1616
  const state = getState();
1427
1617
  state.containerRoot = document.getElementById(root);
@@ -1511,7 +1701,11 @@
1511
1701
  let pendingUpdates = [];
1512
1702
 
1513
1703
  /**
1514
- * Batch multiple state updates into single render
1704
+ * The `batchUpdates` function in JavaScript allows for batching multiple updates and flushing them all
1705
+ * at once.
1706
+ * @param callback - The `callback` parameter in the `batchUpdates` function is a function that will be
1707
+ * executed within a batch update. This function can contain multiple updates that need to be processed
1708
+ * together in a batch to improve performance and avoid unnecessary re-renders.
1515
1709
  */
1516
1710
  const batchUpdates = (callback) => {
1517
1711
  const wasBatching = isBatching;
@@ -1529,7 +1723,9 @@
1529
1723
  };
1530
1724
 
1531
1725
  /**
1532
- * Flush all pending updates
1726
+ * The `flushUpdates` function processes and executes pending updates stored in an array.
1727
+ * @returns If the `pendingUpdates` array is empty, the `flushUpdates` function will return nothing
1728
+ * (undefined).
1533
1729
  */
1534
1730
  const flushUpdates = () => {
1535
1731
  if (pendingUpdates.length === 0) return