@unsetsoft/ryunixjs 1.1.6-canary.78 → 1.1.6-canary.79
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/dist/Ryunix.js +25 -2
- package/dist/Ryunix.min.js +1 -1
- package/package.json +1 -1
package/dist/Ryunix.js
CHANGED
|
@@ -164,6 +164,7 @@
|
|
|
164
164
|
* `setState` function that can be used to update the state.
|
|
165
165
|
*/
|
|
166
166
|
const useStore = (initial) => {
|
|
167
|
+
console.log('[useStore] Initial state:', initial);
|
|
167
168
|
const oldHook =
|
|
168
169
|
vars.wipFiber.alternate &&
|
|
169
170
|
vars.wipFiber.alternate.hooks &&
|
|
@@ -173,14 +174,17 @@
|
|
|
173
174
|
queue: oldHook ? [...oldHook.queue] : [],
|
|
174
175
|
};
|
|
175
176
|
|
|
177
|
+
console.log('[useStore] Hook before processing queue:', hook);
|
|
176
178
|
hook.queue.forEach((action) => {
|
|
177
179
|
hook.state =
|
|
178
180
|
typeof action === STRINGS.function ? action(hook.state) : action;
|
|
179
181
|
});
|
|
180
182
|
|
|
183
|
+
console.log('[useStore] Hook after processing queue:', hook);
|
|
181
184
|
hook.queue = [];
|
|
182
185
|
|
|
183
186
|
const setState = (action) => {
|
|
187
|
+
console.log('[useStore] setState called with action:', action);
|
|
184
188
|
hook.queue.push(action);
|
|
185
189
|
|
|
186
190
|
vars.wipRoot = {
|
|
@@ -199,6 +203,10 @@
|
|
|
199
203
|
vars.hookIndex++;
|
|
200
204
|
}
|
|
201
205
|
|
|
206
|
+
console.log('[useStore] Returning state and setState:', [
|
|
207
|
+
hook.state,
|
|
208
|
+
setState,
|
|
209
|
+
]);
|
|
202
210
|
return [hook.state, setState]
|
|
203
211
|
};
|
|
204
212
|
|
|
@@ -683,6 +691,7 @@
|
|
|
683
691
|
* fiber's subtree
|
|
684
692
|
*/
|
|
685
693
|
const reconcileChildren = (wipFiber, elements) => {
|
|
694
|
+
console.log('[reconcileChildren] Start reconciliation for fiber:', wipFiber);
|
|
686
695
|
let index = 0;
|
|
687
696
|
let oldFiber = wipFiber.alternate && wipFiber.alternate.child;
|
|
688
697
|
let prevSibling = null;
|
|
@@ -724,6 +733,7 @@
|
|
|
724
733
|
}
|
|
725
734
|
|
|
726
735
|
if (newFiber) {
|
|
736
|
+
console.log('[reconcileChildren] New fiber created:', newFiber);
|
|
727
737
|
// Ensure hooks and state are properly initialized for new fibers
|
|
728
738
|
if (!newFiber.alternate) {
|
|
729
739
|
newFiber.hooks = [];
|
|
@@ -731,9 +741,17 @@
|
|
|
731
741
|
newFiber.hooks = newFiber.alternate.hooks || [];
|
|
732
742
|
}
|
|
733
743
|
|
|
734
|
-
//
|
|
744
|
+
// Synchronize state between parent and child fibers
|
|
735
745
|
if (wipFiber.hooks) {
|
|
736
|
-
newFiber.
|
|
746
|
+
newFiber.hooks = wipFiber.hooks.map((hook) => ({ ...hook }));
|
|
747
|
+
newFiber.hooks.forEach((hook) => {
|
|
748
|
+
if (hook.queue.length > 0) {
|
|
749
|
+
hook.state = hook.queue.reduce((state, action) => {
|
|
750
|
+
return typeof action === 'function' ? action(state) : action
|
|
751
|
+
}, hook.state);
|
|
752
|
+
hook.queue = [];
|
|
753
|
+
}
|
|
754
|
+
});
|
|
737
755
|
}
|
|
738
756
|
}
|
|
739
757
|
|
|
@@ -751,6 +769,11 @@
|
|
|
751
769
|
oldFiber.effectTag = EFFECT_TAGS.DELETION;
|
|
752
770
|
vars.deletions.push(oldFiber);
|
|
753
771
|
});
|
|
772
|
+
|
|
773
|
+
console.log(
|
|
774
|
+
'[reconcileChildren] Reconciliation complete for fiber:',
|
|
775
|
+
wipFiber,
|
|
776
|
+
);
|
|
754
777
|
};
|
|
755
778
|
|
|
756
779
|
var Reconciler = /*#__PURE__*/Object.freeze({
|
package/dist/Ryunix.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,
|
|
1
|
+
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("lodash")):"function"==typeof define&&define.amd?define(["exports","lodash"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self).Ryunix={},e.lodash)}(this,(function(e,o){"use strict";let t={containerRoot:{},nextUnitOfWork:{},currentRoot:{},wipRoot:{},deletions:[],wipFiber:{},hookIndex:0};const n=/[A-Z]/g,r=Object.freeze({TEXT_ELEMENT:Symbol("text.element"),Ryunix_ELEMENT:Symbol("ryunix.element"),RYUNIX_EFFECT:Symbol("ryunix.effect"),RYUNIX_MEMO:Symbol("ryunix.memo"),RYUNIX_URL_QUERY:Symbol("ryunix.urlQuery"),RYUNIX_REF:Symbol("ryunix.ref"),RYUNIX_STORE:Symbol("ryunix.store"),RYUNIX_REDUCE:Symbol("ryunix.reduce")}),s=Object.freeze({object:"object",function:"function",style:"ryunix-style",className:"ryunix-class",children:"children",boolean:"boolean",string:"string"}),i=Object.freeze({style:"style",className:"className"}),l=Object.freeze({PLACEMENT:Symbol("ryunix.reconciler.status.placement").toString(),UPDATE:Symbol("ryunix.reconciler.status.update").toString(),DELETION:Symbol("ryunix.reconciler.status.deletion").toString()}),a=e=>`${e}-${Math.random().toString(36).substring(2,9)}`,c=(e,o)=>(o=o||[],null==e||typeof e==s.boolean||(Array.isArray(e)?e.some((e=>{c(e,o)})):o.push(e)),o),p=(e,o,...t)=>{t=c(t,[]);const n=o&&o.key?a(o.key):a(r.Ryunix_ELEMENT.toString());return{type:e,props:{...o,key:n,children:t.map((e=>typeof e===s.object?e:u(e)))}}},u=e=>({type:r.TEXT_ELEMENT,props:{nodeValue:e,children:[]}}),d=(e,o)=>{t.wipRoot={dom:o,props:{children:[e]},alternate:t.currentRoot},t.deletions=[],t.nextUnitOfWork=t.wipRoot},f=e=>{console.log("[useStore] Initial state:",e);const o=t.wipFiber.alternate&&t.wipFiber.alternate.hooks&&t.wipFiber.alternate.hooks[t.hookIndex],n={state:o?o.state:e,queue:o?[...o.queue]:[]};console.log("[useStore] Hook before processing queue:",n),n.queue.forEach((e=>{n.state=typeof e===s.function?e(n.state):e})),console.log("[useStore] Hook after processing queue:",n),n.queue=[];const r=e=>{console.log("[useStore] setState called with action:",e),n.queue.push(e),t.wipRoot={dom:t.currentRoot.dom,props:{...t.currentRoot.props},alternate:t.currentRoot},t.nextUnitOfWork=t.wipRoot,t.deletions=[]};return t.wipFiber&&t.wipFiber.hooks&&(t.wipFiber.hooks.push(n),t.hookIndex++),console.log("[useStore] Returning state and setState:",[n.state,r]),[n.state,r]},h=(e,n)=>{const s=t.wipFiber.alternate&&t.wipFiber.alternate.hooks&&t.wipFiber.alternate.hooks[t.hookIndex],i={type:r.RYUNIX_EFFECT,deps:n};s&&o.isEqual(s.deps,i.deps)||e(),t.wipFiber.hooks&&(t.wipFiber.hooks.push(i),t.hookIndex++)},m=(e,n)=>{const s=t.wipFiber.alternate&&t.wipFiber.alternate.hooks&&t.wipFiber.alternate.hooks[t.hookIndex],i={type:r.RYUNIX_MEMO,value:null,deps:n};return s&&o.isEqual(s.deps,i.deps)?i.value=s.value:i.value=e(),t.wipFiber.hooks&&(t.wipFiber.hooks.push(i),t.hookIndex++),i.value},y=()=>{const e=new URLSearchParams(window.location.search),o={};for(let[t,n]of e.entries())o[t]=n;return o},b=e=>e.startsWith("on"),E=e=>e!==s.children&&!b(e),k=(e,o)=>t=>e[t]!==o[t],w=e=>o=>!(o in e),R=e=>{e.hooks&&e.hooks.filter((e=>e.tag===r.RYUNIX_EFFECT&&e.cancel)).forEach((e=>{e.cancel()}))},g=e=>{e.hooks&&e.hooks.filter((e=>e.tag===r.RYUNIX_EFFECT&&e.effect)).forEach((e=>{e.cancel=e.effect()}))},x=e=>{const o=e.type==r.TEXT_ELEMENT?document.createTextNode(""):document.createElement(e.type);return F(o,{},e.props),o},F=(e,o,t)=>{Object.keys(o).filter(b).filter((e=>w(t)(e)||k(o,t)(e))).forEach((t=>{const n=t.toLowerCase().substring(2);e.removeEventListener(n,o[t])})),Object.keys(o).filter(E).filter(w(t)).forEach((o=>{e[o]=""})),Object.keys(t).filter(E).filter(k(o,t)).forEach((n=>{if(n===s.style)N(e,t["ryunix-style"]);else if(n===i.style)N(e,t.style);else if(n===s.className){if(""===t["ryunix-class"])throw new Error("data-class cannot be empty.");o["ryunix-class"]&&e.classList.remove(...o["ryunix-class"].split(/\s+/)),e.classList.add(...t["ryunix-class"].split(/\s+/))}else if(n===i.className){if(""===t.className)throw new Error("className cannot be empty.");o.className&&e.classList.remove(...o.className.split(/\s+/)),e.classList.add(...t.className.split(/\s+/))}else e[n]=t[n]})),Object.keys(t).filter(b).filter(k(o,t)).forEach((o=>{const n=o.toLowerCase().substring(2);e.addEventListener(n,t[o])}))},N=(e,o)=>{e.style=Object.keys(o).reduce(((e,t)=>e+=`${t.replace(n,(function(e){return"-"+e.toLowerCase()}))}: ${o[t]};`),"")};var _=Object.freeze({__proto__:null,DomStyle:N,createDom:x,updateDom:F});const T=()=>{t.deletions.forEach(v),t.wipRoot&&t.wipRoot.child&&(v(t.wipRoot.child),t.currentRoot=t.wipRoot),t.wipRoot=void 0},v=e=>{if(!e)return;let o=e.parent;for(;!o.dom;)o=o.parent;const t=o.dom;if(e.effectTag===l.PLACEMENT&&null!=e.dom)t.appendChild(e.dom),g(e);else if(e.effectTag===l.UPDATE&&null!=e.dom)R(e),F(e.dom,e.alternate.props,e.props),g(e);else if(e.effectTag===l.DELETION)return I(e,t),void R(e);v(e.child),v(e.sibling)},I=(e,o)=>{e.dom?o.removeChild(e.dom):I(e.child,o)};var O=Object.freeze({__proto__:null,commitDeletion:I,commitRoot:T,commitWork:v});const S=(e,o)=>{console.log("[reconcileChildren] Start reconciliation for fiber:",e);let n=0,r=e.alternate&&e.alternate.child,s=null;const i=new Map;for(;r;){const e=r.props.key||r.type;i.set(e,r),r=r.sibling}for(;n<o.length;){const t=o[n],r=t.props.key||t.type,a=i.get(r);let c;a&&t&&t.type===a.type?(c={type:a.type,props:t.props,dom:a.dom,parent:e,alternate:a,effectTag:l.UPDATE},i.delete(r)):t&&(c={type:t.type,props:t.props,dom:void 0,parent:e,alternate:void 0,effectTag:l.PLACEMENT}),c&&(console.log("[reconcileChildren] New fiber created:",c),c.alternate?c.hooks=c.alternate.hooks||[]:c.hooks=[],e.hooks&&(c.hooks=e.hooks.map((e=>({...e}))),c.hooks.forEach((e=>{e.queue.length>0&&(e.state=e.queue.reduce(((e,o)=>"function"==typeof o?o(e):o),e.state),e.queue=[])})))),0===n?e.child=c:s&&(s.sibling=c),s=c,n++}i.forEach((e=>{e.effectTag=l.DELETION,t.deletions.push(e)})),console.log("[reconcileChildren] Reconciliation complete for fiber:",e)};var C=Object.freeze({__proto__:null,reconcileChildren:S});const L=e=>{t.wipFiber=e,t.hookIndex=0,t.wipFiber.hooks=[];const o=e.type(e.props);let n=Array.isArray(o)?o:[o];S(e,n)},U=e=>{e.dom||(e.dom=x(e)),S(e,e.props.children)};var j=Object.freeze({__proto__:null,updateFunctionComponent:L,updateHostComponent:U});const q=e=>{let o=!1;for(;t.nextUnitOfWork&&!o;)t.nextUnitOfWork=M(t.nextUnitOfWork),o=e.timeRemaining()<1;!t.nextUnitOfWork&&t.wipRoot&&T(),requestIdleCallback(q)};requestIdleCallback(q);const M=e=>{if(e.type instanceof Function?L(e):U(e),e.child)return e.child;let o=e;for(;o;){if(o.sibling)return o.sibling;o=o.parent}};var X={createElement:p,render:d,init:(e,o="__ryunix")=>{t.containerRoot=document.getElementById(o),d(e,t.containerRoot)},Fragment:e=>e.children,Dom:_,Workers:Object.freeze({__proto__:null,performUnitOfWork:M,workLoop:q}),Reconciler:C,Components:j,Commits:O};window.Ryunix=X,e.default=X,e.useCallback=(e,o)=>m((()=>e),o),e.useEffect=h,e.useMemo=m,e.useQuery=y,e.useRef=e=>{const o=t.wipFiber.alternate&&t.wipFiber.alternate.hooks&&t.wipFiber.alternate.hooks[t.hookIndex],n={type:r.RYUNIX_REF,value:o?o.value:{current:e}};return t.wipFiber.hooks&&(t.wipFiber.hooks.push(n),t.hookIndex++),n.value},e.useRouter=e=>{const[o,t]=f(window.location.pathname),n=(e,o)=>{const t=o.split("?")[0],r=e.find((e=>e.NotFound)),s=r?{route:{component:r.NotFound},params:{}}:{route:{component:null},params:{}};for(const r of e){if(r.subRoutes){const e=n(r.subRoutes,o);if(e)return e}if("*"===r.path)return s;if(!r.path||"string"!=typeof r.path){console.warn("Invalid route detected:",r),console.info("if you are using { NotFound: NotFound } please add { path: '*', NotFound: NotFound }");continue}const e=[],i=new RegExp(`^${r.path.replace(/:\w+/g,(o=>(e.push(o.substring(1)),"([^/]+)")))}$`),l=t.match(i);if(l){return{route:r,params:e.reduce(((e,o,t)=>(e[o]=l[t+1],e)),{})}}}return s},r=e=>{window.history.pushState({},"",e),i(e)},i=e=>{const o=e.split("?")[0];t(o)};h((()=>{const e=()=>i(window.location.pathname);return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)}),[]);const l=n(e,o)||{};return{Children:()=>{const e=y(),{route:o}=l;return o&&o.component&&typeof o.component===s.function?o.component({params:l.params||{},query:e}):(console.error("Component not found for current path or the component is not a valid function:",l),null)},NavLink:({to:e,...o})=>p("a",{href:e,onClick:o=>{o.preventDefault(),r(e)},...o},o.children),navigate:r}},e.useStore=f,Object.defineProperty(e,"__esModule",{value:!0})}));
|