You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
run `cargo make all` in a terminal to build the app, and `cargo make serve` to start a dev server
23
28
on `127.0.0.0:8000`.
24
29
25
-
26
30
## A little deeper
27
-
Alternatively, create a new lib with Cargo: `cargo new --lib appname`. Here and everywhere it appears in this guide, `
28
-
appname` should be replaced with the name of your app.
31
+
32
+
Alternatively, create a new lib with Cargo: `cargo new --lib appname`. Here and everywhere it appears in this guide, `appname` should be replaced with the name of your app.
29
33
30
34
If not using the quickstart repo, create an Html file with a body that contains this:
35
+
31
36
```html
32
37
<sectionid="app"></section>
33
38
34
-
<scriptsrc='/pkg/package.js'></script>
39
+
<scriptsrc="/pkg/package.js"></script>
35
40
36
41
<script>
37
-
const { render } = wasm_bindgen;
38
-
functionrun() {
39
-
render();
40
-
}
41
-
wasm_bindgen('/pkg/package_bg.wasm')
42
-
.then(run)
43
-
.catch(console.error);
42
+
const { render } = wasm_bindgen;
43
+
functionrun() {
44
+
render();
45
+
}
46
+
wasm_bindgen("/pkg/package_bg.wasm")
47
+
.then(run)
48
+
.catch(console.error);
44
49
</script>
45
50
```
51
+
46
52
The first line above is an empty element with id: It's where your app will render.
47
53
The subsequent ones load your app's wasm modules.
48
54
49
-
The quickstart repo includes this file. You will eventually need to modify it to
55
+
The quickstart repo includes this file. You will eventually need to modify it to
50
56
change the page's title, add a description, favicon, stylesheet etc.
51
57
52
-
`Cargo.toml`, which is a file created by Cargo that describes your app, needs `wasm-bindgen`, `web-sys`, and `
53
-
seed` as depdendencies,
54
-
and crate-type
58
+
`Cargo.toml`, which is a file created by Cargo that describes your app, needs `wasm-bindgen`, `web-sys`, and `seed` as depdendencies,
59
+
and crate-type
55
60
of `"cdylib"`. The version in the quickstart repo has these set up already. Example:
56
61
57
62
```toml
@@ -71,12 +76,14 @@ web-sys = "^0.3.6"
71
76
```
72
77
73
78
## A short example
79
+
74
80
Here's an example demonstrating structure and syntax; it can be found in working form
75
-
in the [counter example](https://github.com/David-OConnor/seed/tree/master/examples/counter)
81
+
in the [counter example](https://github.com/David-OConnor/seed/tree/master/examples/counter)
76
82
Descriptions of its parts are in the
77
83
Guide section below. Its structure follows [The Elm Architecture](https://guide.elm-lang.org/architecture/).
78
84
79
-
*lib.rs*:
85
+
_lib.rs_:
86
+
80
87
```rust
81
88
#[macro_use]
82
89
externcrate seed;
@@ -177,16 +184,19 @@ pub fn render() {
177
184
.run();
178
185
}
179
186
```
187
+
180
188
For a truly minimimal example, see [lib.rs in the quickstart repo](https://github.com/David-OConnor/seed-quickstart/blob/master/src/lib.rs)
181
189
182
190
## Building and running
191
+
183
192
To build your app run `cargo make all`, and to host on a dev server, run `cargo make serve`.
184
193
185
194
For a more robust starting setup, check out Martin Kavik's [seed-quickstart-webpack repo](https://github.com/MartinKavik/seed-quickstart-webpack).
186
195
187
196
## Running included examples
197
+
188
198
To run an example located in the [examples folder](https://github.com/David-OConnor/seed/tree/master/examples),
189
-
run `cargo make start example_name`, where you replace `example_name` with the example name. Eg:
199
+
run `cargo make start example_name`, where you replace `example_name` with the example name. Eg:
190
200
`cargo make start counter`.
191
201
192
202
Some examples also require to run API server in another terminal window - `cargo make start_server example_name`.
@@ -195,63 +205,62 @@ When server(s) are running, open [127.0.0.1:8000](http://127.0.0.1:8000) in your
195
205
196
206
# About
197
207
198
-
199
208
## Goals
209
+
200
210
- Learning the syntax, creating a project, and building it should be easy - regardless
201
-
of your familiarity with Rust.
211
+
of your familiarity with Rust.
202
212
203
213
- Complete documentation that always matches the current version. Getting examples working, and
204
-
starting a project should be painless, and require nothing beyond this guide.
205
-
206
-
- Expressive, flexible view syntax that's easy to read and write.
214
+
starting a project should be painless, and require nothing beyond this guide.
207
215
216
+
- Expressive, flexible view syntax that's easy to read and write.
208
217
209
218
## A note on view syntax
219
+
210
220
This project uses an unconventional approach to describe how to display DOM elements.
211
221
It neither uses completely natural (ie macro-free) Rust code, nor
212
-
an HTML-like abstraction (eg JSX or templates). My intent is to make the code close
213
-
to natural Rust, while streamlining the syntax in a way suited for creating
222
+
an HTML-like abstraction (eg JSX or templates). My intent is to make the code close
223
+
to natural Rust, while streamlining the syntax in a way suited for creating
214
224
a visual layout with minimal repetition. The macros used are thin wrappers
215
225
for constructors, and don't conceal much. Specifically, the element-creation macros
216
-
allow for accepting a variable number of parameters, and the attrs/style marcros are
226
+
allow for accepting a variable number of parameters, and the attrs/style marcros are
217
227
essentially HashMap literals, with wrappers that let element macros know how to distinguish
218
228
them.
219
229
220
230
The lack of resemblance to HTML be offputting, but the learning
221
-
curve is shallow, and I think the macro syntax is close-enough to normal Rust that it's
231
+
curve is shallow, and I think the macro syntax is close-enough to normal Rust that it's
222
232
easy to reason about how to build views, without compartmentalizing it into logic code and display code.
223
-
This lack of separation in particular is a controversial decision, but I think the benefits
233
+
This lack of separation in particular is a controversial decision, but I think the benefits
224
234
are worth it.
225
235
226
-
227
236
## Where to start if you're familiar with existing frontend frameworks
237
+
228
238
The [todomvc example](https://github.com/David-OConnor/seed/tree/master/examples/todomvc) is an implementation of the [TodoMVC project](http://todomvc.com/),
229
239
which has example code in other frameworks that produce identitcal apps. Compare the example in this
230
240
project to one on that page that uses a framework you're familiar with.
231
241
232
-
233
242
## Influences
243
+
234
244
This project is strongly influenced by Elm, React, and Redux. The overall structure
235
245
of Seed apps mimicks that of The Elm Architecture.
236
246
237
-
238
247
## There are already several Rust/WASM frameworks; why add another?
239
248
240
-
I'm distinguishing Seed through clear examples and documentation, and using `wasm-bindgen`/`web-sys` internally. I started this
249
+
I'm distinguishing Seed through clear examples and documentation, and using `wasm-bindgen`/`web-sys` internally. I started this
241
250
project after being unable to get existing frameworks working
242
-
due to lack of documented examples, and inconsistency between documentation and
251
+
due to lack of documented examples, and inconsistency between documentation and
243
252
published versions. My intent is for anyone who's proficient in a frontend
244
-
framework to get a standalone app working in the browser within a few minutes, using just the
253
+
framework to get a standalone app working in the browser within a few minutes, using just the
245
254
quickstart guide.
246
255
247
-
Seed's different approach to view syntax also distinguishes it:
248
-
rather than use an HTML-like markup similar to JSX,
256
+
Seed's different approach to view syntax also distinguishes it:
257
+
rather than use an HTML-like markup similar to JSX,
249
258
it uses Rust builtin types, thinly-wrapped by macros that allow flexible composition.
250
259
This decision will not appeal to everyone, but I think it integrates more naturally with
251
260
the language.
252
261
253
-
254
262
## Why build a frontend in Rust over Elm, or Javascript-based frameworks?
263
+
255
264
You may prefer writing in Rust, and using packages from Cargo vice npm. Getting started with
256
265
this framework will in most cases be easier, and require less config and setup overhead than
257
266
with JS frameworks. You may appreciate Rust's compile-time error-checking, and built-in testing.
@@ -265,48 +274,47 @@ no distinction between components and normal functions. The API is
265
274
flexible, and avoids OOP boilerplate. Its integrated routing and message system
266
275
avoids the dependency glue-code associated with Redux and React-Router.
267
276
268
-
Seed has a *batteries-included* approach, which you may appreciate.
269
-
277
+
Seed has a _batteries-included_ approach, which you may appreciate.
270
278
271
279
## Why not to use this, and stick with JS
280
+
272
281
Seed's under rapid development, and breaking changes are likely. Finding Rust/WASM-help,
273
282
both in person, and in online communities will be difficult, and finding help for Seed
274
-
even more so. Seed doesn't have the wealth of existing reusable *components* that other frameworks
283
+
even more so. Seed doesn't have the wealth of existing reusable _components_ that other frameworks
275
284
have, so you will need to implement solved problems (eg date-pickers) yourself, or adapt them
276
285
from existing solutions. There are no existing tutorials or guides outside the official one, and
277
286
few examples.
278
287
279
288
Seed doesn't have a track-record of production apps. Finding developers experienced with Rust/wasm-bindgen,
280
289
or Seed specifically will be much more difficult than popular JS/compile-to-JS frameworks. Seed's feature-set
281
-
is incomplete compared to JS frameworks. Seed hasn't been benchmarked, and its performance may
290
+
is incomplete compared to JS frameworks. Seed hasn't been benchmarked, and its performance may
282
291
be lower than JS frameworks.
283
292
284
293
Seed's view syntax is non-standard compared to HTML-templates, or HTML-mockup languages like
285
294
`JSX`.
286
295
287
-
288
296
## What about Gloo ?
289
-
We're working closely with the `rustwasm` team on [Gloo](https://github.com/rustwasm/gloo), and
297
+
298
+
We're working closely with the `rustwasm` team on [Gloo](https://github.com/rustwasm/gloo), and
290
299
intend to incorporate `Gloo` crates into Seed as appropriate, as well as contribute Seed
291
300
code into `Gloo` crates. Seed's a cohesive, high-level framework, while `Gloo` will
292
301
be a versatile, standardized toolkit.
293
302
294
-
295
-
296
303
### Shoutouts
304
+
297
305
- The [WASM-Bindgen](https://github.com/rustwasm/wasm-bindgen) team,
298
-
for building the tools this project relies on
306
+
for building the tools this project relies on
299
307
- Alex Chrichton, for being extraodinarily helpful in the Rust / WASM community
300
308
- The [Elm](https://elm-lang.org/) team, for creating and standardizing the Elm architecture
301
309
- Mozilla, for excellent DOM documentation
302
310
- Denis Kolodin, for creating the inspirational [Yew framework](https://github.com/DenisKolodin/yew)
303
-
- Utkarsh Kukreti, for through his [Draco repo](https://github.com/utkarshkukreti/draco),
304
-
helping me understand how wasm-bindgen's
305
-
closure system can be used to update state.
311
+
- Utkarsh Kukreti, for through his [Draco repo](https://github.com/utkarshkukreti/draco),
312
+
helping me understand how wasm-bindgen's
313
+
closure system can be used to update state.
306
314
- Tim Robinson, for being very helpful on the [Rust Gitter](https://gitter.im/rust-lang/rust).
-[Mozilla MDN web docs](https://developer.mozilla.org/en-US/)
312
320
-[web-sys api](https://rustwasm.github.io/wasm-bindgen/api/web_sys/) (A good partner for the MDN docs - most DOM items have web-sys equivalents used internally)
@@ -315,4 +323,3 @@ be a versatile, standardized toolkit.
315
323
-[Seed's API docs](https://docs.rs/seed)
316
324
-[Learn Rust](https://www.rust-lang.org/learn)
317
325
-[Testing in Headless Browsers](https://rustwasm.github.io/wasm-bindgen/wasm-bindgen-test/browsers.html)
0 commit comments