rasti 2.1.0-alpha.1 → 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 CHANGED
@@ -1,18 +1,33 @@
1
- # <a href="http://rasti.js.org"><img src="docs/logo.svg" height="80" alt="Rasti.js - JavaScript library for building user interfaces" aria-label="rasti.js.org" /></a>
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
- Rasti is a minimalistic JavaScript library for building user interfaces.
4
- It is designed to simplify the creation of complex dynamic applications by providing a declarative API for building reusable and composable UI components.
5
- Rasti is based on web standards, has a small footprint, and can be used directly in the browser without requiring any boilerplate or configuration.
8
+ <p align="center">
9
+ <b>Modern MVC for building user interfaces</b>
10
+ </p>
6
11
 
7
- The project is [hosted on GitHub](https://github.com/8tentaculos/rasti), and it's available for use under the [MIT](LICENSE.md) software license.
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
  [![Travis (.com)](https://img.shields.io/travis/com/8tentaculos/rasti?style=flat-square)](https://app.travis-ci.com/8tentaculos/rasti)
11
15
  [![npm version](https://img.shields.io/npm/v/rasti.svg?style=flat-square)](https://www.npmjs.com/package/rasti)
16
+ [![npm package minimized gzipped size](https://img.shields.io/bundlejs/size/rasti?style=flat-square)](https://unpkg.com/rasti/dist/rasti.min.js)
12
17
  [![npm downloads](https://img.shields.io/npm/dm/rasti.svg?style=flat-square)](https://www.npmjs.com/package/rasti)
13
- [![](https://data.jsdelivr.com/v1/package/npm/rasti/badge)](https://www.jsdelivr.com/package/npm/rasti)
18
+ [![jsDelivr hits (npm)](https://img.shields.io/jsdelivr/npm/hm/rasti?style=flat-square)](https://www.jsdelivr.com/package/npm/rasti)
14
19
 
15
- ## Getting started
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
- The [rasti npm package](https://www.npmjs.com/package/rasti) includes precompiled production and development UMD builds in the dist folder. They can be used directly without a bundler and are thus compatible with many popular JavaScript module loaders and environments.
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="${{ '&' : function() { this.options.onClick() } }}"
87
+ onClick=${{ '&' : function() { this.options.handleClick() } }}
73
88
  >
74
- ${({ options }) => options.label}
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
- ${({ model }) => Button.mount({ label : '-', onClick : () => model.count-- })}
81
- <span>${({ model }) => model.count}</span>
82
- ${({ model }) => Button.mount({ label : '+', onClick : () => model.count++ })}
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](http://rasti.js.org/example/todo/index.html) that can be used as starter project.
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
- ## API
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
- [Crypto Babylon](https://cryptobabylon.net), a markets analytics platform, leverages the capabilities of Rasti.
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
- [jsPacman](https://pacman.js.org), a JavaScript DOM-based remake of the classic Ms. Pac-Man game, utilizes Rasti at a low level for its custom game engine.
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.md)
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
+