Code Monkey home page Code Monkey logo

Comments (6)

hwittenborn avatar hwittenborn commented on May 28, 2024

It looks like this is already handled as mentioned in #162 (comment), but it doesn't look like such behavior is currently documented.

Does the documentation for that not exist, or am I just looking in the wrong place?

from relm4.

hwittenborn avatar hwittenborn commented on May 28, 2024

I looked here in the documentation as well, and it also doesn't appear such behavior is documented.

from relm4.

hwittenborn avatar hwittenborn commented on May 28, 2024

Something I found a bit surprising is that using the new_var = old_var.field syntax doesn't automatically clone the field:

// Automatically clones `sender`
connect_changed[sender] => move |name_input| { ...

// Doesn't clone `model.errors`
connect_changed[errors = model.errors, sender] => move |name_input| { ...

// Clone's `model.errors` through manual `.clone()` call
connect_changed[errors = model.errors.clone(), sender] => move |name_input| { ...

Since the [var_name] syntax automatically clones the variable, I was thinking that the [new_var = old_var.field] syntax would also.

I can't really think of a case where you'd just rename with the [...] block but not clone, because at that point you could just let the closure take ownership of the old_var in question. Is this intended behavior for some other reason?

from relm4.

AaronErhardt avatar AaronErhardt commented on May 28, 2024

Something I found a bit surprising is that using the new_var = old_var.field syntax doesn't automatically clone the field:

This is because you might not want to use .clone() to duplicate your data. It's surely the most common trait, but some types in Rust have use methods.

from relm4.

hwittenborn avatar hwittenborn commented on May 28, 2024

I was mostly wondering when you wouldn't want to though, as I was thinking you'd pretty much always want to clone when using stuff like [errors = model.errors]. I guess if you had something like model.errors.error1, then it might make sense to just pass in the entire model.errors struct into the closure, while leaving the rest of model outside of it.

That makes enough sense to me, but the currently behavior for the [var = var.field] stuff still needs documented, right?

from relm4.

AaronErhardt avatar AaronErhardt commented on May 28, 2024

Yes, documentation is missing and we could add a shorter syntax for cloning struct fields, so we can keep this issue open until this is resolved.

from relm4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.