rasti 3.0.0-alpha.0 → 3.0.0-alpha.2
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 -65
- package/dist/rasti.js +237 -107
- package/dist/rasti.min.js +1 -1
- package/es/Component.js +140 -60
- package/es/Emitter.js +7 -3
- package/es/Model.js +6 -6
- package/es/View.js +74 -38
- package/es/index.js +1 -0
- package/es/utils/deepFlat.js +12 -0
- package/lib/Component.cjs +140 -60
- package/lib/Emitter.cjs +7 -3
- package/lib/Model.cjs +6 -6
- package/lib/View.cjs +74 -38
- package/lib/index.cjs +1 -0
- package/lib/utils/deepFlat.cjs +14 -0
- package/package.json +2 -2
- package/src/Component.js +141 -61
- package/src/Emitter.js +7 -3
- package/src/Model.js +6 -6
- package/src/View.js +74 -38
- package/src/utils/deepFlat.js +12 -0
package/README.md
CHANGED
|
@@ -19,13 +19,20 @@
|
|
|
19
19
|
|
|
20
20
|
## Key Features
|
|
21
21
|
|
|
22
|
-
-
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
-
|
|
26
|
-
-
|
|
27
|
-
|
|
28
|
-
-
|
|
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.
|
|
29
36
|
|
|
30
37
|
## Getting Started
|
|
31
38
|
|
|
@@ -58,19 +65,20 @@ const { Model, Component } = Rasti;
|
|
|
58
65
|
### Create a `Component`
|
|
59
66
|
|
|
60
67
|
```javascript
|
|
61
|
-
//
|
|
62
|
-
// Renders seconds from model.
|
|
68
|
+
// Define a Timer component that displays the number of seconds from the model.
|
|
63
69
|
const Timer = Component.create`
|
|
64
70
|
<div>
|
|
65
71
|
Seconds: <span>${({ model }) => model.seconds}</span>
|
|
66
72
|
</div>
|
|
67
73
|
`;
|
|
68
|
-
|
|
74
|
+
|
|
75
|
+
// Create a model to store the seconds.
|
|
69
76
|
const model = new Model({ seconds: 0 });
|
|
70
|
-
|
|
71
|
-
//
|
|
77
|
+
|
|
78
|
+
// Mount the Timer component to the body and pass the model as an option.
|
|
72
79
|
Timer.mount({ model }, document.body);
|
|
73
|
-
|
|
80
|
+
|
|
81
|
+
// Increment the `seconds` property of the model every second.
|
|
74
82
|
setInterval(() => model.seconds++, 1000);
|
|
75
83
|
```
|
|
76
84
|
|
|
@@ -79,65 +87,30 @@ setInterval(() => model.seconds++, 1000);
|
|
|
79
87
|
### Adding sub components
|
|
80
88
|
|
|
81
89
|
```javascript
|
|
82
|
-
//
|
|
83
|
-
// Calls `options.handleClick` when clicked.
|
|
84
|
-
// Renders children passed to it.
|
|
85
|
-
const Button = Component.create`
|
|
86
|
-
<button
|
|
87
|
-
onClick=${{ '&' : function() { this.options.handleClick() } }}
|
|
88
|
-
>
|
|
89
|
-
${({ options }) => options.renderChildren()}
|
|
90
|
-
</button>
|
|
91
|
-
`;
|
|
92
|
-
// Create Counter component.
|
|
93
|
-
// Adds two Buttons to increment and decrement count.
|
|
94
|
-
// Displays current count.
|
|
95
|
-
const Counter = Component.create`
|
|
96
|
-
<div>
|
|
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}>
|
|
104
|
-
</div>
|
|
105
|
-
`;
|
|
106
|
-
// Create model to store count.
|
|
107
|
-
const model = new Model({ count: 0 });
|
|
108
|
-
// Mount counter on body.
|
|
109
|
-
// Pass model as options.
|
|
110
|
-
Counter.mount({ model }, document.body);
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
[Try it on CodePen](https://codepen.io/8tentaculos/pen/ZEZarEQ?editors=0010)
|
|
114
|
-
|
|
115
|
-
### Rendering iterables
|
|
116
|
-
|
|
117
|
-
```javascript
|
|
118
|
-
// Routes data to be used in Navigation.
|
|
90
|
+
// Define the routes for the navigation menu.
|
|
119
91
|
const routes = [
|
|
120
|
-
{ label
|
|
121
|
-
{ label
|
|
122
|
-
{ label
|
|
92
|
+
{ label: 'Home', href: '#' },
|
|
93
|
+
{ label: 'Faq', href: '#faq' },
|
|
94
|
+
{ label: 'Contact', href: '#contact' },
|
|
123
95
|
];
|
|
124
|
-
|
|
96
|
+
|
|
97
|
+
// Create a Link component for navigation items.
|
|
125
98
|
const Link = Component.create`
|
|
126
99
|
<a href="${({ options }) => options.href}">
|
|
127
100
|
${({ options }) => options.label}
|
|
128
101
|
</a>
|
|
129
102
|
`;
|
|
130
|
-
|
|
131
|
-
//
|
|
103
|
+
|
|
104
|
+
// Create a Navigation component that renders Link components for each route.
|
|
132
105
|
const Navigation = Component.create`
|
|
133
106
|
<nav>
|
|
134
|
-
${
|
|
135
|
-
({ label, href }) =>
|
|
107
|
+
${self => self.options.routes.map(
|
|
108
|
+
({ label, href }) => self.partial`<${Link} ${{ label, href }} />`
|
|
136
109
|
)}
|
|
137
110
|
</nav>
|
|
138
111
|
`;
|
|
139
|
-
|
|
140
|
-
//
|
|
112
|
+
|
|
113
|
+
// Create a Page component that includes the Navigation and displays the current route's label as the title.
|
|
141
114
|
const Page = Component.create`
|
|
142
115
|
<main>
|
|
143
116
|
<${Navigation} routes=${({ options }) => options.routes} />
|
|
@@ -150,12 +123,14 @@ const Page = Component.create`
|
|
|
150
123
|
</section>
|
|
151
124
|
</main>
|
|
152
125
|
`;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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.
|
|
156
131
|
window.addEventListener('popstate', () => model.location = document.location.hash);
|
|
157
|
-
|
|
158
|
-
//
|
|
132
|
+
|
|
133
|
+
// Mount the Page component to the body, passing the routes and model as options.
|
|
159
134
|
Page.mount({ routes, model }, document.body);
|
|
160
135
|
```
|
|
161
136
|
|