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`).
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`).
265
265
266
266
If you configured `broker.requireEventsRegistration(true)` in your `ojs.config.js`, only events defined here and registered will be allowed.
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)"`
Iterate over arrays or objects efficiently. Try to keep your callbacks stateless to avoid memory leaks.
719
722
720
723
```javascript
721
724
import { each } from"modular-openscriptjs";
@@ -743,8 +746,8 @@ Fragments allow you to group multiple elements without adding an extra node to t
743
746
h.$(h.li("Item 1"), h.li("Item 2"));
744
747
```
745
748
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.
748
751
> **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
752
750
753
### Special Attributes
@@ -856,10 +859,25 @@ h.div(
856
859
v(user, (u) =>`Hello, ${u.name}!`),
857
860
);
858
861
```
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
+
consth=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
+
```
859
877
860
878
### Reactivity & Objects
861
879
862
-
> [!CAUTION]
880
+
> [!CAUTION]
863
881
> **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