rasti 3.0.1 → 4.0.0-alpha.1
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 +40 -19
- package/dist/rasti.js +1787 -628
- package/dist/rasti.min.js +1 -1
- package/es/Component.js +748 -473
- package/es/Emitter.js +182 -28
- package/es/Model.js +237 -51
- package/es/View.js +73 -31
- package/es/core/Element.js +55 -0
- package/es/core/EventsManager.js +41 -0
- package/es/core/Interpolation.js +70 -0
- package/es/core/InterpolationWrapper.js +14 -0
- package/es/core/Partial.js +12 -0
- package/es/core/PathManager.js +88 -0
- package/es/core/SafeHTML.js +17 -0
- package/es/index.js +13 -0
- package/es/utils/deepFlat.js +4 -2
- package/es/utils/findComment.js +42 -0
- package/es/utils/getAttributesDiff.js +33 -0
- package/es/utils/getAttributesHTML.js +25 -0
- package/es/utils/getResult.js +4 -2
- package/es/utils/parseHTML.js +14 -0
- package/es/utils/syncNode.js +109 -0
- package/es/utils/validateListener.js +14 -0
- package/lib/Component.cjs +749 -474
- package/lib/Emitter.cjs +182 -28
- package/lib/Model.cjs +237 -51
- package/lib/View.cjs +73 -31
- package/lib/core/Element.cjs +57 -0
- package/lib/core/EventsManager.cjs +43 -0
- package/lib/core/Interpolation.cjs +72 -0
- package/lib/core/InterpolationWrapper.cjs +16 -0
- package/lib/core/Partial.cjs +14 -0
- package/lib/core/PathManager.cjs +90 -0
- package/lib/core/SafeHTML.cjs +19 -0
- package/lib/index.cjs +13 -0
- package/lib/utils/deepFlat.cjs +4 -2
- package/lib/utils/findComment.cjs +44 -0
- package/lib/utils/getAttributesDiff.cjs +35 -0
- package/lib/utils/getAttributesHTML.cjs +27 -0
- package/lib/utils/getResult.cjs +4 -2
- package/lib/utils/parseHTML.cjs +16 -0
- package/lib/utils/syncNode.cjs +111 -0
- package/lib/utils/validateListener.cjs +16 -0
- package/package.json +11 -8
- package/src/Component.js +745 -472
- package/src/Emitter.js +182 -28
- package/src/Model.js +236 -51
- package/src/View.js +73 -31
- package/src/core/Element.js +55 -0
- package/src/core/EventsManager.js +41 -0
- package/src/core/Interpolation.js +70 -0
- package/src/core/InterpolationWrapper.js +14 -0
- package/src/core/Partial.js +12 -0
- package/src/core/PathManager.js +88 -0
- package/src/core/SafeHTML.js +17 -0
- package/src/index.js +4 -5
- package/src/utils/deepFlat.js +4 -2
- package/src/utils/findComment.js +40 -0
- package/src/utils/getAttributesDiff.js +31 -0
- package/src/utils/getAttributesHTML.js +23 -0
- package/src/utils/getResult.js +6 -2
- package/src/utils/parseHTML.js +12 -0
- package/src/utils/syncNode.js +107 -0
- package/src/utils/validateListener.js +12 -0
package/README.md
CHANGED
|
@@ -73,12 +73,13 @@ const Timer = Component.create`
|
|
|
73
73
|
`;
|
|
74
74
|
|
|
75
75
|
// Create a model to store the seconds.
|
|
76
|
-
const model = new Model({ seconds: 0 });
|
|
76
|
+
const model = new Model({ seconds : 0 });
|
|
77
77
|
|
|
78
78
|
// Mount the Timer component to the body and pass the model as an option.
|
|
79
79
|
Timer.mount({ model }, document.body);
|
|
80
80
|
|
|
81
81
|
// Increment the `seconds` property of the model every second.
|
|
82
|
+
// Only the text node inside the <span> gets updated on each render.
|
|
82
83
|
setInterval(() => model.seconds++, 1000);
|
|
83
84
|
```
|
|
84
85
|
|
|
@@ -89,22 +90,22 @@ setInterval(() => model.seconds++, 1000);
|
|
|
89
90
|
```javascript
|
|
90
91
|
// Define the routes for the navigation menu.
|
|
91
92
|
const routes = [
|
|
92
|
-
{ label: 'Home', href: '#' },
|
|
93
|
-
{ label: 'Faq', href: '#faq' },
|
|
94
|
-
{ label: 'Contact', href: '#contact' },
|
|
93
|
+
{ label : 'Home', href : '#' },
|
|
94
|
+
{ label : 'Faq', href : '#faq' },
|
|
95
|
+
{ label : 'Contact', href : '#contact' },
|
|
95
96
|
];
|
|
96
97
|
|
|
97
98
|
// Create a Link component for navigation items.
|
|
98
99
|
const Link = Component.create`
|
|
99
|
-
<a href="${({
|
|
100
|
-
${({
|
|
100
|
+
<a href="${({ props }) => props.href}">
|
|
101
|
+
${({ props }) => props.renderChildren()}
|
|
101
102
|
</a>
|
|
102
103
|
`;
|
|
103
104
|
|
|
104
105
|
// Create a Navigation component that renders Link components for each route.
|
|
105
106
|
const Navigation = Component.create`
|
|
106
107
|
<nav>
|
|
107
|
-
${({
|
|
108
|
+
${({ props, partial }) => props.routes.map(
|
|
108
109
|
({ label, href }) => partial`<${Link} href="${href}">${label}</${Link}>`
|
|
109
110
|
)}
|
|
110
111
|
</nav>
|
|
@@ -113,10 +114,10 @@ const Navigation = Component.create`
|
|
|
113
114
|
// Create a Main component that includes the Navigation and displays the current route's label as the title.
|
|
114
115
|
const Main = Component.create`
|
|
115
116
|
<main>
|
|
116
|
-
<${Navigation} routes=${({
|
|
117
|
+
<${Navigation} routes=${({ props }) => props.routes} />
|
|
117
118
|
<section>
|
|
118
119
|
<h1>
|
|
119
|
-
${({ model,
|
|
120
|
+
${({ model, props }) => props.routes.find(
|
|
120
121
|
({ href }) => href === (model.location || '#')
|
|
121
122
|
).label}
|
|
122
123
|
</h1>
|
|
@@ -125,7 +126,7 @@ const Main = Component.create`
|
|
|
125
126
|
`;
|
|
126
127
|
|
|
127
128
|
// Initialize a model to store the current location.
|
|
128
|
-
const model = new Model({ location: document.location.hash });
|
|
129
|
+
const model = new Model({ location : document.location.hash });
|
|
129
130
|
|
|
130
131
|
// Update the model's location state when the browser's history changes.
|
|
131
132
|
window.addEventListener('popstate', () => model.location = document.location.hash);
|
|
@@ -136,6 +137,30 @@ Main.mount({ routes, model }, document.body);
|
|
|
136
137
|
|
|
137
138
|
[Try it on CodePen](https://codepen.io/8tentaculos/pen/dyBMNbq?editors=0010)
|
|
138
139
|
|
|
140
|
+
### Adding event listeners
|
|
141
|
+
|
|
142
|
+
```javascript
|
|
143
|
+
// Create a model to store the counter value.
|
|
144
|
+
const model = new Model({ count : 0 });
|
|
145
|
+
|
|
146
|
+
// Create a Counter component with increment and decrement buttons.
|
|
147
|
+
const Counter = Component.create`
|
|
148
|
+
<div>
|
|
149
|
+
<div>Counter: ${({ model }) => model.count}</div>
|
|
150
|
+
<button onClick=${function() { this.model.count++; }}>Increment</button>
|
|
151
|
+
<button onClick=${function() { this.model.count--; }}>Decrement</button>
|
|
152
|
+
</div>
|
|
153
|
+
`;
|
|
154
|
+
|
|
155
|
+
// Mount the Counter component to the body and pass the model as an option.
|
|
156
|
+
Counter.mount({ model }, document.body);
|
|
157
|
+
|
|
158
|
+
// Event listeners are bound to 'this' and use delegation from the root element.
|
|
159
|
+
// When buttons are clicked, only the text node gets updated, not the entire component.
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
[Try it on CodePen](https://https://codepen.io/8tentaculos/pen/XJXVQOR?editors=0010)
|
|
163
|
+
|
|
139
164
|
## Why Choose **Rasti**?
|
|
140
165
|
|
|
141
166
|
**Rasti** is built for developers who want a simple yet powerful way to create UI components without the complexity of heavy frameworks. Whether you're building a high-performance dashboard, or embedding a lightweight widget, **Rasti** lets you:
|
|
@@ -155,16 +180,12 @@ You can find a sample **TODO application** in the [example folder](https://githu
|
|
|
155
180
|
|
|
156
181
|
For detailed information on how to use **Rasti**, refer to the [API documentation](/docs/api.md).
|
|
157
182
|
|
|
183
|
+
## Version History
|
|
158
184
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
A market analytics platform efficiently rendering over 300 dynamic rows, updated in real-time with thousands of messages per second via multiple WebSocket connections.
|
|
164
|
-
|
|
165
|
-
### [jsPacman](https://pacman.js.org)
|
|
166
|
-
|
|
167
|
-
A DOM-based remake of the classic Ms. Pac-Man game. **Rasti** powers its custom game engine.
|
|
185
|
+
- **[v4.0.0](https://github.com/8tentaculos/rasti/releases/tag/v4.0.0)** - Current version with simpler event handling, smarter component reuse, and granular DOM updates
|
|
186
|
+
- **[v3.0.0](https://github.com/8tentaculos/rasti/releases/tag/v3.0.0)** - Introduced **Containers**, dynamic element tags, **Component** tags, `partial` method, and dropped ES5 support
|
|
187
|
+
- **[v2.0.0](https://github.com/8tentaculos/rasti/releases/tag/v2.0.0)** - Introduced **Components**
|
|
188
|
+
- **[v1.0.0](https://github.com/8tentaculos/rasti/releases/tag/v1.0.0)** - Initial release
|
|
168
189
|
|
|
169
190
|
## License
|
|
170
191
|
|