rasti 2.1.0-alpha.1 → 3.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 +106 -46
- package/dist/rasti.js +1502 -109
- package/dist/rasti.min.js +1 -1
- package/es/Component.js +788 -513
- package/es/Emitter.js +89 -78
- package/es/Model.js +124 -130
- package/es/View.js +280 -244
- package/es/index.js +6 -5
- package/es/utils/deepFlat.js +12 -0
- package/es/utils/getResult.js +13 -0
- package/lib/Component.cjs +844 -0
- package/lib/Emitter.cjs +137 -0
- package/lib/Model.cjs +176 -0
- package/lib/View.cjs +333 -0
- package/lib/index.cjs +15 -0
- package/lib/utils/deepFlat.cjs +14 -0
- package/lib/utils/getResult.cjs +15 -0
- package/package.json +69 -80
- package/src/Component.js +501 -233
- package/src/Emitter.js +44 -36
- package/src/Model.js +19 -13
- package/src/View.js +94 -50
- package/src/utils/deepFlat.js +12 -0
- package/src/utils/getResult.js +11 -0
- package/lib/Component.js +0 -570
- 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,40 @@
|
|
|
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)
|
|
19
|
+
|
|
20
|
+
## Key Features
|
|
21
|
+
|
|
22
|
+
- **Declarative Components** 🌟
|
|
23
|
+
Build dynamic UI components using intuitive template literals.
|
|
24
|
+
- **Event Delegation** 🎯
|
|
25
|
+
Simplify event handling with built-in delegation.
|
|
26
|
+
- **Model-View Binding** 🔗
|
|
27
|
+
Keep your UI and data in sync with ease.
|
|
28
|
+
- **Server-Side Rendering** 🌐
|
|
29
|
+
Render as plain text for server-side use or static builds.
|
|
30
|
+
- **Lightweight and Fast** ⚡
|
|
31
|
+
Minimal overhead with efficient rendering.
|
|
32
|
+
- **Legacy Compatibility** 🕰️
|
|
33
|
+
Seamlessly integrates into existing **Backbone.js** projects.
|
|
34
|
+
- **Standards-Based** 📐
|
|
35
|
+
Built on modern web standards, no tooling required.
|
|
36
|
+
|
|
37
|
+
## Getting Started
|
|
16
38
|
|
|
17
39
|
### Using npm
|
|
18
40
|
|
|
@@ -40,24 +62,23 @@ import { Model, Component } from 'https://esm.run/rasti';
|
|
|
40
62
|
const { Model, Component } = Rasti;
|
|
41
63
|
```
|
|
42
64
|
|
|
43
|
-
|
|
44
|
-
The UMD builds make Rasti available as a `window.Rasti` global variable.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
### A simple `Component`
|
|
65
|
+
### Create a `Component`
|
|
48
66
|
|
|
49
67
|
```javascript
|
|
50
|
-
//
|
|
68
|
+
// Define a Timer component that displays the number of seconds from the model.
|
|
51
69
|
const Timer = Component.create`
|
|
52
70
|
<div>
|
|
53
71
|
Seconds: <span>${({ model }) => model.seconds}</span>
|
|
54
72
|
</div>
|
|
55
73
|
`;
|
|
56
|
-
|
|
74
|
+
|
|
75
|
+
// Create a model to store the seconds.
|
|
57
76
|
const model = new Model({ seconds: 0 });
|
|
58
|
-
|
|
77
|
+
|
|
78
|
+
// Mount the Timer component to the body and pass the model as an option.
|
|
59
79
|
Timer.mount({ model }, document.body);
|
|
60
|
-
|
|
80
|
+
|
|
81
|
+
// Increment the `seconds` property of the model every second.
|
|
61
82
|
setInterval(() => model.seconds++, 1000);
|
|
62
83
|
```
|
|
63
84
|
|
|
@@ -66,49 +87,88 @@ setInterval(() => model.seconds++, 1000);
|
|
|
66
87
|
### Adding sub components
|
|
67
88
|
|
|
68
89
|
```javascript
|
|
69
|
-
//
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
90
|
+
// Define the routes for the navigation menu.
|
|
91
|
+
const routes = [
|
|
92
|
+
{ label: 'Home', href: '#' },
|
|
93
|
+
{ label: 'Faq', href: '#faq' },
|
|
94
|
+
{ label: 'Contact', href: '#contact' },
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
// Create a Link component for navigation items.
|
|
98
|
+
const Link = Component.create`
|
|
99
|
+
<a href="${({ options }) => options.href}">
|
|
74
100
|
${({ options }) => options.label}
|
|
75
|
-
</
|
|
101
|
+
</a>
|
|
76
102
|
`;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
103
|
+
|
|
104
|
+
// Create a Navigation component that renders Link components for each route.
|
|
105
|
+
const Navigation = Component.create`
|
|
106
|
+
<nav>
|
|
107
|
+
${({ options }) => options.routes.map(
|
|
108
|
+
({ label, href }) => Link.mount({ label, href })
|
|
109
|
+
)}
|
|
110
|
+
</nav>
|
|
111
|
+
`;
|
|
112
|
+
|
|
113
|
+
// Create a Page component that includes the Navigation and displays the current route's label as the title.
|
|
114
|
+
const Page = Component.create`
|
|
115
|
+
<main>
|
|
116
|
+
<${Navigation} routes=${({ options }) => options.routes} />
|
|
117
|
+
<section>
|
|
118
|
+
<h1>
|
|
119
|
+
${({ state, options }) => options.routes.find(
|
|
120
|
+
({ href }) => href === (state.location || '#')
|
|
121
|
+
).label}
|
|
122
|
+
</h1>
|
|
123
|
+
</section>
|
|
124
|
+
</main>
|
|
84
125
|
`;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
126
|
+
|
|
127
|
+
// Initialize a model to store the current location.
|
|
128
|
+
const model = new Model({ location: document.location.hash });
|
|
129
|
+
|
|
130
|
+
// Update the model's location state when the browser's history changes.
|
|
131
|
+
window.addEventListener('popstate', () => model.location = document.location.hash);
|
|
132
|
+
|
|
133
|
+
// Mount the Page component to the body, passing the routes and model as options.
|
|
134
|
+
Page.mount({ routes, model }, document.body);
|
|
89
135
|
```
|
|
90
136
|
|
|
91
|
-
[Try it on CodePen](https://codepen.io/8tentaculos/pen/
|
|
137
|
+
[Try it on CodePen](https://codepen.io/8tentaculos/pen/dyBMNbq?editors=0010)
|
|
138
|
+
|
|
139
|
+
## Why Choose **Rasti**?
|
|
140
|
+
|
|
141
|
+
### Why Choose Rasti?
|
|
142
|
+
|
|
143
|
+
- **Lightweight Applications**: Designed for streamlined apps, free from unnecessary overhead or tooling.
|
|
144
|
+
- **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.
|
|
145
|
+
- **Seamless Legacy Integration**: Modernize your **Backbone.js** views progressively, enabling incremental improvements without a full rewrite.
|
|
146
|
+
|
|
92
147
|
|
|
93
148
|
## Example
|
|
94
149
|
|
|
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](
|
|
150
|
+
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.
|
|
151
|
+
|
|
152
|
+
## API Documentation
|
|
96
153
|
|
|
97
|
-
|
|
154
|
+
For detailed information on how to use **Rasti**, refer to the [API documentation](/docs/api.md).
|
|
98
155
|
|
|
99
|
-
Complete [API documentation](docs/api.md).
|
|
100
156
|
|
|
101
|
-
## Powered by Rasti
|
|
157
|
+
## Powered by **Rasti**
|
|
102
158
|
|
|
103
|
-
### Crypto Babylon
|
|
159
|
+
### [Crypto Babylon](https://cryptobabylon.net)
|
|
104
160
|
|
|
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.
|
|
161
|
+
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
162
|
|
|
108
|
-
### jsPacman
|
|
163
|
+
### [jsPacman](https://pacman.js.org)
|
|
109
164
|
|
|
110
|
-
|
|
165
|
+
A DOM-based remake of the classic Ms. Pac-Man game. **Rasti** powers its custom game engine.
|
|
111
166
|
|
|
112
167
|
## License
|
|
113
168
|
|
|
114
|
-
[MIT](LICENSE.
|
|
169
|
+
**Rasti** is open-source and available under the [MIT License](LICENSE).
|
|
170
|
+
|
|
171
|
+
## Contributing
|
|
172
|
+
|
|
173
|
+
Contributions are welcome! Share feature ideas or report bugs on our [GitHub Issues page](https://github.com/8tentaculos/rasti/issues).
|
|
174
|
+
|