olova 2.0.9 → 2.0.11
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 +54 -54
- package/dist/hooks/createEffect.js +14 -0
- package/dist/hooks/createMemo.js +21 -0
- package/dist/hooks/createRef.js +13 -0
- package/dist/hooks/createSignal.js +13 -0
- package/dist/olova.d.ts +1 -1
- package/dist/olova.js +1 -1
- package/package.json +15 -15
- package/dist/hooks/callback.js +0 -4
- package/dist/hooks/context.js +0 -21
- package/dist/hooks/effect.js +0 -11
- package/dist/hooks/memo.js +0 -15
- package/dist/hooks/reducer.js +0 -11
- package/dist/hooks/ref.js +0 -5
- package/dist/hooks/state.js +0 -19
- package/package-lock.json +0 -1433
|
@@ -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,54 @@
|
|
|
1
|
-
# Olova JavaScript Framework
|
|
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
|
+
# Olova JavaScript Framework
|
|
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
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { currentEffect, setCurrentEffect } from "./createSignal";
|
|
2
|
+
function createEffect(t) {
|
|
3
|
+
const e = () => {
|
|
4
|
+
f(), setCurrentEffect(e);
|
|
5
|
+
try {
|
|
6
|
+
f = t() || (() => {});
|
|
7
|
+
} finally {
|
|
8
|
+
setCurrentEffect(null);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
let f = () => {};
|
|
12
|
+
e();
|
|
13
|
+
}
|
|
14
|
+
export { createEffect };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { $state, $effect } from "../olova.js";
|
|
2
|
+
function createMemo(t, e = []) {
|
|
3
|
+
const [o, s] = $state(void 0),
|
|
4
|
+
[c, a] = $state(e),
|
|
5
|
+
[i, r] = $state(void 0);
|
|
6
|
+
return (
|
|
7
|
+
$effect(() => {
|
|
8
|
+
if (
|
|
9
|
+
void 0 === i ||
|
|
10
|
+
((f = c),
|
|
11
|
+
(o = e).length !== f.length || o.some((t, e) => !Object.is(t, f[e])))
|
|
12
|
+
) {
|
|
13
|
+
const o = t();
|
|
14
|
+
Object.is(o, i) || (r(o), s(o)), a(e);
|
|
15
|
+
}
|
|
16
|
+
var o, f;
|
|
17
|
+
}),
|
|
18
|
+
o
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
export { createMemo };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createSignal } from "./createSignal";
|
|
2
|
+
function createRef(e = null) {
|
|
3
|
+
const [r, t] = createSignal({ current: e });
|
|
4
|
+
return {
|
|
5
|
+
get current() {
|
|
6
|
+
return r().current;
|
|
7
|
+
},
|
|
8
|
+
set current(e) {
|
|
9
|
+
t({ current: e });
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export { createRef };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
let currentEffect = null;
|
|
2
|
+
const setCurrentEffect = (t) => {
|
|
3
|
+
currentEffect = t;
|
|
4
|
+
};
|
|
5
|
+
function createSignal(t) {
|
|
6
|
+
let e = t;
|
|
7
|
+
const r = new Set();
|
|
8
|
+
return [
|
|
9
|
+
() => (currentEffect && r.add(currentEffect), e),
|
|
10
|
+
(t) => ((e = "function" == typeof t ? t(e) : t), r.forEach((t) => t()), e),
|
|
11
|
+
];
|
|
12
|
+
}
|
|
13
|
+
export { createSignal, currentEffect, setCurrentEffect };
|
package/dist/olova.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
declare module "olova";
|
|
1
|
+
declare module "olova";
|
package/dist/olova.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import{createSignal as $state}from"./hooks/createSignal";import{createEffect as $effect}from"./hooks/createEffect";import{createMemo as $memo}from"./hooks/createMemo";import{createRef as $ref}from"./hooks/createRef";function h(e,t={},...n){if(e===h.Fragment){const e=document.createDocumentFragment(),t=n.flat();for(let n=0;n<t.length;n++){const o=t[n];if("function"==typeof o){const t=document.createTextNode("");$effect((()=>{const n=o();if(Array.isArray(n)){const o=t.previousSibling;o&&o.remove();const r=document.createDocumentFragment();for(let e=0;e<n.length;e++){const t=n[e];r.appendChild(t instanceof Node?t:document.createTextNode(String(t)))}e.insertBefore(r,t)}else t.textContent=String(n)})),e.appendChild(t)}else o instanceof Node?e.appendChild(o):null!=o&&e.appendChild(document.createTextNode(String(o)))}return e}const o="function"==typeof e?e(t):document.createElement(e);if("function"!=typeof e){if(t){const e=Object.entries(t);for(let t=0;t<e.length;t++){const[n,r]=e[t];"ref"===n?queueMicrotask((()=>{r&&"object"==typeof r&&(r.current=o)})):n.startsWith("on")?o.addEventListener(n.slice(2).toLowerCase(),r):"style"===n&&"object"==typeof r?Object.assign(o.style,r):"className"===n?o.className=r:o.setAttribute(n,r)}}const e=document.createTextNode(""),r=n.flat();for(let t=0;t<r.length;t++){const n=r[t];if("function"==typeof n)$effect((()=>{const t=n();if(Array.isArray(t)){o.textContent="";const e=document.createDocumentFragment();for(let n=0;n<t.length;n++){const o=t[n];e.appendChild(o instanceof Node?o:document.createTextNode(String(o)))}o.appendChild(e)}else e.textContent=String(t),e.parentNode||o.appendChild(e)}));else if(Array.isArray(n)){const e=document.createDocumentFragment();for(let t=0;t<n.length;t++){const o=n[t];o instanceof Node?e.appendChild(o):null!=o&&e.appendChild(document.createTextNode(String(o)))}o.appendChild(e)}else n instanceof Node?o.appendChild(n):null!=n&&o.appendChild(document.createTextNode(String(n)))}}return o}h.Fragment=Symbol("Fragment");const Fragment=h.Fragment;export{h,$state,$effect,$memo,Fragment,$ref};
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "olova",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "A lightweight JavaScript framework for building reactive applications.",
|
|
5
|
-
"main": "dist/olova.js",
|
|
6
|
-
"keywords": [
|
|
7
|
-
"javascript",
|
|
8
|
-
"framework",
|
|
9
|
-
"reactive",
|
|
10
|
-
"olova",
|
|
11
|
-
"olovajs"
|
|
12
|
-
],
|
|
13
|
-
"author": "Nazmul Hossain",
|
|
14
|
-
"license": "MIT"
|
|
15
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "olova",
|
|
3
|
+
"version": "2.0.11",
|
|
4
|
+
"description": "A lightweight JavaScript framework for building reactive applications.",
|
|
5
|
+
"main": "dist/olova.js",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"javascript",
|
|
8
|
+
"framework",
|
|
9
|
+
"reactive",
|
|
10
|
+
"olova",
|
|
11
|
+
"olovajs"
|
|
12
|
+
],
|
|
13
|
+
"author": "Nazmul Hossain",
|
|
14
|
+
"license": "MIT"
|
|
15
|
+
}
|
package/dist/hooks/callback.js
DELETED
package/dist/hooks/context.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
);
|
|
21
|
-
}
|
package/dist/hooks/effect.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
});
|
|
11
|
-
}
|
package/dist/hooks/memo.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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;
|
|
15
|
-
}
|
package/dist/hooks/reducer.js
DELETED
package/dist/hooks/ref.js
DELETED
package/dist/hooks/state.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
);
|
|
19
|
-
}
|