Skip to content

Commit 6f4547c

Browse files
authored
Merge pull request #4 from OpenScriptJs/develop
finished the documentation and added local state initialization
2 parents b593667 + 3d35f17 commit 6f4547c

5 files changed

Lines changed: 9 additions & 8 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<p align="center">
44
<a href="https://github.com/OpenScriptJs/modular-openscript" target="_blank">
55
<!-- You can add a logo here if available -->
6-
<img src="https://via.placeholder.com/200x50?text=OpenScriptJs" alt="OpenScriptJs Logo" width="200">
6+
<img src="assets/images/OpenScript.Js.png" alt="OpenScriptJs Logo" width="200">
77
</a>
88
</p>
99

@@ -885,7 +885,7 @@ count.listener((s) => {
885885

886886
### Global vs Local State
887887

888-
- **Local State**: Defined inside a component's constructor (`this.count = state(0)`). Used for component-specific logic (toggles, form inputs).
888+
- **Local State**: Defined inside a component's constructor (`this.count = state(0); this.count.listener(this)`). Used for component-specific logic (toggles, form inputs).
889889
- **Global State**: Defined in a shared file (e.g., `contexts.js` or `store.js`) and imported by multiple components. Used for app-wide data (user profile, theme, cart).
890890

891891
---

assets/images/OpenScript.Js.png

25.2 KB
Loading

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.0.16",
3+
"version": "2.1.0",
44
"description": "OpenScriptJs Framework - A lightweight, reactive JavaScript framework for building modern web applications",
55
"type": "module",
66
"main": "./dist/modular-openscriptjs.umd.js",

src/component/Component.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ export default class Component {
320320
let final = {
321321
index: -1,
322322
parent: null,
323-
states: [],
324323
resetParent: false,
325324
replaceParent: false,
326325
firstOfParent: false,
@@ -335,7 +334,6 @@ export default class Component {
335334
) {
336335
args[i].listener(`component-${this.id}`);
337336
this.states[args[i].$__id__] = args[i];
338-
final.states.push(args[i].$__id__);
339337
} else if (
340338
!(
341339
args[i] instanceof DocumentFragment || args[i] instanceof HTMLElement
@@ -394,7 +392,6 @@ export default class Component {
394392
index,
395393
parent,
396394
resetParent,
397-
states,
398395
replaceParent,
399396
firstOfParent,
400397
reconcileParent,
@@ -456,7 +453,7 @@ export default class Component {
456453

457454
let uuid = this.id;
458455

459-
if (states?.length) {
456+
if (this.states?.length) {
460457
container.resolve("repository").addComponentArgs(this.id, args ?? []);
461458
}
462459

@@ -478,7 +475,7 @@ export default class Component {
478475
}
479476
}
480477

481-
states.forEach((id) => {
478+
Object.keys(this.states).forEach((id) => {
482479
attr[`s-${id}`] = id;
483480
});
484481

src/core/State.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ export default class State {
6565
}
6666

6767
this.$__listeners__.set(`component-${listener.id}`, listener);
68+
69+
// Add the state to the component's states
70+
listener.states[this.$__id__] = this;
71+
6872
return `component-${listener.id}`;
6973
} else {
7074
let id = this.$__CALLBACK_ID__++;

0 commit comments

Comments
 (0)