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 CHANGED
@@ -19,13 +19,20 @@
19
19
 
20
20
  ## Key Features
21
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.
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
- // Create Timer component.
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
- // Create model to store seconds.
74
+
75
+ // Create a model to store the seconds.
69
76
  const model = new Model({ seconds: 0 });
70
- // Mount timer on body.
71
- // Pass model as options.
77
+
78
+ // Mount the Timer component to the body and pass the model as an option.
72
79
  Timer.mount({ model }, document.body);
73
- // Increment `model.seconds` every second.
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
- // Create Button component.
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 : 'Home', href : '#' },
121
- { label : 'Faq', href : '#faq' },
122
- { label : 'Contact', href : '#contact' },
92
+ { label: 'Home', href: '#' },
93
+ { label: 'Faq', href: '#faq' },
94
+ { label: 'Contact', href: '#contact' },
123
95
  ];
124
- // Create Link component to be used in Navigation.
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
- // Create Navigation component.
131
- // Iterates over routes and mounts Link components.
103
+
104
+ // Create a Navigation component that renders Link components for each route.
132
105
  const Navigation = Component.create`
133
106
  <nav>
134
- ${({ options }) => options.routes.map(
135
- ({ label, href }) => Link.mount({ label, href })
107
+ ${self => self.options.routes.map(
108
+ ({ label, href }) => self.partial`<${Link} ${{ label, href }} />`
136
109
  )}
137
110
  </nav>
138
111
  `;
139
- // Create Page component.
140
- // Adds Navigation and displays current route label as title.
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
- // Local state to store location.
154
- const model = new Model({ location : document.location.hash });
155
- // Listen to location changes and update state.
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
- // Mount counter on body.
158
- // Pass routes and model as options.
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