Skip to content

Commit

Permalink
Merge branch 'master' into 17/doc_link_fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
itsgreggreg authored Mar 9, 2020
2 parents 62a6b4f + 70e7924 commit c023b95
Show file tree
Hide file tree
Showing 16 changed files with 684 additions and 487 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

https://seed-rs.org/

Based on [Seed-quickstart-webpack](https://github.com/seed-rs/seed-quickstart-webpack]).
Based on [Seed-quickstart-webpack](https://github.com/seed-rs/seed-quickstart-webpack).

To build this site in a local environment, follow the instructions in the above link.
Make sure to use `rustc nightly` - run `rustup default nightly`, in order for the verification
Expand Down
308 changes: 192 additions & 116 deletions crate/Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions crate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ build = "build.rs"
crate-type = ["cdylib"]

[build-dependencies]
pulldown-cmark = "^0.6.0"
pulldown-cmark = "^0.6.1"

[dev-dependencies]
wasm-bindgen-test = "^0.2.50" # sync with `wasm-bindgen`
wasm-bindgen-test = "^0.3.8"

[dependencies]
wasm-bindgen = "^0.2.50" # sync with `wasm-bindgen-test`
serde = { version = "^1.0.102", features = ['derive'] }
serde_json = "^1.0.41"
seed = "0.5.0"
#seed = { git = "https://github.com/seed-rs/seed", branch="master" }
#seed = { path = "../../seed" }
wasm-bindgen = "^0.2.58"
serde = { version = "^1.0.104", features = ['derive'] }
serde_json = "^1.0.45"
#seed = "0.6.0"
seed = { git = "https://github.com/seed-rs/seed.git" }

[dependencies.web-sys]
version = "^0.3.28"
version = "^0.3.35"
features = [
"ScrollToOptions",
"Navigator",
]

[profile.release]
lto = true
opt-level = 's'
opt-level = 'z'
codegen-units = 1
34 changes: 30 additions & 4 deletions crate/guides/changelog.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
# Changelog

# Changelog

[unreleased]

- (placeholder)

## v0.6.0
- Implemented `UpdateEl` for `Filter` and `FilterMap`.
- Added method `El::is_custom(&self)`.
- Fixed custom elements patching (#325).
- Removed unnecessary error message for comment nodes.
- [BREAKING] Removed deprecated `update` and `trigger_update_ev`.
- [BREAKING] Removed the remains of lifecycle hooks.
- Fixed `value` and `checked` setting for input elements (a bug in VirtualDOM patch algorithm).
- [BREAKING] Removed unpredictable internal input listeners - Seed will not longer react to external input value changes.
- [BREAKING] Use `EventHandler` instead of `Listener`. (`Listener` is now used as the internal DOM EventListener representation.)
- [deprecated] - `raw_ev` is deprecated in favor of `ev`. Functionality is the same.
- Improved performance - rewritten event-handling and other refactors in VirtualDOM.
- Fixed processing of multiple event-handlers (#138).
- Added DOM Element references - see `ElRef` and examples (`canvas`, `user_media` or `todomvc`) (#115).
- Removed `Ms: Clone` restriction as much as possible.
- [BREAKING] Added or changed `Custom` variant from `Custom(String)` to `Custom(Cow<'static, str>)`
in `Ev`, `Tag`, `At` and `St`. Use function `from` to create custom entities (e.g. `At::from("my-attribute")`) (#208).
- Added macro `nodes!`. It accepts `Node<Msg>` and `Vec<Node<Msg`, returns flattened `Vec<Node<Msg>`.
- Refactored all examples.
- Fixed and rewritten example `todomvc`.
- Renamed `counter` example to `counter_advanced`.
- Renamed `drop` example to `drop_zone`.
- Removed `server_interaction_detailed` example.
- Added a new simpler `counter` example.
- Changed example in the main `README.md`.
- Added flag `#![forbid(unsafe_code)]` so the Seed will be marked as a safe library by the Rust community tools.
- Removed `clone` restriction from the method `Effect::map_msg`.
- Implemented `UpdateEl` for `FlatMap`.

## v0.5.1
- [BREAKING] `MessageMapper::map_message` changed to `MessageMapper::map_msg`.
- [BREAKING] `fetch` and `storage` moved to `seed::browser::service::{fetch, storage}`,
Expand All @@ -16,7 +42,7 @@ but reimported at the lib level. Ie: `seed::fetch`, and `seed::storage`.
- Export `Attrs`, `Style`, `Listener`. ie, can import with `seed::Style` etc.
- Fixed a bug causing the docs not to build.

## 0.5.0
## v0.5.0
- Added helper `seed::canvas()`, and `seed::canvas_context()` helper functions.
- Fixed `Url` parsing (resolves issue with hash routing).
- [BREAKING] `From<String> for Url` changed to `TryFrom<String> for Url`.
Expand Down
53 changes: 20 additions & 33 deletions crate/guides/code_comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,20 @@ way to handle it. We're also using Typescript.

## React

```jsx
import * as React from "react"
import * as ReactDOM from "react-dom"
```tsx
import * as React from 'react'
import * as ReactDOM from 'react-dom'

interface MainProps {}
interface MainState {
val: number
}

class Main extends React.Component<MainProps, MainState> {
constructor(props) {
super(props)

this.state = {
val: 0
}
const Main: React.FC<MainProps> = () => {
const [value, setValue] = React.useState<number>(0)
const increment = () => setValue(value + 1)

this.increment = this.increment.bind(this)
}

increment() {
this.setState({val: this.state.val + 1})
}

render() {
return (
<button onClick={() => this.state.increment()}>
{"Hello, World × " + this.state.val}
</button>
)
}
return <button onClick={increment}>{'Hello, World × ' + value}</button>
}

ReactDOM.render(<Main />, document.getElementById("app"))
ReactDOM.render(<Main />, document.getElementById('app'))
```


Expand Down Expand Up @@ -98,15 +78,22 @@ pub fn render() {

## React

```jsx
const Form = ({name, color, value, changeText, doIt}:
{name: string, color: string, value: number, changeText: Function, doIt: Function}) {
```tsx
interface Props {
name: string
color: string
value: number
changeText: (ev: React.ChangeEvent<HTMLInputElement>) => void
doIt: Function
}

const Form: React.FC<Props> = ({ name, color, value, changeText, doIt }) => {
// A description
const style: CSSProperties = {fontSize: 12, color: color}
const style: React.CSSProperties = { fontSize: 12, color: color }

return (
<>
<input value={value.toString() onChange={(ev) => changeText(ev)} />
<input value={value.toString()} onChange={changeText} />

<button
className="buttons"
Expand Down
11 changes: 2 additions & 9 deletions crate/guides/misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ To output to the web browser's console (ie `console.log()` in JS), use
in a similar way, equivalent to JS's `console.error()`.

## Custom tags
Seed generally retricts the element tags allowed by using Enums for the tags, and
Seed generally restricts the element tags allowed by using Enums for the tags, and
a predefined set of element-creation macros. If you wish to use a custom tag, you can
use using `Tag::from` (`El` and `Tag` are
exposed in the prelude), either with the `El::empty` constructor, or using the `custom!`
Expand Down Expand Up @@ -131,11 +131,4 @@ Additionally, use `seed::html_document()` in the same way, to return a

We also include `seed::canvas()`, and `seed::canvas_context()`.

You can call `seed::cookies()` to retrieve all cookies from the current `HtmlDocument`.

## Input elements are controlled
`input`, `textarea`, and `select` elements are always controlled, in the vein of `React`'s
[controlled components](https://reactjs.org/docs/forms.html#controlled-components).
This means that even if there's no event associated with user input to these fields, their
value will always stay in sync with the model, which may mean ignoring text input if
not set up with a `Ev::Input` event.
You can call `seed::cookies()` to retrieve all cookies from the current `HtmlDocument`.
26 changes: 25 additions & 1 deletion crate/guides/quickstart.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# New features in v0.6.0:
Reference [this PR](https://github.com/seed-rs/seed/pull/330).

- Added the `nodes!` enum. This vec-like enum can be used to combine different collections
of `Node`s, for use in view macros.
Example:
```rust
nodes![
h1!["a node"],
vec![
h4["a vec"],
h4["of nodes"],
],
]
```

- You can use native DOM elements safely because
`ElRef::get` checks if the referenced element exists,
is in the DOM now, and has the right type. Check ouf the `canvas`, `user_media`,
or `todomvc` examples.

- `El::custom` added; this can be used to create an Element with a custom / arbitrary tag.


# Quickstart

## Setup
Expand Down Expand Up @@ -53,7 +77,7 @@ edition = "2018"
crate-type = ["cdylib"]

[dependencies]
seed = "^0.5.0"
seed = "^0.6.0"
wasm-bindgen = "^0.2.50"
```

Expand Down
2 changes: 1 addition & 1 deletion crate/guides/server_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ tokio-timer = "0.2.11"
shared = { path = "../shared" }
```

The client's `cargo.toml` is a standard Seed one. The shared `Cargo.toml` includes
The client's `Cargo.toml` is a standard Seed one. The shared `Cargo.toml` includes
whatever you need for your shared data structures and code; it will usually include
`serde` for serializing and deserializing, and may include database code, since
this crate is a good place for database models and schema.
Expand Down
62 changes: 37 additions & 25 deletions crate/guides/structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,19 @@ See the [view section](https://seed-rs.org/guide/view) for details.


## Initializing
To start your app, call the `App::builder` method, which takes the following parameters:
To start your app, call the `App::builder` method, which creates an
[Builder struct](https://docs.rs/seed/0.6.0/seed/app/builder/struct.Builder.html) struct.
It has the the following optional methods:

- An `init` function which accepts an initial routing, initial orders, and outputs
an [Init struct](https://docs.rs/seed/latest/seed/app/builder/init/struct.Init.html) (imported in the prelude),
wrapping the initial model.
- Your update function
- Your view function
- `before_mount` - Specify a function which allow you to
select the HTML element where the app will be mounted and how it'll be mounted.
- `after_mount` - Used to initialize the model, and provide initial URL handling.
- `routes` - used to specify routing function. See the Routing section for details.
- `window_events` Registers a function which decides how window events will be handled.
- `sync` - Registers a sync function. (Fill out)

And the following mandatory one:
- `build_and_start` - run at the end, to initialize the app.

You can can chain the following optional methods:

Expand All @@ -160,35 +166,28 @@ state based on url (See the `Routing` section)

And must must complete with the method `.build_and_start();`.

`.mount()` takes a single argument, which can be the id of the element you wish to mount in,
a `web_sys::Element`, or a `web_sys::HtmlElement`. Examples:
`App::builder(update, view).mount(seed::body())`
`App::builder(update, view).mount('a_div_id`)`

```
App::builder(update, view).mount(
seed::body().querySelector("section").unwrap().unwrap()
)
```

The `App::builder` call must be wrapped in a function with the `#[wasm_bindgen(start)]` invocation.

This will render your app to the element holding the id you passed; in the case of this example,
"main". The only part of the web page Seed will interact with is that element, so you can
use other HTML not part of Seed, or other JS code/frameworks in the same document.

Example, with optional methods:
Example using a custom mount point:
```rust
fn before_mount(_url: Url) -> BeforeMount {
BeforeMount::new()
.mount_point("main")
.mount_type(MountType::Takeover)
}

#[wasm_bindgen(start)]
pub fn render() {
App::builder(update, view)
.mount("main")
.routes(routes)
.window_events(window_events)
.before_mount(before_mount)
.build_and_start();
}
```

This will render your app to the element holding the id you passed; in the case of this example,
"main". The only part of the web page Seed will interact with is that element, so you can
use other HTML not part of Seed, or other JS code/frameworks in the same document.

Example of using an `after_mount` function:
```rust
fn after_mount(url: Url, orders: &mut impl Orders<Msg>) -> AfterMount<Model> {
Expand All @@ -213,3 +212,16 @@ pub fn render() {
`AfterMount::default()` covers the most common use-cases, where the model is initialized with its
`default::Default` implementation. (This is also true if we don't use the `.after_mount()` method.
You can pass a different model by using `after_mount::new(model)`, where `model` here is your model.


Example, with `route` and `window_events`, described in the Routing and Misc sections of this guide
respectively:
```rust
#[wasm_bindgen(start)]
pub fn render() {
App::builder(update, view)
.routes(routes)
.window_events(window_events)
.build_and_start();
}
```
6 changes: 3 additions & 3 deletions crate/guides/view.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ For boolean attributes that are handled by presense or absense, like `disabled`,
```rust
fn a_component() -> Node<Msg> {
// ...
input![ attrs!{At::Typed => "checkbox"; At::Checked => true.as_at_value()} ]
input![ attrs!{At::Autofocus => true.as_at_value()} ]
input![ attrs!{At::Type => "checkbox"; At::Checked => true.as_at_value()} ]
input![ attrs!{At::AutoFocus => true.as_at_value()} ]
// ...
}
```
Expand Down Expand Up @@ -293,7 +293,7 @@ let my_el = div![]
.add_class("complete")
.add_attr("alt".to_string(), "a description".to_string())
.add_style(St::Height, "20px".to_string())
.replace_text("Oops, not complete");oo
.replace_text("Oops, not complete");

```

Expand Down
30 changes: 16 additions & 14 deletions crate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ use serde_json;
use std::{convert::identity, fmt};
use Visibility::*;

const SEED_VERSION: &str = "0.5.0 (Dec 04, 2019)";
const SEED_VERSION: &str = "0.6.0";
const SEED_VERSION_DATE: &str = "Feb 1, 2020";
const TITLE_SUFFIX: &str = "Seed";
const STORAGE_KEY: &str = "seed";
const USER_AGENT_FOR_PRERENDERING: &str = "ReactSnap";
Expand Down Expand Up @@ -324,19 +325,20 @@ fn search(guides: &[Guide], query: &str) -> Vec<Guide> {
// ------ ------

pub fn view(model: &Model) -> impl View<Msg> {
let mut nodes = vec![div![
class![C.min_h_screen, C.bg_white,],
match model.page {
Page::Guide {
guide,
show_intro,
} => page::guide::view(&guide, model, show_intro).els(),
Page::NotFound => page::not_found::view().els(),
},
page::partial::header::view(model).els(),
]];
nodes.append(&mut blender::view_for_content(model.mode).els());
nodes
nodes![
div![
class![C.min_h_screen, C.bg_white,],
match model.page {
Page::Guide {
guide,
show_intro,
} => page::guide::view(&guide, model, show_intro).els(),
Page::NotFound => page::not_found::view().els(),
},
page::partial::header::view(model).els(),
],
blender::view_for_content(model.mode).els(),
]
}

// ------ ------
Expand Down
Loading

0 comments on commit c023b95

Please sign in to comment.