Hacker News new | ask | show | jobs
by monooso 1255 days ago
> ...they also have an `update_changeset`, which I think is an anti-pattern.

I disagree that it's an anti-pattern. I'm already making a distinction between a "create" and an "update" changeset, as these may have different validation rules.

Of course, some situations may warrant separate changesets for operations on individual fields (updating an email address, updating a password, etc.), but in practise I rarely find this to be useful.

> Please don't do this. Just create multiple reusable functions for each check.

It's worth noting that these aren't mutually exclusive approaches; we regularly use both on my current project.

1 comments

I will agree that not every situation will require multiple kinds of updates. For those situations an `update_changeset` may be considered okay. I now realize how definite my wording sounds. But I just meant that if you have multiple update operations, that should be exposed as multiple changeset functions. If you have multiple update operations but a single update_changeset function, it is possible to send the server data you did not intend to be sent together and now you are changing things that were not originally meant to be changed together. This has happened in previous projects I have worked on and now prefer the be explicit with multiple changeset functions.
I think we're in agreement here that you should create as many different changesets as needed, according to the operations you wish to support.