olova 2.0.11 → 2.0.12
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/.github/workflows/publish.yml +18 -18
- package/README.md +1 -54
- package/dist/olova.d.ts +1 -1
- package/dist/olova.js +1 -1
- package/package-lock.json +1433 -0
- package/package.json +15 -15
- package/dist/hooks/createEffect.js +0 -14
- package/dist/hooks/createMemo.js +0 -21
- package/dist/hooks/createRef.js +0 -13
- package/dist/hooks/createSignal.js +0 -13
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
name: Publish to NPM
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: [ main ]
|
|
6
|
-
|
|
7
|
-
jobs:
|
|
8
|
-
publish:
|
|
9
|
-
runs-on: ubuntu-latest
|
|
10
|
-
steps:
|
|
11
|
-
- uses: actions/checkout@v2
|
|
12
|
-
- uses: actions/setup-node@v2
|
|
13
|
-
with:
|
|
14
|
-
node-version: '14'
|
|
15
|
-
registry-url: 'https://registry.npmjs.org'
|
|
16
|
-
- run: yarn publish
|
|
17
|
-
env:
|
|
18
|
-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
|
1
|
+
name: Publish to NPM
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v2
|
|
12
|
+
- uses: actions/setup-node@v2
|
|
13
|
+
with:
|
|
14
|
+
node-version: '14'
|
|
15
|
+
registry-url: 'https://registry.npmjs.org'
|
|
16
|
+
- run: yarn publish
|
|
17
|
+
env:
|
|
18
|
+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
package/README.md
CHANGED
|
@@ -1,54 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Olova is a lightweight and reactive JavaScript framework that simplifies UI
|
|
4
|
-
development with a clean, intuitive syntax. It provides a reactivity system and
|
|
5
|
-
hooks to manage state and side effects, allowing developers to build modern web
|
|
6
|
-
applications with ease.
|
|
7
|
-
|
|
8
|
-
## Features
|
|
9
|
-
|
|
10
|
-
- **State Management**: Use the `State` hook to manage reactive state in your
|
|
11
|
-
components.
|
|
12
|
-
- **Side Effects**: Use the `Effect` hook to run side effects in response to
|
|
13
|
-
state changes.
|
|
14
|
-
- **JSX-style Syntax**: Write UI components using a simple, declarative
|
|
15
|
-
JSX-style syntax.
|
|
16
|
-
- **Reactivity**: Automatically re-render components when state changes.
|
|
17
|
-
|
|
18
|
-
## Installation
|
|
19
|
-
|
|
20
|
-
To get started with Olova, first install the core library via npm or yarn.
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
npm install olova
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
or
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
yarn add olova
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Example Usage
|
|
33
|
-
|
|
34
|
-
Here is an example of a basic component in Olova:
|
|
35
|
-
|
|
36
|
-
```js
|
|
37
|
-
import Olova, { State, Effect } from "olova";
|
|
38
|
-
|
|
39
|
-
export default function Home() {
|
|
40
|
-
const [count, setCount] = State(0);
|
|
41
|
-
|
|
42
|
-
Effect(() => {
|
|
43
|
-
console.log("Home is rendered");
|
|
44
|
-
console.log(count);
|
|
45
|
-
}, [count]);
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
<>
|
|
49
|
-
<h1>{count}</h1>
|
|
50
|
-
<button onClick={() => setCount(count + 1)}>Increment</button>
|
|
51
|
-
</>
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
```
|
|
1
|
+
|
package/dist/olova.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
declare module "olova";
|
|
1
|
+
declare module "olova";
|
package/dist/olova.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const e=Symbol("BATCH_UPDATES"),t=Symbol("SIGNAL_TYPE");class n{constructor(){this.globalSubs=new Set,this.propSubs=new Map,this.weakPropSubs=new WeakMap,this.dependencies=new WeakMap,this.batchMode=!1,this.pendingDeps=new Set}subscribe(e,t){if(!t)return;this.dependencies.has(t)||this.dependencies.set(t,new Set);const n=this.dependencies.get(t);if(!n.has(e)){if(n.add(e),!e)return void this.globalSubs.add(t);const s="object"==typeof e?this.weakPropSubs:this.propSubs;s.has(e)||s.set(e,new Set),s.get(e).add(t)}}notify(e,t=new Set){if(this.batchMode)return this.pendingDeps.add(e),t;if(e){const n=this.propSubs.get(e);if(n&&this.notifyDependentSubs(n,e,t),"object"==typeof e){const n=this.weakPropSubs.get(e);n&&this.notifyDependentSubs(n,e,t)}}return this.notifyDependentSubs(this.globalSubs,e,t),t}startBatch(){this.batchMode=!0,this.pendingDeps.clear()}endBatch(){this.batchMode=!1;const e=new Set;for(const t of this.pendingDeps)this.notify(t,e);return this.pendingDeps.clear(),e}notifyDependentSubs(e,t,n){for(const s of e)if(!n.has(s)){const e=this.dependencies.get(s);t&&e&&!e.has(t)||(s(),n.add(s))}}cleanup(e){if(e){this.propSubs.delete(e);for(const[t,n]of this.dependencies)n.delete(e),0===n.size&&this.dependencies.delete(t)}}}class s{constructor(){this.updates=new Map,this.priorities=new Map,this.timeouts=new Map,this.debounceTime=16}add(e,t,n=0,s=!1){if(s)return this.timeouts.has(e)&&clearTimeout(this.timeouts.get(e)),void this.timeouts.set(e,setTimeout((()=>{this.addImmediate(e,t,n),this.timeouts.delete(e)}),this.debounceTime));this.addImmediate(e,t,n)}addImmediate(e,t,n){if(this.updates.has(e)){const s=this.updates.get(e),i=this.priorities.get(e)||0;"object"==typeof s&&"object"==typeof t&&(t={...s,...t}),n=Math.max(i,n)}this.updates.set(e,t),this.priorities.set(e,n)}process(e){0!==this.updates.size&&(this.timeouts.size>0?Promise.all(Array.from(this.timeouts.values()).map((e=>new Promise((t=>{const n=setInterval((()=>{this.timeouts.has(e)||(clearInterval(n),t())}),0)}))))).then((()=>this.processImmediate(e))):this.processImmediate(e))}processImmediate(e){const t=[...this.updates.entries()].sort(((e,t)=>(this.priorities.get(t[0])||0)-(this.priorities.get(e[0])||0)));e.startBatch();const n=new Set;for(const[s,i]of t)"function"==typeof i&&i(),e.notify(s,n);e.endBatch(),this.updates.clear(),this.priorities.clear()}clear(){this.timeouts.forEach((e=>clearTimeout(e))),this.timeouts.clear(),this.updates.clear(),this.priorities.clear()}}const i=(i,o={})=>{const{equals:r=Object.is,immediate:a=!0,batched:c=!1,debounce:l=!1}=o;let d=i;const u=new n,f=new s,p=e=>{const t=h();return t&&u.subscribe(e,t),e?d[e]:d};return p[e]=()=>(u.startBatch(),()=>{u.endBatch(),f.clear()}),p[t]=!0,[p,(e,t,n=0)=>{const s="function"==typeof e?e(t?d[t]:d):e;(t?!r(d[t],s):!r(d,s))&&(d=t?{...d,[t]:s}:s,c?(f.add(t,s,n,l),queueMicrotask((()=>{f.process(u)}))):u.notify(t))}]};function o(e,t={defer:!1}){let n=null,s=new Set;const i=()=>{n&&n(),s.clear(),f=i;try{n=e()||null}finally{f=null}};return t.defer||i(),i}function r(e,t={}){const[n,s]=i(void 0,t);let r=!1,a=new Set;return o((()=>{a.clear();const i=e();r&&t.equals&&t.equals(n(),i)||(s(i),r=!0)})),n}function a(e,t={}){const{initialValue:n=null,cacheTime:s=5e3,retries:o=3,retryDelay:r=1e3,lazy:a=!1}=t,[c,l]=i(n),[d,u]=i(!1),[f,h]=i(null);let p=new Map,m=new Map,y=0;const b=e=>{e?(p.delete(e),m.has(e)&&(clearTimeout(m.get(e)),m.delete(e))):(p.clear(),m.forEach((e=>clearTimeout(e))),m.clear())},g=async t=>{const n=JSON.stringify(t);if(p.has(n))return p.get(n);u(!0),h(null),y=0;const i=async()=>{try{const i=await e(t);return l(i),p.set(n,i),s>0&&m.set(n,setTimeout((()=>b(n)),s)),i}catch(e){if(y<o)return y++,await new Promise((e=>setTimeout(e,r*y))),i();throw h(e),e}finally{u(!1)}};return i()};return a||g(),{data:c,loading:d,error:f,refetch:g,clearCache:b}}function c(e,n,...s){if("function"==typeof e)return e({...n,children:s});if(e===l)return s.flat().filter(Boolean);const i=document.createElement(e);if(n)for(const[e,s]of Object.entries(n))if("ref"===e)"function"==typeof s?s(i):s&&(s.current=i);else if(e.startsWith("on")){const t=e.toLowerCase().slice(2);i.addEventListener(t,s)}else if("style"===e)"string"==typeof s?i.style.cssText=s:Object.assign(i.style,s);else if("classList"===e){if(Array.isArray(s))i.classList.add(...s.filter(Boolean));else if("object"==typeof s)for(const[e,t]of Object.entries(s))t?i.classList.add(e):i.classList.remove(e)}else"class"===e||"className"===e?i.className=s:["key"].includes(e)||("function"==typeof s&&s[t]?o((()=>{i[e]=s()})):i[e]=s);return s.flat().forEach((e=>{const t=g(e);t&&i.appendChild(t)})),i}new Map;const l=Symbol("Fragment");function d(t,n,s={}){const{hydrate:o=!1,onError:r=console.error,suspense:a=!0,beforeMount:c,afterMount:l}=s;if(!o)for(;n.firstChild;)n.removeChild(n.firstChild);const[d]=i(null),f=d[e]();c?.();try{let e=t();if(a&&e instanceof Promise)return void e.then((e=>{u(e,n,o),l?.()})).catch(r);u(e,n,o),l?.()}catch(e){r(e)}finally{f()}return()=>{for(;n.firstChild;)n.removeChild(n.firstChild)}}function u(e,t,n){if(!e)return;const s=Array.isArray(e)?e.flat(1/0):[e],i=Array.from(t.childNodes);let o=0;if(s.filter(Boolean).forEach((e=>{"string"==typeof e||"number"==typeof e?n&&i[o]?.nodeType===Node.TEXT_NODE?i[o].textContent=e+"":t.appendChild(document.createTextNode(e+"")):e instanceof Node?n&&i[o]?e.isEqualNode(i[o])||t.replaceChild(e,i[o]):t.appendChild(e):Array.isArray(e)?u(e,t,n):e&&"object"==typeof e&&t.appendChild(document.createTextNode(JSON.stringify(e))),o++})),!n)for(;o<i.length;)t.removeChild(i[o]),o++}let f=null;const h=()=>f;function p(e){const t=Symbol("context");return new Map,{Provider:({value:e,children:n})=>{const s=m(t);return f=e,f=s,n},Context:t,defaultValue:e}}function m(e){return f||e.defaultValue}function y({fallback:e,children:t}){try{return t}catch(t){return e(t)}}function b(e){let t=null,n=null;return function(s){if(!t)throw n||(n=e().then((e=>{t=e.default||e}))),n;return c(t,s)}}export{i as createSignal,o as createEffect,r as createMemo,a as createResource,p as createContext,m as useContext,c as h,l as Fragment,d as render,y as ErrorBoundary,b as lazy};const g=e=>{if(null==e||!1===e)return null;const n=()=>{const e=Math.random().toString(36).slice(2,8),t=document.createComment("start:"+e),n=document.createComment("end:"+e),s=document.createDocumentFragment();return s.appendChild(t),s.appendChild(n),{fragment:s,startNode:t,endNode:n}};if("function"==typeof e){const{fragment:s,startNode:i,endNode:r}=n();let a=null,c=null;return o((()=>{let n=(e[t],e());if(n===c)return;if(a){if(a.nodeType===Node.TEXT_NODE&&("string"==typeof n||"number"==typeof n)){const e=n+"";return a.textContent!==e&&(a.textContent=e),void(c=n)}if(a instanceof Element&&n instanceof Element&&a.tagName===n.tagName){const e=a.attributes,t=n.attributes;for(const t of e)n.hasAttribute(t.name)||a.removeAttribute(t.name);for(const e of t)a.getAttribute(e.name)!==e.value&&a.setAttribute(e.name,e.value);if(a.childNodes.length===n.childNodes.length){let e=!1;for(let t=0;t<a.childNodes.length;t++){const s=a.childNodes[t],i=n.childNodes[t];if(s.nodeType!==Node.TEXT_NODE||i.nodeType!==Node.TEXT_NODE){e=!0;break}s.textContent!==i.textContent&&(s.textContent=i.textContent)}if(!e)return void(c=n)}}}const s=r.parentNode,o=document.createDocumentFragment();if(null!=n){const e=S(n);e&&o.appendChild(e)}if(i.nextSibling!==r){let e=i.nextSibling;const t=[];for(;e&&e!==r;)t.push(e),e=e.nextSibling;t.forEach((e=>e.remove()))}o.firstChild?(s.insertBefore(o,r),a=i.nextSibling):a=null,c=n})),s}if(Array.isArray(e)){const{fragment:t,startNode:s,endNode:i}=n();let r=[],a=new Map;return o((()=>{const t=e.filter(Boolean);if(0===t.length){if(0===r.length)return;let e=s.nextSibling;const t=[];for(;e&&e!==i;)t.push(e),e=e.nextSibling;return t.forEach((e=>e.remove())),r=[],void a.clear()}if(r.length===t.length&&r.length<5){let e=!1;const n=[];let o=s.nextSibling;for(;o&&o!==i;)n.push(o),o=o.nextSibling;for(let s=0;s<t.length;s++){const i=r[s],o=t[s],a=n[s];if(i!==o){if(a.nodeType!==Node.TEXT_NODE||"string"!=typeof o&&"number"!=typeof o){e=!0;break}a.textContent=o+""}}if(!e)return void(r=[...t])}const n=document.createDocumentFragment(),o=new Map;t.forEach(((e,t)=>{const s=e?.key||`${typeof e}:${e+""}`;let i;a.has(s)?(i=a.get(s),a.delete(s)):i=g(e),i&&(o.set(s,i),n.appendChild(i))})),a.clear(),a=o;let c=s.nextSibling;const l=[];for(;c&&c!==i;)l.push(c),c=c.nextSibling;l.forEach((e=>e.remove())),i.parentNode.insertBefore(n,i),r=[...t]})),t}return e instanceof Node?e:document.createTextNode(e+"")},S=e=>{if(Array.isArray(e)){const t=document.createDocumentFragment();return e.forEach((e=>{const n=g(e);n&&t.appendChild(n)})),t}return e instanceof Node?e:document.createTextNode(e+"")};
|