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

[FEAT adapterOptions] Ensure adapterOptions use is possible throughout #5627

Merged
merged 7 commits into from
Sep 13, 2018
Merged

[FEAT adapterOptions] Ensure adapterOptions use is possible throughout #5627

merged 7 commits into from
Sep 13, 2018

Conversation

nathanhammond
Copy link
Member

@nathanhammond nathanhammond commented Sep 10, 2018

Addressing this comment: #3700 (comment)

  • Tests (@runspired asked me to split those from the actual code to ease possible backporting.)
  • Docs

@nathanhammond nathanhammond changed the title [WIP] Feed options through. Feed options through. Sep 10, 2018
@nathanhammond
Copy link
Member Author

nathanhammond commented Sep 10, 2018

An external demo of this appearing to work can be found here:
nathanhammond/adapter-options@8decfd7#diff-2168f026d657db1526ae92392f844a3fR8

@nathanhammond

This comment has been minimized.

@nathanhammond
Copy link
Member Author

The two test-related commits are done with different styles.

  • HasManyReference cloned the tests and tested only the adapterOptions passing.
  • BelongsToReference added in an assertion to the tests which already covered the code path.

Let me know which pattern you prefer, I can use it for both.

@runspired
Copy link
Contributor

This is also implementable in user-space if the user isn't afraid of tweaking the computed returned from hasMany or belongsTo.

The entire original meta the user defines on the model is accessible via accessing the meta via relationshipsByName.

Copy link
Contributor

@runspired runspired left a comment

Choose a reason for hiding this comment

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

Overall this is a good direction to take. Let's not add support for specifying adapterOptions on relationships, but everything else looks good with the fixes I've mentioned.

@@ -231,17 +231,17 @@ export default class BelongsToRelationship extends Relationship {
Other calls must conform to the typical expectations, for instance, sync relationships
expect that their data is already loaded.
*/
getData(isForcedReload = false) {
getData(options = {}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

let's leave isForcedReload as the second argument here, as it should not be leaked to end users.

Copy link
Contributor

Choose a reason for hiding this comment

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

options does not need a defaultValue

@@ -270,7 +270,7 @@ export default class BelongsToRelationship extends Relationship {
"' with id " +
this.internalModel.id +
' but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async (`DS.belongsTo({ async: true })`)',
record === null || !record.get('isEmpty') || isForcedReload
record === null || !record.get('isEmpty') || options.reload === true
Copy link
Contributor

Choose a reason for hiding this comment

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

let's keep isForcedReload

@@ -344,17 +344,17 @@ export default class ManyRelationship extends Relationship {
});
}

getData(isForcedReload = false) {
getData(options = {}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same as for belongsTo, make isForcedReload the second arg.

Copy link
Contributor

Choose a reason for hiding this comment

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

also, options does not need to have a default value

@@ -379,7 +379,7 @@ export default class ManyRelationship extends Relationship {
}' with id ${
this.internalModel.id
} but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async (\`DS.hasMany({ async: true })\`)`,
this.allInverseRecordsAreLoaded || isForcedReload
this.allInverseRecordsAreLoaded || options.reload === true
Copy link
Contributor

Choose a reason for hiding this comment

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

same as belongsTo, let's keep isForcedReload here

@@ -554,7 +554,8 @@ export default class Relationship {

this.setHasFailedLoadAttempt(false);
this.setShouldForceReload(true);
this.getData(true);
options.reload = true;
this.getData(options);
Copy link
Contributor

Choose a reason for hiding this comment

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

let's make this this.getData(options, true). We don't want to leak the ability to add reload as an option to calls to load, and the reason for this flag is to enforce that only this specific call to getData is considered a reload.

reload() {
return this.hasManyRelationship.reload();
reload(options = {}) {
options.reload = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

we can delete the default value assignment and the options.reload = true assignment

@@ -545,7 +545,7 @@ export default class Relationship {
this.setRelationshipIsStale(true);
}

reload() {
reload(options = {}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

options does not need a default value here

addon/-legacy-private/system/store.js Outdated Show resolved Hide resolved
addon/-legacy-private/system/store.js Outdated Show resolved Hide resolved
addon/-record-data-private/system/store.js Outdated Show resolved Hide resolved
@nathanhammond
Copy link
Member Author

The only remaining things are related to WeakMap. I believe that the code I have is actually correct in order to work in both Ember 2.X and 3.X.

@nathanhammond nathanhammond mentioned this pull request Sep 12, 2018
Copy link
Contributor

@runspired runspired left a comment

Choose a reason for hiding this comment

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

I'm ok with it as is but I think the docs could be slightly more clear (see comment)

@@ -395,11 +417,22 @@ export default class BelongsToReference extends Reference {
});
```

You may also pass in an options object whose properties will be
fed forward. This enables you to pass `adapterOptions` into a
a reference. A full example can be found in the `load` method.
Copy link
Contributor

Choose a reason for hiding this comment

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

" into the request given to the adapter via the reference" might be more clear in these docs.

@runspired runspired changed the title Feed options through. [FEAT adapterOptions] Ensure adapterOptions use is possible throughout Sep 12, 2018
@runspired runspired merged commit 71b3d90 into emberjs:master Sep 13, 2018
@nathanhammond nathanhammond deleted the feed-options-through branch September 14, 2018 22:46
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.

2 participants