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

[DEPRECATION RFC ember-data] deprecate errors changing record state #384

Conversation

runspired
Copy link
Contributor

@sandstrom
Copy link
Contributor

sandstrom commented Oct 11, 2018

Great suggestion! 🏅

How about adding these methods on the model itself, i.e. model.addErrors etc?

To me it would feel more consistent with the current API, for example accessing relationships are via model.belongsTo (it's not model.relationships.belongsTo).

(model.errors would still exist, but would be read-only, apart from the methods that already are on there, but they will probably be deprecated at some point, I assume)

## Summary

Deprecates the `add` `remove` and `clear` methods of `DS.Errors` in favor of `addError`
`removeError` and `clearErrors`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses the singular whereas the design uses the plural.

@hjdivad
Copy link
Member

hjdivad commented Oct 17, 2018

@sandstrom i'd rather not scope creep into changing the API itself; the goal of this rfc is to follow-through on the (now quite old) deprecation and make it actionable for users.


On the question of moving the API to the model, I'd prefer to avoid adding more API surface area to a class users already subclass a lot.

To me it would feel more consistent with the current API, for example accessing relationships are via model.belongsTo (it's not model.relationships.belongsTo).

This is a good point about consistency although i think the safer way to consolidate this would be to move belongsTo &c. to record.relationships rather than to have a larger API on DS.Model.

@sandstrom
Copy link
Contributor

sandstrom commented Oct 18, 2018

@hjdivad Alright, you have a point regarding scope creep and the downside of adding more methods to model.

Another concern is that the method names model.errors.addErrors feels verbose (this is also mentioned in the RFC "The new method names may feel unnecessarily verbose"). Moving the API would allow less verbose method names, but since we're not going down that path, how about another solution:

Add a flag somewhere (suggestions below) and when that flag is enabled, we use the new API. That way we can keep the cleaner api model.errors.add (and it's also a better fit among the existing methods, e.g. model.errors.has).

Places we could add a flag

  1. In the global config/environment.js
  2. On the DS.Errors object (reopen and use isNewErrorMethodsAPI: true (similar to isNewSerializerAPI:true[1]).
  3. On the methods themselves, add a third argument for API opt-in errors.add(…, …, true) and in 3.9 we'd make the new API default and drop the third argument.

(I'd prefer (3), but either would work)

[1] https://www.emberjs.com/blog/2015/06/18/ember-data-1-13-released.html#toc_upgrade-guide

@hjdivad @runspired What's your thoughts?

@hjdivad
Copy link
Member

hjdivad commented Oct 18, 2018

@sandstrom I do like the idea of a flag rather than moving the methods. But the downside is the flag is all or nothing: in a large codebase it can be important to be able to migrate deprecations incrementally.

Adding a flag to the call site does allow for incremental migration and from my point of view is roughly equivalent to making a new method. I don't have a strong opinion between the two choices. As i see it, each has a slight edge over the other:

  1. Adding a flag creates more work for people migrating as they add the flag and then later should drop it for cleanup once the deprecation is removed
  2. But creating less pleasant method names impacts new projects

I could go either way (although again I'm not a fan of a global flag due to the impact on incremental conversion).

@runspired @dgeb ?

@runspired
Copy link
Contributor Author

runspired commented Oct 19, 2018

@sandstrom @hjdivad

I agree with David on being opposed to a global flag. I am additionally against the local flag and in favor of the changes here as proposed for three reasons. I list them here in order of importance:

Assuming a local opt-in API like the following:

add(member: string, message: string|string[], optIntoFuture: boolean)
  1. My largest complaint with this syntax is that it leads to a double deprecation lifecyle.

Not only would users have to opt-in at each call site to eliminate the deprecation and ensure their code did not break, but once the deprecation completed they would need to receive a new deprecation telling them to drop the third argument.

  1. & 3. My second and third complaints with this syntax both pertain to believing that the syntax today is misleading. add remove and clear are evocative of the set delete and clear APIs of Map and WeakMap. Given their behaviors and the nature of the data structure (a mapping of errors), one might expect the APIs to behave similarly, but they don't.

set(key, value) doesn't differentiate between value being an array vs not, but add/addErrors does.

delete(key) doesn't leave behind an empty array, but remove/removeErrors does. Also note, that while you can add a single error to an attribute, remove removes all of them, not just the one.

clear is the only API of the three that is semantically the same.

Both because I dislike the confusion with the mechanics of true Map classes, and because of the differences in function signatures, the names of the existing APIs make me uneasy.

@sandstrom
Copy link
Contributor

sandstrom commented Oct 19, 2018

@runspired Good arguments!

  1. In my opinion we could skip the second deprecation, since the third argument will be ignored. But I understand if you'd like to do it "the right way" and make it a two-phase thing.

  2. Not really sold on the confusion risk with map, I think people will understand that add on different objects will have different effects.

That said, this is only the voice of one person and if you, as the RFC champion, disagree I think we should go ahead with this PR anyway. I've declared my suggestions above and they've been discussed, which is the important part — if none of them end up in the final version (i.e. discarded) that's totally fine! 😄

So even though I have some concerns (1 & 2) I'm still overall positive to this RFC! 🏅

tylerturdenpants added a commit to emberjs/website that referenced this pull request Oct 19, 2018
Ideas, feel free to add to list or claim:
- [ ] ```I've been getting a lot of questions about how tree-shaking is coming along. I would be willing to train anyone that wants to help on what's already done and what still needs to be done. Disclaimer: It's a lot of work! #emberjs #EmberFest``` https://twitter.com/kellyselden/status/1050717338595745792
- [ ] Include summary from pixelhandler (and cc him) #issue-triage team: https://discordapp.com/channels/480462759797063690/480523776845414412/500377829452546058
- [x] From jenweber on #support-ember-times: Another times topic: emberjs/ember.js#16910 I would summarize as, "ember.js has an addition to the test suite to help with API documentation! In the past, you might have noticed that a small number of methods  had missing docs. When code gets moved around in ember.js, such as putting functions in their own modules, it's easy to make mistakes that impact the documentation parser. This test builds the docs and checks them for unintentional changes. Thanks <link to ed> for the test and to everyone who helped fix missing docs over the years." Todd Jordan did the majority of the fixes when things got dropped, I think. Hard to say for sure 🔏 @kennethlarsen 
- [x] emberjs/rfcs#384 (:lock: @jessica-jordan)
- [x] emberjs/rfcs#386 (:lock: @jessica-jordan)
- [ ] emberjs/rfcs#387 (:lock: @jessica-jordan)
- [x] emberjs/rfcs#388 (:lock: @Alonski)
- [ ] emberjs/rfcs#389
- [x] EmberConf brainstorming session date, if confirmed (:lock: @amyrlam)
- [ ] Hacktoberfest roundup?
- [ ] Check https://github.com/jessica-jordan/whats-new-in-emberland
- [x] [ember-self-focused](https://engineering.linkedin.com/blog/2018/10/making-ember-applications--ui-transitions-screen-reader-friendly) (🔒 @chrisrng )
- [ ] ...

Ideas we are waiting on:
- [ ] EmberCamp talks, deep dive? http://embercamp.com/ and https://github.com/ember-chicago/ember-camp-2018-notes ... Maybe we wait for the talk videos to be published? Keep an eye on #ember-camp in Discord. not out yet
- [ ] GraphQL with Ember? https://emberfest.eu/schedule/#rocky-neurock Or maybe we can reach out to them for a post-EmberFest writeup? See also the blog post: https://medium.com/kloeckner-i/ember-and-graphql-8aa15f7a2554
@hjdivad
Copy link
Member

hjdivad commented Oct 25, 2018

Moving this to final comment period. We'll aim to merge next week, barring any additional concerns.

Thanks very much @sandstrom @lindyhopchris for taking the time to review and give feedback. 🎉

@runspired runspired added the FCP to close The core-team that owns this RFC has moved that this RFC be closed. label Dec 3, 2018
@runspired
Copy link
Contributor Author

We landed a different approach to resolving this due to a desire to reconsider how we propagate errors through the system more holistically.

@runspired runspired closed this Jan 4, 2019
@runspired runspired deleted the ember-data-errors-manipulation-deprecation branch January 4, 2019 23:12
@runspired runspired restored the ember-data-errors-manipulation-deprecation branch January 4, 2019 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FCP to close The core-team that owns this RFC has moved that this RFC be closed. T-deprecation T-ember-data RFCs that impact the ember-data library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants