Skip to content

Commit fe591c5

Browse files
committed
updated the readme
1 parent cbf24fa commit fe591c5

2 files changed

Lines changed: 32 additions & 14 deletions

File tree

README.md

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ We didn't just build another framework; we built a toolset for developers who va
7070

7171
### Installation
7272

73-
Start a project
73+
Start a project (All basic configurations are done)
7474
```bash
7575
npm create openscript-app <project-name> <template>
7676
```
@@ -261,11 +261,11 @@ configureApp();
261261
262262
### Define Application Events
263263

264-
OpenScript uses a centralized event broker. It's best practice to define all your application events in a single file, typically `events.js` (or `src/events.js`).
264+
OpenScript uses a centralized event broker. It's best practice to define all your application events in a single file, typically `ojs.events.js` (or `src/ojs.events.js`).
265265

266266
If you configured `broker.requireEventsRegistration(true)` in your `ojs.config.js`, only events defined here and registered will be allowed.
267267

268-
Create a `src/events.js` file:
268+
Create a `src/ojs.events.js` file:
269269

270270
```javascript
271271
/**
@@ -473,6 +473,7 @@ export default class Counter extends Component {
473473
constructor() {
474474
super();
475475
this.count = state(0);
476+
this.count.listener(this); // make this component listen to count state changes
476477
}
477478

478479
// Lifecycle Methods (prefixed with $_)
@@ -579,22 +580,24 @@ Listen to global application events dispatched via the Broker. Methods prefixed
579580
import { parsePayload } from "modular-openscriptjs";
580581
581582
export default class UserProfile extends Component {
582-
// Listen for 'auth' and 'login' event
583-
async $$auth_login(eventData, eventName) {
583+
// Listen for 'auth:login' and 'auth:logout' events
584+
$$auth = {
585+
login_logout: (eventData, eventName) {
584586
// 1. Parse the payload
585-
const data = parsePayload(eventData);
587+
const data = parsePayload(eventData);
586588
587-
console.log("User Logged In:", data.message.get("userId"));
589+
console.log("User Logged In:", data.message.get("userId"));
590+
}
588591
}
589592
}
590593
```
591594
592595
#### 4. Inline Attribute Listeners
593596

594-
For attributes that expect a string script (like `onclick`), use `this.method()`.
597+
For attributes that expect a string script (like `onclick`), use `this.method(methodName, ...arguments)`. This method formats the component methods such that it can be called from the html markup. Example: `onclick="handleClick(arg1, arg2)"`
595598

596599
```javascript
597-
h.button({ onclick: this.method("handleClick") }, "Click");
600+
h.button({ onclick: this.method("handleClick", "arg1", "arg2") }, "Click");
598601
```
599602

600603
---
@@ -715,7 +718,7 @@ h.div(
715718

716719
#### Iteration (`each`)
717720

718-
Iterate over arrays or objects efficiently.
721+
Iterate over arrays or objects efficiently. Try to keep your callbacks stateless to avoid memory leaks.
719722

720723
```javascript
721724
import { each } from "modular-openscriptjs";
@@ -743,8 +746,8 @@ Fragments allow you to group multiple elements without adding an extra node to t
743746
h.$(h.li("Item 1"), h.li("Item 2"));
744747
```
745748

746-
> [!IMPORTANT]
747-
> **Single Root Requirement**: Even when using fragments, your overall component structure or logic block must eventually anchor to a single parent element in the DOM tree.
749+
> [!IMPORTANT]
750+
> **Single Root Requirement**: Even when using fragments, your overall component structure or logic block must eventually anchor to a single parent element in the DOM tree.
748751
> **No Wrapper**: Components returning a fragment are **NOT** wrapped in a custom element (e.g., `<ojs-my-comp>`). This means they cannot easily hold local state or use lifecycle hooks that depend on the wrapper. Use fragments primarily for static content or splitting up render logic.
749752
750753
### Special Attributes
@@ -856,10 +859,25 @@ h.div(
856859
v(user, (u) => `Hello, ${u.name}!`),
857860
);
858861
```
862+
To style the anonymous component wrapper, you can add a third argument to the `v` helper. The third parameter should be an object like `{ c_attr: {class: 'mb-3 d-block'} }`
863+
```javascript
864+
import { v, app } from "modular-openscriptjs";
865+
const h = app("h");
866+
867+
h.div(
868+
h.h1("Welcome"),
869+
// Only this specific span node updates when 'user' state changes
870+
v(
871+
user,
872+
(u) => h.span(`Hello, ${u.value.name}!`),
873+
{ c_attr: {class: 'mb-3 d-block'} }
874+
),
875+
);
876+
```
859877

860878
### Reactivity & Objects
861879

862-
> [!CAUTION]
880+
> [!CAUTION]
863881
> **Object Property Pitfall**: Modifying a property of an object stored in state **does NOT** trigger the state to fire. The state system watches the reference of the value, not the deep properties.
864882
865883
```javascript

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "modular-openscriptjs",
3-
"version": "2.1.2",
3+
"version": "2.1.3",
44
"description": "OpenScriptJs Framework - A lightweight, reactive JavaScript framework for building modern web applications",
55
"type": "module",
66
"main": "./dist/modular-openscriptjs.umd.js",

0 commit comments

Comments
 (0)