lume-js 0.0.0 → 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Sathvik C
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # lume-js
2
+
3
+ Minimal reactive state + DOM binding with **zero runtime** overhead.
4
+ Inspired by Go-style simplicity.
5
+
6
+ ## Philosophy
7
+ - ⚡ Zero runtime, direct DOM updates (no VDOM, no diffing).
8
+ - 🔑 Simple `state()` and `bindDom()` — that's it.
9
+ - 🧩 Explicit nesting (`state({ user: state({ name: "Alice" }) })`).
10
+ - ✨ Works anywhere — plain JS, or alongside other frameworks.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm install lume-js
16
+ ```
17
+
18
+ ## Example
19
+
20
+ **main.js**
21
+ ```js
22
+ import { state, bindDom } from "lume-js";
23
+
24
+ const store = state({
25
+ count: 0,
26
+ user: state({ name: "Alice" })
27
+ });
28
+
29
+ bindDom(document.body, store);
30
+
31
+ document.getElementById("inc").addEventListener("click", () => {
32
+ store.count++;
33
+ });
34
+
35
+ document.getElementById("changeName").addEventListener("click", () => {
36
+ store.user.name = store.user.name === "Alice" ? "Bob" : "Alice";
37
+ });
38
+ ```
39
+
40
+ **index.html**
41
+ ```html
42
+ <p>Count: <span data-bind="count"></span></p>
43
+ <p>User Name: <span data-bind="user.name"></span></p>
44
+
45
+ <button id="inc">Increment</button>
46
+ <button id="changeName">Change Name</button>
47
+ ```
48
+
49
+ ## Status
50
+
51
+ 🚧 Early alpha (`0.1.0`). API may change. Feedback welcome!
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "lume-js",
3
- "version": "0.0.0",
4
- "description": "",
5
- "main": "index.js",
3
+ "version": "0.1.1",
4
+ "main": "src/index.js",
5
+ "type": "module",
6
6
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
7
+ "dev": "vite examples",
8
+ "build": "echo 'No build step yet, zero-runtime already!'"
8
9
  },
9
- "keywords": [],
10
- "author": "",
11
- "license": "ISC"
10
+ "files": [
11
+ "src"
12
+ ],
13
+ "devDependencies": {
14
+ "vite": "^7.1.9"
15
+ }
12
16
  }
@@ -0,0 +1,52 @@
1
+ export function state(obj) {
2
+ const listeners = {};
3
+
4
+ function notify(key, val) {
5
+ if (listeners[key]) listeners[key].forEach(fn => fn(val));
6
+ }
7
+
8
+ const proxy = new Proxy(obj, {
9
+ get(target, key) {
10
+ return target[key];
11
+ },
12
+ set(target, key, value) {
13
+ target[key] = value;
14
+ notify(key, value);
15
+ return true;
16
+ }
17
+ });
18
+
19
+ proxy.$subscribe = (key, fn) => {
20
+ if (!listeners[key]) listeners[key] = [];
21
+ listeners[key].push(fn);
22
+ // initialize
23
+ fn(proxy[key]);
24
+ };
25
+
26
+ return proxy;
27
+ }
28
+
29
+ // Zero-runtime data-bind init
30
+ export function bindDom(root, store) {
31
+ const nodes = root.querySelectorAll("[data-bind]");
32
+ nodes.forEach(el => {
33
+ const path = el.getAttribute("data-bind").split(".");
34
+ const lastKey = path.pop();
35
+
36
+ let target = store;
37
+ for (const key of path) {
38
+ target = target[key]; // must be wrapped with state()
39
+ }
40
+
41
+ // subscribe once
42
+ target.$subscribe(lastKey, val => {
43
+ if (el.tagName === "INPUT" || el.tagName === "TEXTAREA") el.value = val;
44
+ else el.textContent = val;
45
+ });
46
+
47
+ // 2-way binding for inputs
48
+ if (el.tagName === "INPUT" || el.tagName === "TEXTAREA") {
49
+ el.addEventListener("input", e => target[lastKey] = e.target.value);
50
+ }
51
+ });
52
+ }
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './core/state.js';
package/index.js DELETED
@@ -1 +0,0 @@
1
- console.log("hello world!");