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

make shouldSerializeHasMany public #2494 #4279

Merged
merged 1 commit into from
Jun 2, 2016
Merged

make shouldSerializeHasMany public #2494 #4279

merged 1 commit into from
Jun 2, 2016

Conversation

jondayton
Copy link
Contributor

From #2494

@jondayton jondayton changed the title [FEATURE] make shouldSerializeHasMany public #2494 make shouldSerializeHasMany public #2494 Mar 28, 2016
@bmac
Copy link
Member

bmac commented Mar 28, 2016

Thanks @jondayton. Since this change is going to add a new method to Ember Data's public api would you mind wrapping it in a feature flag?

@jondayton
Copy link
Contributor Author

@bmac no problem. In that case, since it's removing the private api and adding the public, it may be better to leave the private method and add a public reference under the feature flag

@bmac
Copy link
Member

bmac commented Mar 28, 2016

Good plan @jondayton.

@jondayton
Copy link
Contributor Author

@bmac added a deprecation warning + test. I've been looking at it again and making this a feature flag will require either warnings in several places or a third private method __shouldSerializeHasMany which would sit in the middle to handle the deprecation warning and flag. This seems like a bit of overkill for changing the name of a method, as functionality hasn't really changed, it's just been renamed.

var relationshipType = snapshot.type.determineRelationshipType(relationship, this.store);
shouldSerializeHasMany(snapshot, key, relationship) {
if (this._shouldSerializeHasMany) {
deprecate('The private method `_shouldSerializeHasMany` has been deprecated. Please use public method `shouldSerializeHasMany`.', false, {
Copy link
Member

@fivetanley fivetanley May 11, 2016

Choose a reason for hiding this comment

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

I think "The private method _shouldSerializeHasMany has been promoted to the public API. Please remove the underscore to use the public shouldSerializeHasMany method instead." might be a bit better description of what's going on.

@igorT
Copy link
Member

igorT commented May 11, 2016

Needs a feature flag, we should also make a shouldSerializeBelongsTo as well

@jondayton
Copy link
Contributor Author

sounds good. I'll take a pass at it tonight.

@bmac
Copy link
Member

bmac commented May 23, 2016

ping @jondayton do you have time to update this pr?

@jondayton
Copy link
Contributor Author

@bmac updated the pr with a feature flag.

@jondayton
Copy link
Contributor Author

logic goes something like this

if feature flag enabled ? use public method : use private method
if private override exists throw a deprecation warning

technically we could break people who are overriding the private method without a deprecation warning, but I do think it's better to throw the warning.

I used shouldSerializeHasMany for the public name, _shouldSerializeHasMany for the private name that is currently being overridden, and __shouldSerializeHasMany for the new private method to use if the feature flag is not enabled

@bmac
Copy link
Member

bmac commented May 26, 2016

Thanks @jondayton. This looks good. Do you mind rebasing this one last time and I will merge it?

@@ -571,8 +571,9 @@ const JSONAPISerializer = JSONSerializer.extend({
*/
serializeHasMany(snapshot, json, relationship) {
var key = relationship.key;
var shouldSerializeHasMany = isEnabled('ds-check-should-serialize-relationships') ? 'shouldSerializeHasMany' : '__shouldSerializeHasMany';
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately this doesn't work so the feature is correctly stripped in production. You need to change this to something like:

var shouldSerializeHasMany = '__shouldSerializeHasMany';
if (isEnabled("ds-check-should-serialize-relationships")) {
  shouldSerializeHasMany = 'shouldSerializeHasMany';
}

@bmac
Copy link
Member

bmac commented May 26, 2016

Sorry @jondayton. @pangratz reminded me that we've been using another pattern for detecting deprecated functions. I added a few comments.

@jondayton
Copy link
Contributor Author

@bmac was out of town for the long weekend but should have some time tonight.

@jondayton
Copy link
Contributor Author

@bmac took another pass at it.

@bmac bmac merged commit e4758d3 into emberjs:master Jun 2, 2016
@bmac
Copy link
Member

bmac commented Jun 2, 2016

Thanks @jondayton

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants