Skip to content

Commit 84e9d49

Browse files
committed
2 parents bf94c7d + 44e2778 commit 84e9d49

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

src/gp2/elements.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ var elements = {
175175
},
176176
disposeGPId: function (id) {
177177
__GP_elements[id] = undefined;
178+
delete __GP_elements[id];
178179
},
179180
getGPId: function (id) {
180181
if (__GP_elements[id]) {

src/gp2/elements_docs.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# 🛠 GP2 Elements Engine Documentation
2+
**Location:** `./src/gp2/elements.js`
3+
4+
This is the custom rendering engine for Random Rants +. It allows us to build the UI using lightweight JS objects (JSON) instead of heavy frameworks like React.
5+
6+
---
7+
8+
## 🚀 Basic Usage
9+
To create an element, pass an array of objects to elements.createElementsFromJSON().
10+
```javascript
11+
const elements = require('./gp2/elements.js');
12+
13+
const myUI = elements.createElementsFromJSON([
14+
{
15+
element: "div",
16+
className: "rant-container",
17+
style: {
18+
padding: "10px",
19+
backgroundColor: "#222"
20+
},
21+
children: [
22+
{
23+
element: "h1",
24+
textContent: "Hello Rant World!",
25+
style: { color: "cyan" }
26+
}
27+
]
28+
}
29+
]);
30+
31+
document.body.append(...myUI);
32+
```
33+
34+
---
35+
36+
## 🔑 Special Properties
37+
38+
- element: The HTML tag name (e.g., "div", "button", "input").
39+
- gid: Global ID. Stores the element in __GP_elements. Access it later via elements.getGPId("id").
40+
- children: An array of more element objects to nest inside this one.
41+
- style: An object of CSS properties (e.g., { color: "red" }).
42+
- styleProperties: Uses style.setProperty. Good for CSS variables like --user-color.
43+
- eventListeners: An array of objects: [{ event: "click", func: myFunc }].
44+
- GPWhenCreated: A function that runs as soon as the element is made. "this" refers to the element.
45+
- dangerouslySetInnerHTML: Used to inject raw HTML. (Replaces the deprecated innerHTML).
46+
47+
---
48+
49+
## 🛠 Advanced Example: Interactive Component
50+
Use GPWhenCreated and eventListeners to make things interactive.
51+
52+
```javascript
53+
const chatInput = elements.createElementsFromJSON([
54+
{
55+
element: "input",
56+
gid: "main-input",
57+
placeholder: "Type a rant...",
58+
eventListeners: [
59+
{
60+
event: "keydown",
61+
func: (e) => { if(e.key === "Enter") console.log("Sent!"); }
62+
}
63+
],
64+
GPWhenCreated: function(elm) {
65+
console.log("Input is ready!");
66+
elm.focus();
67+
}
68+
}
69+
]);
70+
```
71+
72+
---
73+
74+
## ⚠️ Guidelines for Contributors
75+
1. No React: Use this engine. It's lighter for school Chromebooks.
76+
2. Render Free Tier: Keep the code light. Don't cause memory leaks.
77+
3. Cleaning Up: If you use a gid, use elements.disposeGPId("id") if the element is removed.

0 commit comments

Comments
 (0)