@arundeep_bhardwaj/r-lite 1.0.5 → 1.0.7

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.
Files changed (4) hide show
  1. package/index.js +80 -3
  2. package/package.json +8 -2
  3. package/core.js +0 -45
  4. package/hooks.js +0 -51
package/index.js CHANGED
@@ -1,3 +1,80 @@
1
- // index.js (library entry)
2
- export { h, render } from "./core.js";
3
- export { useState, useEffect } from "./hooks.js";
1
+ import { h, render } from "@arundeep_bhardwaj/r-lite/core.js";
2
+ import { useState, useEffect } from "@arundeep_bhardwaj/r-lite/hooks.js";
3
+
4
+ function App() {
5
+ const [count, setCount] = useState(0);
6
+ const [users, setUsers] = useState([]);
7
+
8
+ // API CALL
9
+ useEffect(() => {
10
+ fetch("https://jsonplaceholder.typicode.com/users")
11
+ .then(res => res.json())
12
+ .then(data => {
13
+ setUsers(data);
14
+ });
15
+ }, []);
16
+
17
+ return h(
18
+ "div",
19
+ { className: "app-container" },
20
+
21
+
22
+ h(
23
+ "header",
24
+ { className: "header" },
25
+ h("h1", null, "r_lite"),
26
+ h(
27
+ "p",
28
+ { className: "tagline" },
29
+ "A fast, lightweight UI library designed for micro-frontend architectures"
30
+ ),
31
+ h(
32
+ "div",
33
+ { className: "badges" },
34
+ h("span", null, "⚡ Fast"),
35
+ h("span", null, "📦 Lightweight"),
36
+ h("span", null, "🧩 Micro-Frontend Ready"),
37
+ h("span", null, "🧠 Hooks Based")
38
+ )
39
+ ),
40
+
41
+
42
+ h(
43
+ "section",
44
+ { className: "card" },
45
+ h("h2", null, "Counter Demo"),
46
+ h("p", null, `Current Count: ${count}`),
47
+ h(
48
+ "button",
49
+ { onclick: () => setCount(c => c + 1) },
50
+ "Increment"
51
+ )
52
+ ),
53
+
54
+
55
+ h(
56
+ "section",
57
+ { className: "users-section" },
58
+ h("h2", null, "Users (API Data)"),
59
+
60
+ h(
61
+ "div",
62
+ { className: "grid" },
63
+
64
+ ...users.map(user =>
65
+ h(
66
+ "div",
67
+ { className: "user-card", key: user.id },
68
+
69
+ h("h3", null, user.name),
70
+ h("p", null, `📧 ${user.email}`),
71
+ h("p", null, `🏙 ${user.address.city}`),
72
+ h("p", null, `📞 ${user.phone}`)
73
+ )
74
+ )
75
+ )
76
+ ),
77
+ );
78
+ }
79
+
80
+ render(App, document.getElementById("root"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arundeep_bhardwaj/r-lite",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "A lightweight React-like UI library for micro-frontend architectures",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -17,6 +17,12 @@
17
17
  "framework",
18
18
  "lightweight"
19
19
  ],
20
+ "scripts": {
21
+ "dev": "vite"
22
+ },
20
23
  "author": "Arundeep Bhardwaj",
21
- "license": "MIT"
24
+ "license": "MIT",
25
+ "devDependencies": {
26
+ "vite": "^7.3.1"
27
+ }
22
28
  }
package/core.js DELETED
@@ -1,45 +0,0 @@
1
- import { resetHooks, runEffects } from "./hooks.js";
2
-
3
- let RootComponent = null;
4
- let RootElement = null;
5
-
6
- export function h(type, props = {}, ...children) {
7
- return { type, props, children };
8
- }
9
-
10
- function createDom(vnode) {
11
- if (typeof vnode === "string" || typeof vnode === "number") {
12
- return document.createTextNode(vnode);
13
- }
14
-
15
- if (typeof vnode.type === "function") {
16
- return createDom(vnode.type(vnode.props));
17
- }
18
-
19
- const el = document.createElement(vnode.type);
20
-
21
- Object.entries(vnode.props || {}).forEach(([key, value]) => {
22
- el[key] = value;
23
- });
24
-
25
- vnode.children.forEach(child => {
26
- el.appendChild(createDom(child));
27
- });
28
-
29
- return el;
30
- }
31
-
32
- export function render(App, container) {
33
- RootComponent = App;
34
- RootElement = container;
35
-
36
- resetHooks();
37
- container.innerHTML = "";
38
- container.appendChild(createDom(App()));
39
-
40
- runEffects();
41
- }
42
-
43
- export function rerender() {
44
- render(RootComponent, RootElement);
45
- }
package/hooks.js DELETED
@@ -1,51 +0,0 @@
1
- import { rerender } from "./core.js";
2
-
3
- let hooks = [];
4
- let effects = [];
5
- let index = 0;
6
-
7
- export function resetHooks() {
8
- index = 0;
9
- }
10
-
11
- export function useState(initialValue) {
12
- const i = index;
13
-
14
- hooks[i] = hooks[i] ?? initialValue;
15
-
16
- const setState = value => {
17
- hooks[i] =
18
- typeof value === "function" ? value(hooks[i]) : value;
19
-
20
- rerender();
21
- };
22
-
23
- index++;
24
- return [hooks[i], setState];
25
- }
26
-
27
- export function useEffect(callback, deps) {
28
- const i = index;
29
- const oldDeps = hooks[i];
30
-
31
- let hasChanged = true;
32
-
33
- if (oldDeps) {
34
- hasChanged = deps
35
- ? !deps.every((dep, j) => dep === oldDeps[j])
36
- : true;
37
- }
38
-
39
- if (hasChanged) {
40
- effects.push(() => callback());
41
- hooks[i] = deps;
42
- }
43
-
44
- index++;
45
- }
46
-
47
-
48
- export function runEffects() {
49
- effects.forEach(effect => effect());
50
- effects = [];
51
- }