You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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`).
267
+
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`).
265
268
266
269
If you configured `broker.requireEventsRegistration(true)` in your `ojs.config.js`, only events defined here and registered will be allowed.
267
270
268
-
Create a `src/events.js` file:
271
+
Create a `src/ojs.events.js` file:
269
272
270
273
```javascript
271
274
/**
@@ -448,11 +451,11 @@ You are now set up with the basic structure of an OpenScript application!
448
451
449
452
OpenScript is built around an **Inversion of Control (IoC) Container**. Instead of importing global instances directly, you access core services via the `app()` helper.
For attributes that expect a string script (like `onclick`), use `this.method()`.
600
+
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)"`
Iterate over arrays or objects efficiently. Try to keep your callbacks stateless to avoid memory leaks.
719
725
720
726
```javascript
721
727
import { each } from"modular-openscriptjs";
@@ -743,8 +749,8 @@ Fragments allow you to group multiple elements without adding an extra node to t
743
749
h.$(h.li("Item 1"), h.li("Item 2"));
744
750
```
745
751
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.
752
+
> [!IMPORTANT]
753
+
> **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.
748
754
> **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.
749
755
750
756
### Special Attributes
@@ -857,9 +863,24 @@ h.div(
857
863
);
858
864
```
859
865
866
+
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'} }`
867
+
868
+
```javascript
869
+
import { v, app } from"modular-openscriptjs";
870
+
consth=app("h");
871
+
872
+
h.div(
873
+
h.h1("Welcome"),
874
+
// Only this specific span node updates when 'user' state changes
> **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.
0 commit comments