Skip to content

Commit 6f54b22

Browse files
committed
working on openscript docs
1 parent 653ece1 commit 6f54b22

34 files changed

Lines changed: 2166 additions & 1106 deletions

README.md

Lines changed: 1057 additions & 72 deletions
Large diffs are not rendered by default.

README.npm.md

Lines changed: 61 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# OpenScriptJs
22

3-
[![npm version](https://badge.fury.io/js/openscriptjs.svg)](https://www.npmjs.com/package/openscriptjs)
3+
[![npm version](https://badge.fury.io/js/modular-openscriptjs.svg)](https://www.npmjs.com/package/modular-openscriptjs)
44
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
55

66
A lightweight, reactive JavaScript framework for building modern web applications with components, state management, routing, and event-driven architecture.
@@ -20,52 +20,45 @@ A lightweight, reactive JavaScript framework for building modern web application
2020

2121
### Installation
2222

23-
```bash
24-
npm install openscriptjs
25-
```
26-
27-
### Create a New Project
28-
29-
```bash
30-
npm create openscript my-app
31-
cd my-app
32-
npm run dev
33-
```
34-
35-
Choose from templates:
23+
````bash
3624
- `basic` - Clean starter with vanilla CSS
3725
- `tailwind` - Pre-configured with TailwindCSS
3826

3927
## 📖 Basic Usage
4028

4129
```javascript
42-
import { Component, h, state } from 'openscriptjs';
30+
import { Component, app, state } from "modular-openscriptjs";
31+
32+
const h = app("h");
4333
4434
class Counter extends Component {
45-
constructor() {
46-
super();
47-
this.count = state(0);
48-
}
49-
50-
increment() {
51-
this.count.value++;
52-
}
53-
54-
render() {
55-
return h.div(
56-
h.h2("Count: ", this.count.value),
57-
h.button({
58-
listeners: { click: this.increment.bind(this) }
59-
}, "Increment")
60-
);
61-
}
35+
constructor() {
36+
super();
37+
this.count = state(0);
38+
}
39+
40+
increment() {
41+
this.count.value++;
42+
}
43+
44+
render() {
45+
return h.div(
46+
h.h2("Count: ", this.count.value),
47+
h.button(
48+
{
49+
listeners: { click: this.increment.bind(this) },
50+
},
51+
"Increment"
52+
)
53+
);
54+
}
6255
}
6356
6457
// Mount and render
6558
const counter = new Counter();
6659
await counter.mount();
6760
h.Counter({ parent: document.body });
68-
```
61+
````
6962
7063
## 🏗️ Project Structure
7164
@@ -85,23 +78,21 @@ my-app/
8578
### Components
8679
8780
```javascript
88-
import { Component, h } from 'openscriptjs';
81+
import { Component, app } from "modular-openscriptjs";
82+
83+
const h = app("h");
8984
9085
class MyComponent extends Component {
91-
render(...args) {
92-
return h.div(
93-
{ class: "container" },
94-
h.h1("Hello OpenScript!"),
95-
...args
96-
);
97-
}
86+
render(...args) {
87+
return h.div({ class: "container" }, h.h1("Hello OpenScript!"), ...args);
88+
}
9889
}
9990
```
10091
10192
### State Management
10293
10394
```javascript
104-
import { state } from 'openscriptjs';
95+
import { state } from "modular-openscriptjs";
10596
10697
// Create reactive state
10798
const count = state(0);
@@ -110,20 +101,23 @@ const count = state(0);
110101
count.value = 10;
111102
112103
// Listen to changes
113-
count.listener((s) => console.log('New value:', s.value));
104+
count.listener((s) => console.log("New value:", s.value));
114105
```
115106
116107
### Routing
117108
118109
```javascript
119-
import { router, h } from 'openscriptjs';
110+
import { app } from "modular-openscriptjs";
111+
112+
const router = app("router");
113+
const h = app("h");
120114
121-
router.on('/home', () => {
122-
h.HomePage({ parent: document.body, resetParent: true });
115+
router.on("/home", () => {
116+
h.HomePage({ parent: document.body, resetParent: true });
123117
});
124118
125-
router.on('/about', () => {
126-
h.AboutPage({ parent: document.body, resetParent: true });
119+
router.on("/about", () => {
120+
h.AboutPage({ parent: document.body, resetParent: true });
127121
});
128122
129123
router.listen();
@@ -132,7 +126,9 @@ router.listen();
132126
### Context & Global State
133127
134128
```javascript
135-
import { context, putContext } from 'openscriptjs';
129+
import { context, putContext, app } from "modular-openscriptjs";
130+
131+
const h = app("h");
136132
137133
// Register contexts
138134
putContext(["global", "user"], "AppContext");
@@ -141,8 +137,8 @@ const gc = context("global");
141137
142138
// Initialize states
143139
gc.states({
144-
appName: "My App",
145-
theme: "light"
140+
appName: "My App",
141+
theme: "light",
146142
});
147143
148144
// Pass to components
@@ -154,18 +150,22 @@ h.MyComponent(gc.appName, { parent: document.body });
154150
OpenScript works seamlessly with Tailwind:
155151
156152
```javascript
153+
import { app } from "modular-openscriptjs";
154+
155+
const h = app("h");
156+
157157
h.div(
158-
{ class: "bg-blue-500 text-white p-4 rounded-lg" },
159-
h.h1({ class: "text-2xl font-bold" }, "Styled with Tailwind")
160-
)
158+
{ class: "bg-blue-500 text-white p-4 rounded-lg" },
159+
h.h1({ class: "text-2xl font-bold" }, "Styled with Tailwind")
160+
);
161161
```
162162
163163
See [Tailwind Integration Guide](./docs/TAILWIND_INTEGRATION.md) for details.
164164
165165
## 🔧 Building Your App
166166
167167
```bash
168-
# Development
168+
# Development
169169
npm run dev
170170
171171
# Production build
@@ -181,13 +181,11 @@ For proper minification handling:
181181
182182
```javascript
183183
// vite.config.js
184-
import { openScriptComponentPlugin } from 'openscriptjs/plugin';
184+
import { openScriptComponentPlugin } from "modular-openscriptjs/plugin";
185185
186186
export default {
187-
plugins: [
188-
openScriptComponentPlugin()
189-
]
190-
}
187+
plugins: [openScriptComponentPlugin()],
188+
};
191189
```
192190
193191
This ensures component names survive minification.
@@ -209,9 +207,9 @@ MIT © Levi Kamara Zwannah
209207
210208
## 🔗 Links
211209
212-
- [GitHub Repository](https://github.com/yourusername/openscriptjs)
213-
- [Issue Tracker](https://github.com/yourusername/openscriptjs/issues)
214-
- [npm Package](https://www.npmjs.com/package/openscriptjs)
210+
- [GitHub Repository](https://github.com/yourusername/modular-openscriptjs)
211+
- [Issue Tracker](https://github.com/yourusername/modular-openscriptjs/issues)
212+
- [npm Package](https://www.npmjs.com/package/modular-openscriptjs)
215213
216214
---
217215

bin/create-ojs-app

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ async function createProject(projectName, template = "basic") {
8585
preview: "vite preview",
8686
},
8787
dependencies: {
88-
openscriptjs: "^1.0.0",
88+
"modular-openscriptjs": "^1.0.0",
8989
},
9090
devDependencies: {
9191
vite: "^5.0.7",

examples/advanced-features.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { Component, h, state, putContext, context, app } from "../index.js";
1+
import { Component, app, state, putContext, context } from "../index.js";
2+
3+
const h = app("h");
24

35
// 1. Fragments Example
46
class FragmentComponent extends Component {

examples/basic-app/events.js

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,66 @@
33
* Centralized event catalog following OpenScript best practices
44
*/
55

6-
import { broker } from "../../index.js";
6+
import { app } from "../../index.js";
7+
8+
const broker = app("broker");
79

810
/**
911
* Application Events
1012
* Structure: Nested object where keys become namespaced event names
1113
* Example: app.started becomes "app:started"
1214
*/
1315
export const $e = {
14-
app: {
15-
started: true,
16-
ready: true,
17-
},
16+
app: {
17+
started: true,
18+
ready: true,
19+
},
1820

19-
todo: {
20-
added: true,
21-
updated: true,
22-
deleted: true,
23-
completed: true,
24-
uncompleted: true,
21+
todo: {
22+
added: true,
23+
updated: true,
24+
deleted: true,
25+
completed: true,
26+
uncompleted: true,
2527

26-
needs: {
27-
add: true,
28-
update: true,
29-
delete: true,
30-
toggle: true,
31-
filter: true,
32-
},
28+
needs: {
29+
add: true,
30+
update: true,
31+
delete: true,
32+
toggle: true,
33+
filter: true,
34+
},
3335

34-
has: {
35-
addError: true,
36-
updateError: true,
37-
deleteError: true,
38-
list: true,
39-
}
36+
has: {
37+
addError: true,
38+
updateError: true,
39+
deleteError: true,
40+
list: true,
4041
},
42+
},
4143

42-
filter: {
43-
changed: true,
44-
cleared: true,
44+
filter: {
45+
changed: true,
46+
cleared: true,
4547

46-
needs: {
47-
apply: true,
48-
clear: true,
49-
}
48+
needs: {
49+
apply: true,
50+
clear: true,
5051
},
52+
},
5153

52-
ui: {
53-
needs: {
54-
modal: true,
55-
confirm: true,
56-
toast: true,
57-
},
54+
ui: {
55+
needs: {
56+
modal: true,
57+
confirm: true,
58+
toast: true,
59+
},
5860

59-
modal: {
60-
opened: true,
61-
closed: true,
62-
}
63-
}
61+
modal: {
62+
opened: true,
63+
closed: true,
64+
},
65+
},
6466
};
6567

6668
// Register all events with the broker

examples/basic-app/index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import { loadTodosFromLocalStorage } from "./helpers.js";
1616
import "./routes.js";
1717

1818
// Import OpenScript utilities
19-
import { broker, router } from "../../index.js";
19+
import { app } from "../../index.js";
20+
21+
const broker = app("broker");
22+
const router = app("router");
2023

2124
// ============================================
2225
// APPLICATION INITIALIZATION
@@ -27,10 +30,10 @@ console.log("🚀 Initializing Todo App...");
2730
// Load saved todos from localStorage
2831
const savedTodos = loadTodosFromLocalStorage();
2932
if (savedTodos.length > 0) {
30-
tc.todos.value = savedTodos;
31-
// Update nextId based on loaded todos
32-
const maxId = Math.max(...savedTodos.map(t => t.id || 0));
33-
tc.nextId = maxId + 1;
33+
tc.todos.value = savedTodos;
34+
// Update nextId based on loaded todos
35+
const maxId = Math.max(...savedTodos.map((t) => t.id || 0));
36+
tc.nextId = maxId + 1;
3437
}
3538

3639
// Emit app started event

0 commit comments

Comments
 (0)