Comments (7)
One more thought on this: My suggestion to let update
return an Option<Model>
will cause trouble when calling update
recursively.
So maybe update
could return a tuple like: (Model, shouldRenderBool)
Of course this will break everything. But I think, sooner or later, a way to skip render at update
needs to be provided.
from seed.
Agree - will make breaking/significant changes if needed to get this working.
from seed.
The latest commit has your Tuple idea built in to the lib, and to the counter example. I don't like how it adds verbosity to the API, but I don't have a better approach. Perhaps there's a way to improve this using proc_macros, so that your update func could return just the model for a render, or a (Model, false) tuple for not rendering.
from seed.
I also don't like it. Another possibility: returning an enum:
enum ModelUpdate {
ShouldRender(Model),
SkipRender(Model)
}
from seed.
I like that more than tuple; got it working on my setup. Need to think on this; the enum approach isn't bad, but still adds code to every update branch for a minority use case. Putting the enum and its variants in the prelude to minimize extra code.
Counter:
fn update(msg: Msg, model: Model) -> ModelUpdate<Model> {
match msg {
Msg::Increment => Render(Model {count: model.count + 1, ..model}),
Msg::Decrement => Skip(Model {count: model.count - 1, ..model}),
Msg::ChangeWWC(what_we_count) => Render(Model {what_we_count, ..model }),
}
}
If the update func's set up in a mutable way, there will be less extra, especially if all branches are Render (or Skip) Eg, with all paths render:
fn update(msg: Msg, model: Model) -> ModelUpdate<Model> {
let mut model = model;
match msg {
Msg::Increment => model.count += 1,
Msg::Decrement => model.count -= 1,
Msg::ChangeWWC(what_we_count) =>model.what_we_count = what_we_count,
}
Render(model)
}
from seed.
If you go with the enum approach, then maybe shortening the enum name also saves some extra
enum Update {
Render(Model),
Skip(Model)
}
from seed.
Included in v0.2.4 release, using your last suggestion. I think the extra verbosity is worth the flexibility.
from seed.
Related Issues (20)
- error[E0425]: cannot find function `wheel_ev` in this scope HOT 1
- 1. Create a new issue in the Seed repo with the name and copy-paste this checklist into it (also add blockers and additional tasks, if exist).
- Maintenance & Future of Seed HOT 8
- v0.9.1: browser::json::Error is inaccessible
- Deserializing large numbers fail HOT 11
- Websocket example does not work HOT 2
- how to integrate with another wasm ?
- Websocket API changed from 0.8 to 0.9 HOT 5
- DOM node is not attached to ElRef under some conditions HOT 6
- Does not build with wasm-bindgen 0.2.81 HOT 3
- Closures need types HOT 3
- Release v0.9.2 HOT 3
- Seed 0.8 accepting the newest wasm-bindgen HOT 3
- [0.8.x] WebSocket and too early dropped closure HOT 1
- support `beforeinput` events HOT 1
- Seed doesn't compile with `default-features = false` HOT 2
- checkbox not working HOT 2
- Release v0.10.0 HOT 3
- Cannot use subs (subs::UrlChanged) HOT 2
- Error: unresolved import in wasm_bindgen_initialize HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from seed.