Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An alternative to neq_assign_by #1560

Closed
1 of 3 tasks
intendednull opened this issue Sep 15, 2020 · 0 comments · Fixed by #1961
Closed
1 of 3 tasks

An alternative to neq_assign_by #1560

intendednull opened this issue Sep 15, 2020 · 0 comments · Fixed by #1961
Labels
feature-request A feature request

Comments

@intendednull
Copy link
Contributor

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
@intendednull intendednull added the feature-request A feature request label Sep 15, 2020
@mc1098 mc1098 mentioned this issue Aug 2, 2021
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant