rasti 2.1.0-alpha.0 → 3.0.0-alpha.0
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 +113 -28
- package/dist/rasti.js +1413 -109
- package/dist/rasti.min.js +1 -1
- package/es/Component.js +727 -509
- package/es/Emitter.js +85 -78
- package/es/Model.js +122 -128
- package/es/View.js +260 -239
- package/es/index.js +5 -5
- package/es/utils/getResult.js +13 -0
- package/lib/Component.cjs +784 -0
- package/lib/Emitter.cjs +133 -0
- package/lib/Model.cjs +176 -0
- package/lib/View.cjs +318 -0
- package/lib/index.cjs +14 -0
- package/lib/utils/getResult.cjs +15 -0
- package/package.json +69 -80
- package/src/Component.js +442 -231
- package/src/Emitter.js +37 -33
- package/src/Model.js +15 -9
- package/src/View.js +66 -37
- package/src/utils/getResult.js +11 -0
- package/lib/Component.js +0 -567
- package/lib/Emitter.js +0 -127
- package/lib/Model.js +0 -184
- package/lib/View.js +0 -298
- package/lib/index.js +0 -12
package/README.md
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/logo-dark.svg">
|
|
4
|
+
<img alt="Rasti.js" src="docs/logo.svg" height="120">
|
|
5
|
+
</picture>
|
|
6
|
+
</p>
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
8
|
+
<p align="center">
|
|
9
|
+
<b>Modern MVC for building user interfaces</b>
|
|
10
|
+
</p>
|
|
6
11
|
|
|
7
|
-
|
|
8
|
-
You can report bugs and discuss features on the [GitHub issues page](https://github.com/8tentaculos/rasti/issues).
|
|
12
|
+
**Rasti** is a lightweight MVC library for building fast, reactive user interfaces. Inspired by **Backbone.js**, it retains a familiar API while removing non-essential features and introducing modern, declarative, and composable components to simplify complex UI development.
|
|
9
13
|
|
|
10
14
|
[](https://app.travis-ci.com/8tentaculos/rasti)
|
|
11
15
|
[](https://www.npmjs.com/package/rasti)
|
|
16
|
+
[](https://unpkg.com/rasti/dist/rasti.min.js)
|
|
12
17
|
[](https://www.npmjs.com/package/rasti)
|
|
13
|
-
[](https://img.shields.io/jsdelivr/npm/hm/rasti?style=flat-square)](https://www.jsdelivr.com/package/npm/rasti)
|
|
14
19
|
|
|
15
|
-
##
|
|
20
|
+
## Key Features
|
|
21
|
+
|
|
22
|
+
- 🌟 **Declarative Components**: Build dynamic UI components using intuitive template literals.
|
|
23
|
+
- 🎯 **Event Delegation**: Simplify event handling with built-in delegation.
|
|
24
|
+
- 🔗 **Model-View Binding**: Keep your UI and data in sync with ease.
|
|
25
|
+
- 🌐 **Server-Side Rendering**: Render as plain text for server-side use or static builds.
|
|
26
|
+
- ⚡ **Lightweight and Fast**: Minimal overhead with efficient rendering.
|
|
27
|
+
- 🕰️ **Legacy Compatibility**: Seamlessly integrates into existing **Backbone.js** projects.
|
|
28
|
+
- 📐 **Standards-Based**: Built on modern web standards, no tooling required.
|
|
29
|
+
|
|
30
|
+
## Getting Started
|
|
16
31
|
|
|
17
32
|
### Using npm
|
|
18
33
|
|
|
@@ -40,14 +55,11 @@ import { Model, Component } from 'https://esm.run/rasti';
|
|
|
40
55
|
const { Model, Component } = Rasti;
|
|
41
56
|
```
|
|
42
57
|
|
|
43
|
-
|
|
44
|
-
The UMD builds make Rasti available as a `window.Rasti` global variable.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
### A simple `Component`
|
|
58
|
+
### Create a `Component`
|
|
48
59
|
|
|
49
60
|
```javascript
|
|
50
61
|
// Create Timer component.
|
|
62
|
+
// Renders seconds from model.
|
|
51
63
|
const Timer = Component.create`
|
|
52
64
|
<div>
|
|
53
65
|
Seconds: <span>${({ model }) => model.seconds}</span>
|
|
@@ -56,6 +68,7 @@ const Timer = Component.create`
|
|
|
56
68
|
// Create model to store seconds.
|
|
57
69
|
const model = new Model({ seconds: 0 });
|
|
58
70
|
// Mount timer on body.
|
|
71
|
+
// Pass model as options.
|
|
59
72
|
Timer.mount({ model }, document.body);
|
|
60
73
|
// Increment `model.seconds` every second.
|
|
61
74
|
setInterval(() => model.seconds++, 1000);
|
|
@@ -67,48 +80,120 @@ setInterval(() => model.seconds++, 1000);
|
|
|
67
80
|
|
|
68
81
|
```javascript
|
|
69
82
|
// Create Button component.
|
|
83
|
+
// Calls `options.handleClick` when clicked.
|
|
84
|
+
// Renders children passed to it.
|
|
70
85
|
const Button = Component.create`
|
|
71
86
|
<button
|
|
72
|
-
onClick
|
|
87
|
+
onClick=${{ '&' : function() { this.options.handleClick() } }}
|
|
73
88
|
>
|
|
74
|
-
${({ options }) => options.
|
|
89
|
+
${({ options }) => options.renderChildren()}
|
|
75
90
|
</button>
|
|
76
91
|
`;
|
|
77
92
|
// Create Counter component.
|
|
93
|
+
// Adds two Buttons to increment and decrement count.
|
|
94
|
+
// Displays current count.
|
|
78
95
|
const Counter = Component.create`
|
|
79
96
|
<div>
|
|
80
|
-
${(
|
|
81
|
-
|
|
82
|
-
|
|
97
|
+
<div>Counter: ${() => model.count}</div>
|
|
98
|
+
<${Button} handleClick=${({ model }) => () => model.count++}>
|
|
99
|
+
Increment
|
|
100
|
+
</${Button}>
|
|
101
|
+
<${Button} handleClick=${({ model }) => () => model.count--}>
|
|
102
|
+
Decrement
|
|
103
|
+
</${Button}>
|
|
83
104
|
</div>
|
|
84
105
|
`;
|
|
85
106
|
// Create model to store count.
|
|
86
107
|
const model = new Model({ count: 0 });
|
|
87
108
|
// Mount counter on body.
|
|
109
|
+
// Pass model as options.
|
|
88
110
|
Counter.mount({ model }, document.body);
|
|
89
111
|
```
|
|
90
112
|
|
|
91
113
|
[Try it on CodePen](https://codepen.io/8tentaculos/pen/ZEZarEQ?editors=0010)
|
|
92
114
|
|
|
115
|
+
### Rendering iterables
|
|
116
|
+
|
|
117
|
+
```javascript
|
|
118
|
+
// Routes data to be used in Navigation.
|
|
119
|
+
const routes = [
|
|
120
|
+
{ label : 'Home', href : '#' },
|
|
121
|
+
{ label : 'Faq', href : '#faq' },
|
|
122
|
+
{ label : 'Contact', href : '#contact' },
|
|
123
|
+
];
|
|
124
|
+
// Create Link component to be used in Navigation.
|
|
125
|
+
const Link = Component.create`
|
|
126
|
+
<a href="${({ options }) => options.href}">
|
|
127
|
+
${({ options }) => options.label}
|
|
128
|
+
</a>
|
|
129
|
+
`;
|
|
130
|
+
// Create Navigation component.
|
|
131
|
+
// Iterates over routes and mounts Link components.
|
|
132
|
+
const Navigation = Component.create`
|
|
133
|
+
<nav>
|
|
134
|
+
${({ options }) => options.routes.map(
|
|
135
|
+
({ label, href }) => Link.mount({ label, href })
|
|
136
|
+
)}
|
|
137
|
+
</nav>
|
|
138
|
+
`;
|
|
139
|
+
// Create Page component.
|
|
140
|
+
// Adds Navigation and displays current route label as title.
|
|
141
|
+
const Page = Component.create`
|
|
142
|
+
<main>
|
|
143
|
+
<${Navigation} routes=${({ options }) => options.routes} />
|
|
144
|
+
<section>
|
|
145
|
+
<h1>
|
|
146
|
+
${({ state, options }) => options.routes.find(
|
|
147
|
+
({ href }) => href === (state.location || '#')
|
|
148
|
+
).label}
|
|
149
|
+
</h1>
|
|
150
|
+
</section>
|
|
151
|
+
</main>
|
|
152
|
+
`;
|
|
153
|
+
// Local state to store location.
|
|
154
|
+
const model = new Model({ location : document.location.hash });
|
|
155
|
+
// Listen to location changes and update state.
|
|
156
|
+
window.addEventListener('popstate', () => model.location = document.location.hash);
|
|
157
|
+
// Mount counter on body.
|
|
158
|
+
// Pass routes and model as options.
|
|
159
|
+
Page.mount({ routes, model }, document.body);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
[Try it on CodePen](https://codepen.io/8tentaculos/pen/dyBMNbq?editors=0010)
|
|
163
|
+
|
|
164
|
+
## Why Choose **Rasti**?
|
|
165
|
+
|
|
166
|
+
### Why Choose Rasti?
|
|
167
|
+
|
|
168
|
+
- **Lightweight Applications**: Designed for streamlined apps, free from unnecessary overhead or tooling.
|
|
169
|
+
- **High-Performance Rendering**: Optimized for scenarios where speed matters, delivering fast updates and efficient rendering—ideal for large dynamic tables or datasets without needing virtual scrolling.
|
|
170
|
+
- **Seamless Legacy Integration**: Modernize your **Backbone.js** views progressively, enabling incremental improvements without a full rewrite.
|
|
171
|
+
|
|
172
|
+
|
|
93
173
|
## Example
|
|
94
174
|
|
|
95
|
-
The rasti [GitHub repository](https://github.com/8tentaculos/rasti) includes, in the [example folder](https://github.com/8tentaculos/rasti/tree/master/example/todo), an example [TODO application](
|
|
175
|
+
The rasti [GitHub repository](https://github.com/8tentaculos/rasti) includes, in the [example folder](https://github.com/8tentaculos/rasti/tree/master/example/todo), an example [TODO application](https://rasti.js.org/example/todo/index.html) that can be used as starter project.
|
|
176
|
+
|
|
177
|
+
## API Documentation
|
|
96
178
|
|
|
97
|
-
|
|
179
|
+
For detailed information on how to use **Rasti**, refer to the [API documentation](/docs/api.md).
|
|
98
180
|
|
|
99
|
-
Complete [API documentation](docs/api.md).
|
|
100
181
|
|
|
101
|
-
## Powered by Rasti
|
|
182
|
+
## Powered by **Rasti**
|
|
102
183
|
|
|
103
|
-
### Crypto Babylon
|
|
184
|
+
### [Crypto Babylon](https://cryptobabylon.net)
|
|
104
185
|
|
|
105
|
-
|
|
106
|
-
The Rasti rendering system is responsible for efficiently rendering a table containing over 300 rows. Additionally, it seamlessly updates the DOM in real-time, handling thousands of messages per second from multiple WebSocket connections.
|
|
186
|
+
A market analytics platform efficiently rendering over 300 dynamic rows, updated in real-time with thousands of messages per second via multiple WebSocket connections.
|
|
107
187
|
|
|
108
|
-
### jsPacman
|
|
188
|
+
### [jsPacman](https://pacman.js.org)
|
|
109
189
|
|
|
110
|
-
|
|
190
|
+
A DOM-based remake of the classic Ms. Pac-Man game. **Rasti** powers its custom game engine.
|
|
111
191
|
|
|
112
192
|
## License
|
|
113
193
|
|
|
114
|
-
[MIT](LICENSE.
|
|
194
|
+
**Rasti** is open-source and available under the [MIT License](LICENSE).
|
|
195
|
+
|
|
196
|
+
## Contributing
|
|
197
|
+
|
|
198
|
+
Contributions are welcome! Share feature ideas or report bugs on our [GitHub Issues page](https://github.com/8tentaculos/rasti/issues).
|
|
199
|
+
|