mates 0.0.16 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -47,10 +47,37 @@ const CounterView = (props) => {
|
|
|
47
47
|
renderView(CounterView, "app");
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
+
**count** is a **local let variable** that holds value. which can only be changed froma setter function.
|
|
51
|
+
**incr** is a **setter** function, that when called, updates the view. it has to be non-async.
|
|
52
|
+
|
|
53
|
+
### Scopes
|
|
54
|
+
|
|
55
|
+
Mates introduces a new feature called Scopes. an amazing way to share state with child views (components). using Scopes, child components can access parent's state directly without using props.
|
|
56
|
+
|
|
50
57
|
#### Formatting Support:
|
|
51
58
|
|
|
52
59
|
you can install lit-html plugin on your IDE like vs code or cursor for proper formatting for your template strings.
|
|
53
60
|
|
|
61
|
+
### props()
|
|
62
|
+
|
|
63
|
+
In Mates, props can be passed to child views as object. props is a funciton and not an object but it's passed as object to child component. the view will have to call props() to get the projects object.
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
const CounterView = () => {
|
|
67
|
+
let count = 0;
|
|
68
|
+
let incr = setter(() => count++);
|
|
69
|
+
return () => html`
|
|
70
|
+
<div>count is: ${count}</div>
|
|
71
|
+
<div>${view(ChildView, { count })}</div>
|
|
72
|
+
`;
|
|
73
|
+
};
|
|
74
|
+
const ChildView = (props: Props<{ count: number }>) => {
|
|
75
|
+
return html`parent count is : ${props().count}`;
|
|
76
|
+
};
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**note** please don't destructure props into local variables in the outer function, as it breaks connection from the parent object. but you can do this in the inner function as inner function gets executed everytime the parent view is updated. so you will have always the latest value.
|
|
80
|
+
|
|
54
81
|
### ⚛️ Atoms: Simple Reactive State
|
|
55
82
|
|
|
56
83
|
Atoms hold mutable values. they can hold any Javascript value like primitive or objects or maps or sets.etc They store a single value that can be read, set (replaced with new value), or updated (if it's an object). They support typescript fully.
|
|
@@ -137,9 +164,9 @@ const todoList = unit({
|
|
|
137
164
|
this._setUsers(await fetch("/users").then((d) => d.json()));
|
|
138
165
|
this._setIsLoading(false);
|
|
139
166
|
},
|
|
140
|
-
getUsersCount(){
|
|
167
|
+
getUsersCount() {
|
|
141
168
|
return this.users.length;
|
|
142
|
-
}
|
|
169
|
+
},
|
|
143
170
|
});
|
|
144
171
|
```
|
|
145
172
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mates",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Mates is a front end framework for building web applications",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"rollup": "^3.29.4",
|
|
54
54
|
"rollup-plugin-dts": "^6.1.0",
|
|
55
55
|
"ts-jest": "^29.1.1",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
56
|
+
"tslib": "^2.8.1",
|
|
57
|
+
"typescript": "^5.3.2"
|
|
58
58
|
}
|
|
59
59
|
}
|