Skip to content

An alternative to neq_assign_by #1560

@intendednull

Description

@intendednull

Describe the feature you'd like
It might be useful to provide a method similar to neq_assign_by that doesn't flip the resulting value.

Is your feature request related to a problem? Please describe. (Optional)
I found myself a little confused here:

 fn change(&mut self, props: Self::Properties) -> ShouldRender {
        log::debug!(
            "Equal {:?}",
            self.props.handle.state().session == props.handle.state().session
        );
        let render = self.props.neq_assign_by(props, |a, b| {
            a.handle.state().session == b.handle.state().session || a.id == b.id  // ids are equal, so it doesn't assign
        });
        log::debug!("Should render {:?}", render);
        render
    }

Output:

DEBUG:sonosa_app::pages::record -- Equal false
DEBUG:sonosa_app::pages::record -- Should render false

I needed to use &&, but my train of thought was "render if session changed or id changed".

Describe alternatives you've considered (Optional)
Having the programmer define when to assign rather than when not to assign let's them avoid carrying around an extra not in precious headspace.

Name is still tbd, though I agree with @jstarry:

maybe assign_if
should look to see if there is a rust api naming precedent

assign_by could also work (following the existing scheme). Suggestions are welcome!

 fn change(&mut self, props: Self::Properties) -> ShouldRender {
        self.props.assign_if(props, |a, b| {
            a.handle.state().session != b.handle.state().session || a.id != b.id
        })
    }

Questionnaire

  • I'm interested in implementing this myself but don't know where to start
  • I would like to add this feature
  • I don't have time to add this right now, but maybe later

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions