olova 2.0.8 → 2.0.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.
@@ -1,4 +1,6 @@
1
- import o from "./memo.js";
2
- export default function r(r, t, e) {
3
- return o(r, () => t, e);
1
+ import { createMemoHook } from "./memo.js";
2
+ export function createCallbackHook(o) {
3
+ return function (e, r) {
4
+ return o.$memo(() => e, r);
5
+ };
4
6
  }
@@ -1,21 +1,25 @@
1
- export default function e(e, r) {
2
- const n = e.getCurrentInstance(),
3
- o = n.currentHook++;
4
- if (!n.hooks[o]) {
5
- n.hooks[o] = r._currentValue;
6
- const e = { instance: n, hookIndex: o, version: r._version };
7
- r._subscribers.add(e),
8
- n.contextSubscriptions.add(() => {
9
- r._subscribers.delete(e);
10
- });
11
- }
12
- const s = Array.from(r._subscribers).find(
13
- (e) => e.instance === n && e.hookIndex === o
14
- );
15
- return (
16
- s &&
17
- s.version !== r._version &&
18
- ((n.hooks[o] = r._currentValue), (s.version = r._version)),
19
- r._currentValue
20
- );
1
+ export function createContextHook(e) {
2
+ return function (n) {
3
+ const s = e.getCurrentInstance(),
4
+ t = s.currentHook++;
5
+ if (!s.hooks[t]) {
6
+ s.hooks[t] = n._currentValue;
7
+ const e = { instance: s, hookIndex: t, version: n._version };
8
+ n.subscribers.set(s, e),
9
+ s.contextSubscriptions.add(() => {
10
+ n.subscribers.delete(s);
11
+ });
12
+ }
13
+ const r = n.subscribers.get(s);
14
+ return (
15
+ r &&
16
+ r.version !== n._version &&
17
+ ((s.hooks[t] = n._currentValue),
18
+ (r.version = n._version),
19
+ (e.dirtyInstances = e.dirtyInstances || new Set()),
20
+ e.dirtyInstances.add(s),
21
+ e.scheduleUpdate()),
22
+ n._currentValue
23
+ );
24
+ };
21
25
  }
@@ -1,11 +1,20 @@
1
- export default function e(e, n, t) {
2
- const o = e.getCurrentInstance(),
3
- s = o.currentHook++,
4
- c = o.hooks[s];
5
- (!c || !t || t.length !== c.length || t.some((e, n) => e !== c[n])) &&
6
- o.pendingEffects.push(() => {
7
- o.cleanups.has(s) && o.cleanups.get(s)();
8
- const e = n();
9
- (o.hooks[s] = t), "function" == typeof e && o.cleanups.set(s, e);
10
- });
1
+ export function createEffectHook(n) {
2
+ return function (e, t) {
3
+ const o = n.getCurrentInstance(),
4
+ u = o.currentHook++;
5
+ o.hooks[u] ||
6
+ (o.hooks[u] = { deps: null, cleanup: null, effect: e, lastRun: 0 });
7
+ const c = o.hooks[u];
8
+ (t
9
+ ? c.deps &&
10
+ n.areArraysEqual(
11
+ t.map((n) => ("function" == typeof n ? n() : n)),
12
+ c.deps
13
+ )
14
+ : 0 !== c.lastRun) ||
15
+ ("function" == typeof c.cleanup && c.cleanup(),
16
+ (c.cleanup = e()),
17
+ (c.deps = t?.map((n) => ("function" == typeof n ? n() : n))),
18
+ (c.lastRun = Date.now()));
19
+ };
11
20
  }
@@ -1,15 +1,17 @@
1
- export default function o(o, t, n) {
2
- const e = o.getCurrentInstance(),
3
- r = e.currentHook++,
4
- [s, u] = e.hooks[r] || [void 0, void 0];
5
- if (
6
- !u ||
7
- !n ||
8
- n.length !== u.length ||
9
- n.some((t, n) => !o.shallowEqual(t, u[n]))
10
- ) {
11
- const o = t();
12
- return (e.hooks[r] = [o, n]), o;
13
- }
14
- return s;
1
+ export function createMemoHook(o) {
2
+ return function (n, t) {
3
+ const e = o.getCurrentInstance(),
4
+ r = e.currentHook++,
5
+ [u, c] = e.hooks[r] || [void 0, void 0];
6
+ if (
7
+ !c ||
8
+ !t ||
9
+ t.length !== c.length ||
10
+ t.some((n, t) => !o.shallowEqual(n, c[t]))
11
+ ) {
12
+ const o = n();
13
+ return (e.hooks[r] = [o, t]), o;
14
+ }
15
+ return u;
16
+ };
15
17
  }
@@ -1,11 +1,21 @@
1
- export default function o(o, e, t) {
2
- const n = o.getCurrentInstance(),
3
- s = n.currentHook++;
4
- n.hooks[s] = n.hooks[s] || t;
5
- return [
6
- n.hooks[s],
7
- (t) => {
8
- (n.hooks[s] = e(n.hooks[s], t)), o.scheduleUpdate();
9
- },
10
- ];
1
+ export function createReducerHook(t) {
2
+ return function (s, e, o) {
3
+ const n = t.getCurrentInstance(),
4
+ c = n.currentHook++;
5
+ if (!n.hooks[c]) {
6
+ const a = o ? o(e) : e;
7
+ n.hooks[c] = {
8
+ state: a,
9
+ dispatch: (e) => {
10
+ const o = s(n.hooks[c].state, e);
11
+ o !== n.hooks[c].state &&
12
+ ((n.hooks[c].state = o),
13
+ t.dirtyInstances || (t.dirtyInstances = new Set()),
14
+ t.dirtyInstances.add(n),
15
+ t.scheduleUpdate());
16
+ },
17
+ };
18
+ }
19
+ return [n.hooks[c].state, n.hooks[c].dispatch];
20
+ };
11
21
  }
package/dist/hooks/ref.js CHANGED
@@ -1,5 +1,7 @@
1
- export default function o(o, t) {
2
- const n = o.getCurrentInstance(),
3
- r = n.currentHook++;
4
- return n.hooks[r] || (n.hooks[r] = { current: t }), n.hooks[r];
1
+ export function createRefHook(o) {
2
+ return function (n) {
3
+ const r = o.getCurrentInstance(),
4
+ t = r.currentHook++;
5
+ return r.hooks[t] || (r.hooks[t] = { current: n }), r.hooks[t];
6
+ };
5
7
  }
@@ -1,19 +1,21 @@
1
- export default function e(e, o) {
2
- const t = e.getCurrentInstance(),
3
- s = t.currentHook++;
4
- return (
5
- t.hooks[s] ||
6
- (t.hooks[s] = {
7
- value: o,
8
- setValue: (o) => {
9
- const n = "function" == typeof o ? o(t.hooks[s].value) : o;
10
- n !== t.hooks[s].value &&
11
- ((t.hooks[s].value = n),
12
- (e.dirtyInstances = e.dirtyInstances || new Set()),
13
- e.dirtyInstances.add(t),
14
- e.scheduleUpdate());
15
- },
16
- }),
17
- [t.hooks[s].value, t.hooks[s].setValue]
18
- );
1
+ export function createStateHook(e) {
2
+ return function (t) {
3
+ const o = e.getCurrentInstance(),
4
+ n = o.currentHook++;
5
+ return (
6
+ o.hooks[n] ||
7
+ (o.hooks[n] = {
8
+ value: t,
9
+ setValue: (t) => {
10
+ const s = "function" == typeof t ? t(o.hooks[n].value) : t;
11
+ s !== o.hooks[n].value &&
12
+ ((o.hooks[n].value = s),
13
+ e.dirtyInstances || (e.dirtyInstances = new Set()),
14
+ e.dirtyInstances.add(o),
15
+ e.scheduleUpdate());
16
+ },
17
+ }),
18
+ [() => o.hooks[n].value, o.hooks[n].setValue]
19
+ );
20
+ };
19
21
  }
package/dist/olova.js CHANGED
@@ -1 +1 @@
1
- import stateHook from"./hooks/state.js";import effectHook from"./hooks/effect.js";import memoHook from"./hooks/memo.js";import callbackHook from"./hooks/callback.js";import reducerHook from"./hooks/reducer.js";import refHook from"./hooks/ref.js";import contextHook from"./hooks/context.js";class Olovav2{constructor(){this.rootElement=null,this.components=new Map,this.componentStack=[],this.componentInstances=new Map,this.pendingUpdates=[],this.pendingEffects=[],this.contextSubscriptions=new WeakMap,this.isBatchingUpdates=!1,this.hasScheduledFlush=!1,this.dirtyInstances=null}createElement(e,t,...n){return null==e?(console.error("Element type cannot be null or undefined"),null):"function"==typeof e||"string"==typeof e?{type:e,props:{...t,children:n.flat()}}:(console.error("Invalid element type:",e),null)}render(e,t){try{if(null==e)return;if("string"==typeof e||"number"==typeof e){if(t.nodeType===Node.TEXT_NODE)t.textContent!==String(e)&&(t.textContent=String(e));else if(1===t.childNodes.length&&t.firstChild.nodeType===Node.TEXT_NODE)t.firstChild.textContent!==String(e)&&(t.firstChild.textContent=String(e));else{const n=document.createTextNode(String(e));t.innerHTML="",t.appendChild(n)}return}if(Array.isArray(e))return void this.reconcileChildren(t,e);if("function"==typeof e.type){const n=e.type,o=this.getComponentInstance(n);if(!n.__isMemoized||!o.lastProps||!this.shallowEqual(o.lastProps,e.props)){this.componentStack.push(o),o.currentHook=0,o.lastProps=e.props;const s=n(e.props);o.lastResult=s,this.componentStack.pop(),this.render(s,t)}else this.render(o.lastResult,t);return}if("string"==typeof e.type){let n;t.nodeType===Node.ELEMENT_NODE&&t.tagName.toLowerCase()===e.type?n=t:1===t.childNodes.length&&t.firstChild.nodeType===Node.ELEMENT_NODE&&t.firstChild.tagName.toLowerCase()===e.type?n=t.firstChild:(n=document.createElement(e.type),t.innerHTML="",t.appendChild(n)),this.applyProps(n,e.props);const o=e.props.children||[],s=Array.isArray(o)?o:[o];this.reconcileChildren(n,s)}}catch(e){console.error("Render error:",e)}}reconcileChildren(e,t){const n=Array.from(e.childNodes),o=Math.max(n.length,t.length);for(let s=0;s<o;s++)if(s>=t.length)e.removeChild(n[s]);else if(s>=n.length){const n="string"==typeof t[s]?.type?document.createElement(t[s].type):document.createTextNode("");e.appendChild(n),this.render(t[s],n)}else{const o=n[s],r=t[s];if("string"==typeof r?.type)if(o.nodeType===Node.ELEMENT_NODE&&o.tagName.toLowerCase()===r.type)this.render(r,o);else{const t=document.createElement(r.type);e.replaceChild(t,o),this.render(r,t)}else this.render(r,o)}}applyProps(e,t){const n=e._props||{},o=t||{};e._props=o,Object.keys(n).forEach((t=>{if(!(t in o)&&"children"!==t)if(t.startsWith("on")){const o=t.toLowerCase().substring(2);e.removeEventListener(o,n[t])}else"className"===t?e.removeAttribute("class"):e[t]=""})),Object.keys(o).forEach((t=>{if("ref"===t&&o[t])o[t].current=e;else if(t.startsWith("on")){const s=t.toLowerCase().substring(2);n[t]&&e.removeEventListener(s,n[t]),e.addEventListener(s,o[t])}else"children"!==t&&("className"===t?n[t]!==o[t]&&e.setAttribute("class",o[t]):n[t]!==o[t]&&(e[t]=o[t]))}))}getComponentInstance(e){return this.componentInstances.has(e)||this.componentInstances.set(e,{hooks:[],currentHook:0,effects:[],cleanups:new Map,pendingEffects:[],contextSubscriptions:new Set,lastProps:null,lastResult:null}),this.componentInstances.get(e)}renderComponent(e,t){const n=this.getComponentInstance(e);this.componentStack.push(n),n.currentHook=0;if(!n.lastResult||this.shouldComponentUpdate(n,e)){const o=e();n.lastResult=o,this.render(o,t),n.pendingEffects.length>0&&(this.pendingEffects.push(...n.pendingEffects),n.pendingEffects=[])}else this.render(n.lastResult,t);this.componentStack.pop()}shouldComponentUpdate(e,t){return!e.lastProps||!this.shallowEqual(e.lastProps,t)}getCurrentInstance(){return this.componentStack[this.componentStack.length-1]}createContext(e){const t={_currentValue:e,_defaultValue:e,_subscribers:new Set,_version:0,Provider:({value:e,children:n})=>{const o=this.getCurrentInstance(),s=o.currentHook++,r=o.hooks[s];return this.shallowEqual(r,e)||(t._currentValue=e,t._version++,t._subscribers.forEach((t=>{t.instance.hooks[t.hookIndex]=e,this.scheduleUpdate()}))),o.hooks[s]=e,n},Consumer:({children:e})=>{if("function"!=typeof e)throw new Error("Context.Consumer expects a function as a child");return e(t._currentValue)}};return t}scheduleUpdate(){if(!this.isBatchingUpdates){this.isBatchingUpdates=!0;const e=this.getCurrentInstance();if(e){this.dirtyInstances=new Set([e]);const t=this.componentStack[this.componentStack.length-2];t&&this.dirtyInstances.add(t)}this.hasScheduledFlush||(this.hasScheduledFlush=!0,queueMicrotask((()=>{this.flushUpdates(),this.isBatchingUpdates=!1})))}}flushUpdates(){try{if(this.rootElement&&this.dirtyInstances?.size>0)for(this.components.forEach(((e,t)=>{const n=this.getComponentInstance(e);this.dirtyInstances.has(n)&&this.renderComponent(e,t)}));this.pendingEffects.length>0;){this.pendingEffects.shift()()}}finally{this.dirtyInstances=new Set,this.hasScheduledFlush=!1,this.pendingUpdates=[]}}mount(e,t){for(this.rootElement=t,this.components.set(t,e),this.renderComponent(e,t);this.pendingEffects.length>0;){this.pendingEffects.shift()()}}unmount(e){const t=this.components.get(e);if(t){const n=this.componentInstances.get(t);n&&(n.contextSubscriptions.forEach((e=>e())),n.contextSubscriptions.clear(),n.cleanups.forEach((e=>e())),n.cleanups.clear(),this.componentInstances.delete(t)),this.components.delete(e)}e.innerHTML=""}memo(e){const t=t=>{const n=this.getCurrentInstance();if(!n)return e(t);const o=n.currentHook++,s=n.hooks[o]||{props:null,result:null},r=!s.props||!this.deepEqual(t,s.props);if(!s.result||r){const s=e(t);return n.hooks[o]={props:t,result:s},s}return s.result};return t.__isMemoized=!0,t.__original=e,t}shallowEqual(e,t){if(e===t)return!0;if(!e||!t)return!1;if("object"!=typeof e||"object"!=typeof t)return e===t;const n=Object.keys(e),o=Object.keys(t);return n.length===o.length&&n.every((n=>t.hasOwnProperty(n)&&e[n]===t[n]))}deepEqual(e,t){if(e===t)return!0;if(!e||!t)return!1;if(typeof e!=typeof t)return!1;if("object"!=typeof e)return e===t;if(Array.isArray(e))return!(!Array.isArray(t)||e.length!==t.length)&&e.every(((e,n)=>this.deepEqual(e,t[n])));const n=Object.keys(e),o=Object.keys(t);return n.length===o.length&&n.every((n=>t.hasOwnProperty(n)&&this.deepEqual(e[n],t[n])))}}const Olova=new Olovav2;export const h=Olova.createElement.bind(Olova);export const Fragment=e=>e?e.children:null;export const $state=e=>stateHook(Olova,e);export const $effect=(e,t)=>effectHook(Olova,e,t);export const $memo=(e,t)=>memoHook(Olova,e,t);export const $callback=(e,t)=>callbackHook(Olova,e,t);export const $reducer=(e,t)=>reducerHook(Olova,e,t);export const $ref=e=>refHook(Olova,e);export const $context=e=>contextHook(Olova,e);export const createContext=Olova.createContext.bind(Olova);export const memo=Olova.memo.bind(Olova);export default Olova;function isFunctionComponent(e){return"function"==typeof e}function renderComponent(e,t){try{return"function"==typeof e.type?e.type(e.props):"string"==typeof e?e:Array.isArray(e)?e.map((e=>renderComponent(e,t))):null==e?"":"object"==typeof e?e:String(e)}catch(e){return console.error("Error rendering component:",e),null}}
1
+ import{createStateHook}from"./hooks/state";import{createEffectHook}from"./hooks/effect";import{createMemoHook}from"./hooks/memo";import{createRefHook}from"./hooks/ref";import{createCallbackHook}from"./hooks/callback";import{createContextHook}from"./hooks/context";class ReactLite{constructor(){this.rootElement=null,this.components=new Map,this.componentStack=[],this.componentInstances=new Map,this.pendingUpdates=[],this.pendingEffects=[],this.contextSubscriptions=new WeakMap,this.isBatchingUpdates=!1,this.hasScheduledFlush=!1,this.dirtyInstances=null,this.mountedComponents=new Map,this.$state=createStateHook(this),this.$effect=createEffectHook(this),this.$memo=createMemoHook(this),this.$ref=createRefHook(this),this.$callback=createCallbackHook(this),this.$context=createContextHook(this)}createElement(e,t,...n){if(null==e)return console.error("Element type cannot be null or undefined"),null;const o=n.flat(),r=[];return o.forEach((e=>{"string"==typeof e||"number"==typeof e?r.length>0&&("string"==typeof r[r.length-1]||"number"==typeof r[r.length-1])?r[r.length-1]=String(r[r.length-1])+String(e):r.push(e):null!=e&&r.push(e)})),e===Fragment?{type:Fragment,props:{...t,children:r}}:{type:e,props:{...t,children:r}}}render(e,t){try{if(null==e)return;if("string"==typeof e||"number"==typeof e)return void t.appendChild(document.createTextNode(e));if(Array.isArray(e))return void e.forEach((e=>this.render(e,t)));if(!e.type)return void console.error("Invalid element:",e);if(e.type===Fragment)return void(e.props?.children||[]).forEach((e=>this.render(e,t)));if("function"==typeof e.type){const n=e.type,o=this.getComponentInstance(n);this.componentStack.push(o),o.currentHook=0,o.lastProps=e.props;const r=n(e.props);return o.lastResult=r,this.componentStack.pop(),void this.render(r,t)}if("string"==typeof e.type){const n=document.createElement(e.type);return this.applyProps(n,e.props),(e.props?.children||[]).forEach((e=>this.render(e,n))),void t.appendChild(n)}console.error("Unhandled element type:",e.type)}catch(t){console.error("Render error:",t),console.error("Element:",e)}}applyProps(e,t){Object.keys(t||{}).forEach((n=>{if("ref"===n&&t[n])t[n].current=e;else if(n.startsWith("on")){const o=n.toLowerCase().substring(2);e.addEventListener(o,t[n])}else"children"!==n&&("className"===n?e.setAttribute("class",t[n]):e[n]=t[n])}))}getComponentInstance(e){return this.componentInstances.has(e)||this.componentInstances.set(e,{hooks:[],currentHook:0,effects:new Map,cleanups:new Set,pendingEffects:[],contextSubscriptions:new Set,lastProps:null,lastResult:null}),this.componentInstances.get(e)}renderComponent(e,t){const n=this.getComponentInstance(e);this.componentStack.push(n),n.currentHook=0;const o=e();n.lastResult=o,this.render(o,t),this.componentStack.pop()}scheduleUpdate(){this.isBatchingUpdates||(this.isBatchingUpdates=!0,queueMicrotask((()=>{const e=new Set(this.dirtyInstances);this.dirtyInstances=new Set,e.forEach((e=>{const t=Array.from(this.components.keys()).find((t=>this.componentInstances.get(t)===e));if(t){this.componentStack.push(e),e.currentHook=0;const n=t(),o=e.lastResult;this.areNodesEqual(n,o)||(e.lastResult=n,this.rootElement&&this.updateDOM(this.rootElement,o,n)),this.componentStack.pop()}})),this.isBatchingUpdates=!1})))}updateDOM(e,t,n){if(this.areNodesEqual(t,n))return;const o=(e,t,n,r=0)=>{if("string"==typeof t||"number"==typeof t){const n=e.childNodes[r];return void(n?3===n.nodeType?n.textContent!==String(t)&&(n.textContent=String(t)):e.replaceChild(document.createTextNode(String(t)),n):e.appendChild(document.createTextNode(String(t))))}if(n&&this.areNodesEqual(n,t))return;if(!t)return void(e.childNodes[r]&&e.removeChild(e.childNodes[r]));if(!n||n.type!==t.type){const n=this.createElementFromVNode(t);return void(e.childNodes[r]?e.replaceChild(n,e.childNodes[r]):e.appendChild(n))}const s=e.childNodes[r];"string"==typeof t.type&&this.updateProps(s,n.props||{},t.props||{});const i=Array.isArray(t.props?.children)?t.props.children:[t.props?.children].filter(Boolean),c=Array.isArray(n.props?.children)?n.props.children:[n.props?.children].filter(Boolean),a=Math.max(i.length,c.length);for(let e=0;e<a;e++)o(s,i[e],c[e],e)};o(e,n,t)}updateProps(e,t,n){Object.keys(t).forEach((o=>{if("children"!==o&&!(o in n))if(o.startsWith("on")){const n=o.toLowerCase().substring(2);e.removeEventListener(n,t[o])}else"className"===o?e.removeAttribute("class"):e.removeAttribute(o)})),Object.keys(n).forEach((o=>{if("children"!==o&&n[o]!==t[o])if(o.startsWith("on")){const r=o.toLowerCase().substring(2);t[o]&&e.removeEventListener(r,t[o]),e.addEventListener(r,n[o])}else"className"===o?e.setAttribute("class",n[o]):o in e?e[o]=n[o]:e.setAttribute(o,n[o])}))}flushUpdates(){for(;this.pendingUpdates.length>0;){this.pendingUpdates.shift()()}this.hasScheduledFlush=!1}mount(e,t){this.rootElement=t,this.components.set(e,e),this.mountedComponents.has(t)&&this.unmount(t),t.innerHTML="",this.mountedComponents.set(t,new Set),this.renderComponent(e,t)}unmount(e){console.log("Unmounting component...");Array.from(this.componentInstances.values()).forEach((e=>{e.cleanups&&(e.cleanups.forEach((e=>{try{console.log("Running cleanup on unmount"),e()}catch(e){console.error("Error in unmount cleanup:",e)}})),e.cleanups.clear())})),this.componentInstances.clear(),e.innerHTML=""}createElementFromVNode(e){if("string"==typeof e||"number"==typeof e)return document.createTextNode(e);if(e.type===Fragment){const t=document.createDocumentFragment();return(e.props&&e.props.children?e.props.children:[]).forEach((e=>{t.appendChild(this.createElementFromVNode(e))})),t}if("string"==typeof e.type){const t=document.createElement(e.type);if(e.props){Object.keys(e.props).forEach((n=>{if("children"!==n)if("className"===n)t.setAttribute("class",e.props[n]);else if(n.startsWith("on")){const o=n.toLowerCase().substring(2);t.addEventListener(o,e.props[n])}else t[n]=e.props[n]}));(e.props.children||[]).forEach((e=>{t.appendChild(this.createElementFromVNode(e))}))}return t}return document.createTextNode("")}createContext(e){const t={currentValue:e,defaultValue:e,subscribers:new Map,version:0,Provider:({value:e,children:n})=>{const o=this.getCurrentInstance(),r=o.currentHook++,s=o.hooks[r];return this.shallowEqual(s,e)||(t._currentValue=e,t._version++,t.subscribers.forEach((t=>{t.instance.hooks[t.hookIndex]=e,this.dirtyInstances=this.dirtyInstances||new Set,this.dirtyInstances.add(t.instance),this.scheduleUpdate()}))),o.hooks[r]=e,n},Consumer:({children:e})=>{if("function"!=typeof e)throw new Error("Context.Consumer expects a function as a child");return e(t._currentValue)}};return t}memo(e){const t=t=>{const n=this.getCurrentInstance();if(!n)return e(t);const o=n.currentHook++,r=n.hooks[o]||{props:null,result:null},s=!r.props||!this.deepEqual(t,r.props);if(!r.result||s){const r=e(t);return n.hooks[o]={props:t,result:r},r}return r.result};return t.__isMemoized=!0,t.__original=e,t}shallowEqual(e,t){if(e===t)return!0;if(!e||!t)return!1;if("object"!=typeof e||"object"!=typeof t)return e===t;const n=Object.keys(e),o=Object.keys(t);return n.length===o.length&&n.every((n=>t.hasOwnProperty(n)&&e[n]===t[n]))}deepEqual(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if("object"!=typeof e||null===e||null===t)return!1;const n=Object.keys(e),o=Object.keys(t);return n.length===o.length&&n.every((n=>this.deepEqual(e[n],t[n])))}areArraysEqual(e,t){return e===t||!(!e||!t)&&(e.length===t.length&&e.every(((e,n)=>e===t[n])))}areNodesEqual(e,t){return e===t||!(!e||!t)&&(typeof e==typeof t&&("string"==typeof e||"number"==typeof e?e===t:e.type===t.type&&this.areObjectsEqual(e.props,t.props)))}areObjectsEqual(e,t){if(e===t)return!0;if(!e||!t)return!1;const n=Object.keys(e),o=Object.keys(t);return n.length===o.length&&n.every((n=>"children"===n?this.areChildrenEqual(e[n],t[n]):e[n]===t[n]))}areChildrenEqual(e,t){if(e===t)return!0;if(!e||!t)return!1;const n=Array.isArray(e)?e:[e],o=Array.isArray(t)?t:[t];return n.length===o.length&&n.every(((e,t)=>this.areNodesEqual(e,o[t])))}getCurrentInstance(){const e=this.componentStack[this.componentStack.length-1];if(!e)throw new Error("Hooks can only be called inside function components");return e}}const Olova=new ReactLite;export const h=Olova.createElement.bind(Olova);export const Fragment=Symbol("Fragment");export const $state=Olova.$state.bind(Olova);export const $effect=Olova.$effect.bind(Olova);export const $ref=Olova.$ref.bind(Olova);export const $memo=Olova.$memo.bind(Olova);export const $callback=Olova.$callback.bind(Olova);export const $context=Olova.$context.bind(Olova);export const createContext=Olova.createContext.bind(Olova);export const memo=Olova.memo.bind(Olova);export default Olova;function isFunctionComponent(e){return"function"==typeof e}function renderComponent(e,t){try{return"function"==typeof e.type?e.type(e.props):"string"==typeof e?e:Array.isArray(e)?e.map((e=>renderComponent(e,t))):null==e?"":"object"==typeof e?e:String(e)}catch(e){return console.error("Error rendering component:",e),null}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "olova",
3
- "version": "2.0.8",
3
+ "version": "2.0.10",
4
4
  "description": "A lightweight JavaScript framework for building reactive applications.",
5
5
  "main": "dist/olova.js",
6
6
  "keywords": [