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

Bugfix: coalesceFindRequests should work with non native Adapter classes #7448

Merged
merged 7 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/-ember-data/testem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const customDotReporter = require('@ember-data/unpublished-test-infra/src/testem
console.log(`\n\nLaunching with ${process.env.TESTEM_CI_LAUNCHER || 'Chrome'}\n\n`);

module.exports = {
test_page: 'tests/index.html?hidepassed',
test_page: 'tests/index.html?hidepassed&nocontainer',
disable_watching: true,
reporter: customDotReporter,
launch_in_ci: [process.env.TESTEM_CI_LAUNCHER || 'Chrome'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { module, test } from 'qunit';

import JSONAPIAdapter from '@ember-data/adapter/json-api';

module('unit/adapters/json-api-test', function() {
test('coalesceFindRequests default', function(assert) {
const adapter = JSONAPIAdapter.extend();
assert.deepEqual(adapter.create().coalesceFindRequests, false, 'default result is false');
});

test('coalesceFindRequests true', function(assert) {
const adapter = JSONAPIAdapter.extend({ coalesceFindRequests: true });
assert.deepEqual(adapter.create().coalesceFindRequests, true, 'result is true');
});

test('coalesceFindRequests false', function(assert) {
const adapter = JSONAPIAdapter.extend({ coalesceFindRequests: false });
assert.deepEqual(adapter.create().coalesceFindRequests, false, 'result is false');
});

test('coalesceFindRequests class default', function(assert) {
class MyClass extends JSONAPIAdapter {}
assert.deepEqual(MyClass.create().coalesceFindRequests, false, 'default result is false');
});

test('coalesceFindRequests class true', function(assert) {
class MyClass extends JSONAPIAdapter {
coalesceFindRequests = true;
}
assert.deepEqual(MyClass.create().coalesceFindRequests, true, 'result is true');
});

test('coalesceFindRequests class false', function(assert) {
class MyClass extends JSONAPIAdapter {
coalesceFindRequests = false;
}
assert.deepEqual(MyClass.create().coalesceFindRequests, false, 'result is false');
});
});
39 changes: 39 additions & 0 deletions packages/-ember-data/tests/unit/adapters/rest-adapter/rest-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { module, test } from 'qunit';

import RESTAdapter from '@ember-data/adapter/rest';

module('unit/adapters/rest-test', function() {
test('coalesceFindRequests default', function(assert) {
const adapter = RESTAdapter.extend();
assert.deepEqual(adapter.create().coalesceFindRequests, false, 'default result is false');
});

test('coalesceFindRequests true', function(assert) {
const adapter = RESTAdapter.extend({ coalesceFindRequests: true });
assert.deepEqual(adapter.create().coalesceFindRequests, true, 'result is true');
});

test('coalesceFindRequests false', function(assert) {
const adapter = RESTAdapter.extend({ coalesceFindRequests: false });
assert.deepEqual(adapter.create().coalesceFindRequests, false, 'result is false');
});

test('coalesceFindRequests class default', function(assert) {
class MyClass extends RESTAdapter {}
assert.deepEqual(MyClass.create().coalesceFindRequests, false, 'default result is false');
});

test('coalesceFindRequests class true', function(assert) {
class MyClass extends RESTAdapter {
coalesceFindRequests = true;
}
assert.deepEqual(MyClass.create().coalesceFindRequests, true, 'result is true');
});

test('coalesceFindRequests class false', function(assert) {
class MyClass extends RESTAdapter {
coalesceFindRequests = false;
}
assert.deepEqual(MyClass.create().coalesceFindRequests, false, 'result is false');
});
});
14 changes: 13 additions & 1 deletion packages/adapter/addon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ type SnapshotRecordArray = import('@ember-data/store/-private/system/snapshot-re
@extends EmberObject
*/
export default class Adapter extends EmberObject implements MinimumAdapterInterface {
declare _coalesceFindRequests: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

WAT. I missed this discussion and I am sad. tc39/proposal-class-fields#151 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think a better alternative here may be to do this within the constructor.


/**
If you would like your adapter to use a custom serializer you can
set the `defaultSerializer` property to be the name of the custom
Expand Down Expand Up @@ -479,7 +481,17 @@ export default class Adapter extends EmberObject implements MinimumAdapterInterf
@property coalesceFindRequests
@type {boolean}
*/
coalesceFindRequests = true;
get coalesceFindRequests() {
let coalesceFindRequests = this._coalesceFindRequests;
if (typeof coalesceFindRequests === 'boolean') {
return coalesceFindRequests;
}
return (this._coalesceFindRequests = true);
}

set coalesceFindRequests(value: boolean) {
this._coalesceFindRequests = value;
}

/**
The store will call `findMany` instead of multiple `findRecord`
Expand Down
12 changes: 11 additions & 1 deletion packages/adapter/addon/json-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,17 @@ class JSONAPIAdapter extends RESTAdapter {
@property coalesceFindRequests
@type {boolean}
*/
coalesceFindRequests: boolean = false;
get coalesceFindRequests() {
let coalesceFindRequests = this._coalesceFindRequests;
if (typeof coalesceFindRequests === 'boolean') {
return coalesceFindRequests;
}
return (this._coalesceFindRequests = false);
}

set coalesceFindRequests(value: boolean) {
this._coalesceFindRequests = value;
}

findMany(store: Store, type: ShimModelClass, ids: string[], snapshots: Snapshot[]): Promise<unknown> {
let url = this.buildURL(type.modelName, ids, snapshots, 'findMany');
Expand Down
12 changes: 11 additions & 1 deletion packages/adapter/addon/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,17 @@ class RESTAdapter extends Adapter.extend(BuildURLMixin) {
@property coalesceFindRequests
@type {boolean}
*/
coalesceFindRequests: boolean = false;
get coalesceFindRequests() {
let coalesceFindRequests = this._coalesceFindRequests;
if (typeof coalesceFindRequests === 'boolean') {
return coalesceFindRequests;
}
return (this._coalesceFindRequests = false);
}

set coalesceFindRequests(value: boolean) {
this._coalesceFindRequests = value;
}

/**
Endpoint paths can be prefixed with a `namespace` by setting the namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const customDotReporter = require('@ember-data/unpublished-test-infra/src/testem
console.log(`\n\nLaunching with ${process.env.TESTEM_CI_LAUNCHER || 'Chrome'}\n\n`);

module.exports = {
test_page: 'tests/index.html?hidepassed',
test_page: 'tests/index.html?hidepassed&nocontainer',
disable_watching: true,
reporter: customDotReporter,
launch_in_ci: [process.env.TESTEM_CI_LAUNCHER || 'Chrome'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const customDotReporter = require('@ember-data/unpublished-test-infra/src/testem
console.log(`\n\nLaunching with ${process.env.TESTEM_CI_LAUNCHER || 'Chrome'}\n\n`);

module.exports = {
test_page: 'tests/index.html?hidepassed',
test_page: 'tests/index.html?hidepassed&nocontainer',
disable_watching: true,
reporter: customDotReporter,
launch_in_ci: [process.env.TESTEM_CI_LAUNCHER || 'Chrome'],
Expand Down
2 changes: 1 addition & 1 deletion packages/unpublished-fastboot-test-app/testem.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const customDotReporter = require('@ember-data/unpublished-test-infra/src/testem
console.log(`\n\nLaunching with ${process.env.TESTEM_CI_LAUNCHER || 'Chrome'}\n\n`);

module.exports = {
test_page: 'tests/index.html?hidepassed',
test_page: 'tests/index.html?hidepassed&nocontainer',
disable_watching: true,
reporter: customDotReporter,
launch_in_ci: [process.env.TESTEM_CI_LAUNCHER || 'Chrome'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (TestIE) {
}

module.exports = {
test_page: 'tests/index.html?hidepassed',
test_page: 'tests/index.html?hidepassed&nocontainer',
disable_watching: true,
reporter: customDotReporter,
launch_in_ci: TestIE ? ['IE'] : ['Chrome'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const customDotReporter = require('@ember-data/unpublished-test-infra/src/testem
console.log(`\n\nLaunching with ${process.env.TESTEM_CI_LAUNCHER || 'Chrome'}\n\n`);

module.exports = {
test_page: 'tests/index.html?hidepassed',
test_page: 'tests/index.html?hidepassed&nocontainer',
disable_watching: true,
reporter: customDotReporter,
launch_in_ci: [process.env.TESTEM_CI_LAUNCHER || 'Chrome'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const customDotReporter = require('@ember-data/unpublished-test-infra/src/testem
console.log(`\n\nLaunching with ${process.env.TESTEM_CI_LAUNCHER || 'Chrome'}\n\n`);

module.exports = {
test_page: 'tests/index.html?hidepassed',
test_page: 'tests/index.html?hidepassed&nocontainer',
disable_watching: true,
reporter: customDotReporter,
launch_in_ci: [process.env.TESTEM_CI_LAUNCHER || 'Chrome'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const customDotReporter = require('@ember-data/unpublished-test-infra/src/testem
console.log(`\n\nLaunching with ${process.env.TESTEM_CI_LAUNCHER || 'Chrome'}\n\n`);

module.exports = {
test_page: 'tests/index.html?hidepassed',
test_page: 'tests/index.html?hidepassed&nocontainer',
disable_watching: true,
reporter: customDotReporter,
launch_in_ci: [process.env.TESTEM_CI_LAUNCHER || 'Chrome'],
Expand Down
2 changes: 1 addition & 1 deletion packages/unpublished-test-infra/testem.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
test_page: 'tests/index.html?hidepassed',
test_page: 'tests/index.html?hidepassed&nocontainer',
disable_watching: true,
launch_in_ci: ['Chrome'],
launch_in_dev: ['Chrome'],
Expand Down