From bc0051b4782040af3a39fd3c4ee833dde160e814 Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Fri, 13 Nov 2015 00:56:51 +0000 Subject: [PATCH 01/24] [DOC fix] Adds missing space before list --- addon/serializers/embedded-records-mixin.js | 1 + 1 file changed, 1 insertion(+) diff --git a/addon/serializers/embedded-records-mixin.js b/addon/serializers/embedded-records-mixin.js index 9f5a610d2c8..8cb8f4f6d71 100644 --- a/addon/serializers/embedded-records-mixin.js +++ b/addon/serializers/embedded-records-mixin.js @@ -85,6 +85,7 @@ var camelize = Ember.String.camelize; to modify it to fit your specific needs.** For example review the docs for each method of this mixin: + * [normalize](/api/data/classes/DS.EmbeddedRecordsMixin.html#method_normalize) * [serializeBelongsTo](/api/data/classes/DS.EmbeddedRecordsMixin.html#method_serializeBelongsTo) * [serializeHasMany](/api/data/classes/DS.EmbeddedRecordsMixin.html#method_serializeHasMany) From df81e19edcb8813f54d5f35378d0e47d53f3c580 Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Fri, 13 Nov 2015 09:49:25 -0500 Subject: [PATCH 02/24] [CLEANUP] Clean up adapter/find-all-test.js * Use ES6 `() =>` where applicable * Remove unnecessary `Ember.` and `Ember.RSVP` prefixes * Remove ignored closure parameters * One-line adapater overrides when possible --- tests/integration/adapter/find-all-test.js | 67 +++++++++++----------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/tests/integration/adapter/find-all-test.js b/tests/integration/adapter/find-all-test.js index d7ea583c381..97320ad3e6f 100644 --- a/tests/integration/adapter/find-all-test.js +++ b/tests/integration/adapter/find-all-test.js @@ -1,23 +1,22 @@ import {createStore} from 'dummy/tests/helpers/store'; import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; - import {module, test} from 'qunit'; - import DS from 'ember-data'; -var get = Ember.get; -var Person, store, allRecords; -var run = Ember.run; -var env; +const { attr } = DS; +const { get, run } = Ember; +const { resolve, reject } = Ember.RSVP; + +let Person, store, allRecords, env; module("integration/adapter/find_all - Finding All Records of a Type", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({ - updatedAt: DS.attr('string'), - name: DS.attr('string'), - firstName: DS.attr('string'), - lastName: DS.attr('string') + updatedAt: attr('string'), + name: attr('string'), + firstName: attr('string'), + lastName: attr('string') }); allRecords = null; @@ -28,68 +27,68 @@ module("integration/adapter/find_all - Finding All Records of a Type", { store = env.store; }, - afterEach: function() { - run(function() { + afterEach() { + run(() => { if (allRecords) { allRecords.destroy(); } store.destroy(); }); } }); -test("When all records for a type are requested, the store should call the adapter's `findAll` method.", function(assert) { +test("When all records for a type are requested, the store should call the adapter's `findAll` method.", (assert) => { assert.expect(5); env.registry.register('adapter:person', DS.Adapter.extend({ - findAll: function(store, type, since) { + findAll() { // this will get called twice assert.ok(true, "the adapter's findAll method should be invoked"); - return Ember.RSVP.resolve([{ id: 1, name: "Braaaahm Dale" }]); + return resolve([{ id: 1, name: "Braaaahm Dale" }]); } })); - var allRecords; + let allRecords; - run(function() { - store.findAll('person').then(function(all) { + run(() => { + store.findAll('person').then((all) => { allRecords = all; assert.equal(get(all, 'length'), 1, "the record array's length is 1 after a record is loaded into it"); assert.equal(all.objectAt(0).get('name'), "Braaaahm Dale", "the first item in the record array is Braaaahm Dale"); }); }); - run(function() { - store.findAll('person').then(function(all) { + run(() => { + store.findAll('person').then((all) => { // Only one record array per type should ever be created (identity map) assert.strictEqual(allRecords, all, "the same record array is returned every time all records of a type are requested"); }); }); }); -test("When all records for a type are requested, a rejection should reject the promise", function(assert) { +test("When all records for a type are requested, a rejection should reject the promise", (assert) => { assert.expect(5); - var count = 0; + let count = 0; env.registry.register('adapter:person', DS.Adapter.extend({ - findAll: function(store, type, since) { + findAll() { // this will get called twice assert.ok(true, "the adapter's findAll method should be invoked"); if (count++ === 0) { - return Ember.RSVP.reject(); + return reject(); } else { - return Ember.RSVP.resolve([{ id: 1, name: "Braaaahm Dale" }]); + return resolve([{ id: 1, name: "Braaaahm Dale" }]); } } })); - var allRecords; + let allRecords; - run(function() { - store.findAll('person').then(null, function() { + run(() => { + store.findAll('person').then(null, () => { assert.ok(true, "The rejection should get here"); return store.findAll('person'); - }).then(function(all) { + }).then((all) => { allRecords = all; assert.equal(get(all, 'length'), 1, "the record array's length is 1 after a record is loaded into it"); assert.equal(all.objectAt(0).get('name'), "Braaaahm Dale", "the first item in the record array is Braaaahm Dale"); @@ -97,14 +96,14 @@ test("When all records for a type are requested, a rejection should reject the p }); }); -test("When all records for a type are requested, records that are already loaded should be returned immediately.", function(assert) { +test("When all records for a type are requested, records that are already loaded should be returned immediately.", (assert) => { assert.expect(3); store = createStore({ adapter: DS.Adapter.extend(), person: Person }); - run(function() { + run(() => { // Load a record from the server store.push({ data: { @@ -126,7 +125,7 @@ test("When all records for a type are requested, records that are already loaded assert.equal(allRecords.objectAt(1).get('name'), "Alex MacCaw", "the second item in the record array is Alex MacCaw"); }); -test("When all records for a type are requested, records that are created on the client should be added to the record array.", function(assert) { +test("When all records for a type are requested, records that are created on the client should be added to the record array.", (assert) => { assert.expect(3); store = createStore({ @@ -138,7 +137,7 @@ test("When all records for a type are requested, records that are created on the assert.equal(get(allRecords, 'length'), 0, "precond - the record array's length is zero before any records are loaded"); - run(function() { + run(() => { store.createRecord('person', { name: "Carsten Nielsen" }); }); From 2472b3a2bad15658fe42acf4800383bf1b02f1fc Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Fri, 13 Nov 2015 09:40:56 -0500 Subject: [PATCH 03/24] [CLEANUP] `tests/integration/adapter/find-test.js` * Use ES6 `() =>` where applicable * Remove unnecessary `Ember.` and `Ember.RSVP` prefixes * Remove ignored closure parameters * One-line adapater overrides when possible --- tests/integration/adapter/find-test.js | 78 ++++++++++++-------------- 1 file changed, 35 insertions(+), 43 deletions(-) diff --git a/tests/integration/adapter/find-test.js b/tests/integration/adapter/find-test.js index 04608c5c507..9d289600db7 100644 --- a/tests/integration/adapter/find-test.js +++ b/tests/integration/adapter/find-test.js @@ -1,20 +1,21 @@ import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; - import {module, test} from 'qunit'; - import DS from 'ember-data'; -var Person, store, env; -var run = Ember.run; +const { run } = Ember; +const { attr } = DS; +const { reject } = Ember.RSVP; + +let Person, store, env; module("integration/adapter/find - Finding Records", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({ - updatedAt: DS.attr('string'), - name: DS.attr('string'), - firstName: DS.attr('string'), - lastName: DS.attr('string') + updatedAt: attr('string'), + name: attr('string'), + firstName: attr('string'), + lastName: attr('string') }); env = setupStore({ @@ -23,28 +24,28 @@ module("integration/adapter/find - Finding Records", { store = env.store; }, - afterEach: function() { + afterEach() { run(store, 'destroy'); } }); -test("It raises an assertion when `undefined` is passed as id (#1705)", function(assert) { - assert.expectAssertion(function() { +test("It raises an assertion when `undefined` is passed as id (#1705)", (assert) => { + assert.expectAssertion(() => { store.find('person', undefined); }, "You cannot pass `undefined` as id to the store's find method"); - assert.expectAssertion(function() { + assert.expectAssertion(() => { store.find('person', null); }, "You cannot pass `null` as id to the store's find method"); }); -test("When a single record is requested, the adapter's find method should be called unless it's loaded.", function(assert) { +test("When a single record is requested, the adapter's find method should be called unless it's loaded.", (assert) => { assert.expect(2); var count = 0; env.registry.register('adapter:person', DS.Adapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(_, type) { assert.equal(type, Person, "the find method is called with the correct type"); assert.equal(count, 0, "the find method is only called once"); @@ -53,47 +54,45 @@ test("When a single record is requested, the adapter's find method should be cal } })); - run(function() { + run(() => { store.findRecord('person', 1); store.findRecord('person', 1); }); }); -test("When a single record is requested multiple times, all .find() calls are resolved after the promise is resolved", function(assert) { +test("When a single record is requested multiple times, all .find() calls are resolved after the promise is resolved", (assert) => { var deferred = Ember.RSVP.defer(); env.registry.register('adapter:person', DS.Adapter.extend({ - findRecord: function(store, type, id, snapshot) { - return deferred.promise; - } + findRecord: () => deferred.promise })); - run(function() { + run(() => { store.findRecord('person', 1).then(assert.wait(function(person) { assert.equal(person.get('id'), "1"); assert.equal(person.get('name'), "Braaaahm Dale"); let done = assert.async(); - deferred.promise.then(function(value) { + deferred.promise.then(() => { assert.ok(true, 'expected deferred.promise to fulfill'); done(); - }, function(reason) { + }, () => { assert.ok(false, 'expected deferred.promise to fulfill, but rejected'); done(); }); })); }); - run(function() { - store.findRecord('person', 1).then(assert.wait(function(post) { + run(() => { + store.findRecord('person', 1).then(assert.wait((post) => { assert.equal(post.get('id'), "1"); assert.equal(post.get('name'), "Braaaahm Dale"); let done = assert.async(); - deferred.promise.then(function(value) { + deferred.promise.then(() => { assert.ok(true, 'expected deferred.promise to fulfill'); done(); - }, function(reason) { + }, () => { assert.ok(false, 'expected deferred.promise to fulfill, but rejected'); done(); }); @@ -101,39 +100,32 @@ test("When a single record is requested multiple times, all .find() calls are re })); }); - Ember.run(function() { - deferred.resolve({ id: 1, name: "Braaaahm Dale" }); - }); + run(() => deferred.resolve({ id: 1, name: "Braaaahm Dale" })); }); -test("When a single record is requested, and the promise is rejected, .find() is rejected.", function(assert) { +test("When a single record is requested, and the promise is rejected, .find() is rejected.", (assert) => { env.registry.register('adapter:person', DS.Adapter.extend({ - findRecord: function(store, type, id, snapshot) { - return Ember.RSVP.reject(); - } + findRecord: () => reject() })); - run(function() { - store.findRecord('person', 1).then(null, assert.wait(function(reason) { + run(() => { + store.findRecord('person', 1).then(null, assert.wait(() => { assert.ok(true, "The rejection handler was called"); })); }); }); -test("When a single record is requested, and the promise is rejected, the record should be unloaded.", function(assert) { +test("When a single record is requested, and the promise is rejected, the record should be unloaded.", (assert) => { assert.expect(2); env.registry.register('adapter:person', DS.Adapter.extend({ - findRecord: function(store, type, id, snapshot) { - return Ember.RSVP.reject(); - } + findRecord: () => reject() })); - run(function() { - store.findRecord('person', 1).then(null, assert.wait(function(reason) { + run(() => { + store.findRecord('person', 1).then(null, assert.wait((reason) => { assert.ok(true, "The rejection handler was called"); assert.ok(!store.hasRecordForId('person', 1), "The record has been unloaded"); })); }); - }); From a51bea910065100fb610957b8df2bc8703d4e33c Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Tue, 10 Nov 2015 12:11:25 -0500 Subject: [PATCH 04/24] `Store._find` asserts `adapterPayload` not empty Currently, [Store._find][find] only asserts that the `adapterPayload` is non-null (i.e. `{}` is a valid payload). This commit forces the `adapterPayload` to be non-empty. When TDDing with Mirage, `adapterPayload` is often `{}`, which sneaks through the asserts and ends up as a non-descriptive: ``` Assertion Failed: You must include an 'id' for undefined in an object passed to 'push' ``` Which is triggered in [Store._pushInternalModel][_pushInternalModel], which is a few method invocations away from the source of the issue. [_pushInternalModel]: https://github.com/emberjs/data/blob/f1ccad8ab9356dd51f44d63585c27d8bb4ec9c3a/packages/ember-data/lib/system/store.js#L1709 [find]: https://github.com/emberjs/data/blob/f1ccad8ab9356dd51f44d63585c27d8bb4ec9c3a/packages/ember-data/lib/system/store/finders.js#L27 --- addon/system/store/finders.js | 14 ++++++++++- tests/integration/adapter/find-all-test.js | 10 ++++++++ tests/integration/adapter/find-test.js | 24 +++++++++++++++++++ .../store/json-api-validation-test.js | 8 +++---- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/addon/system/store/finders.js b/addon/system/store/finders.js index f386e8ebd48..e9fb4530dd3 100644 --- a/addon/system/store/finders.js +++ b/addon/system/store/finders.js @@ -14,6 +14,14 @@ import { var Promise = Ember.RSVP.Promise; +function payloadIsNotBlank(adapterPayload) { + if (Ember.isArray(adapterPayload)) { + return true; + } else { + return Object.keys(adapterPayload || {}).length; + } +} + export function _find(adapter, store, typeClass, id, internalModel, options) { var snapshot = internalModel.createSnapshot(options); var promise = adapter.findRecord(store, typeClass, id, snapshot); @@ -24,7 +32,7 @@ export function _find(adapter, store, typeClass, id, internalModel, options) { promise = _guard(promise, _bind(_objectIsAlive, store)); return promise.then(function(adapterPayload) { - Ember.assert("You made a request for a " + typeClass.typeClassKey + " with id " + id + ", but the adapter's response did not have any data", adapterPayload); + Ember.assert("You made a `find` request for a " + typeClass.typeClassKey + " with id " + id + ", but the adapter's response did not have any data", payloadIsNotBlank(adapterPayload)); return store._adapterRun(function() { var payload = normalizeResponseHelper(serializer, store, typeClass, adapterPayload, id, 'findRecord'); //TODO Optimize @@ -56,6 +64,7 @@ export function _findMany(adapter, store, typeClass, ids, internalModels) { promise = _guard(promise, _bind(_objectIsAlive, store)); return promise.then(function(adapterPayload) { + Ember.assert("You made a `findMany` request for a " + typeClass.typeClassKey + " with ids " + ids + ", but the adapter's response did not have any data", payloadIsNotBlank(adapterPayload)); return store._adapterRun(function() { var payload = normalizeResponseHelper(serializer, store, typeClass, adapterPayload, null, 'findMany'); //TODO Optimize, no need to materialize here @@ -77,6 +86,7 @@ export function _findHasMany(adapter, store, internalModel, link, relationship) promise = _guard(promise, _bind(_objectIsAlive, internalModel)); return promise.then(function(adapterPayload) { + Ember.assert("You made a `findHasMany` request for a " + internalModel.modelName + "'s `" + relationship.key + "` relationship, using link " + link + ", but the adapter's response did not have any data", payloadIsNotBlank(adapterPayload)); return store._adapterRun(function() { var payload = normalizeResponseHelper(serializer, store, typeClass, adapterPayload, null, 'findHasMany'); //TODO Use a non record creating push @@ -126,6 +136,7 @@ export function _findAll(adapter, store, typeClass, sinceToken, options) { promise = _guard(promise, _bind(_objectIsAlive, store)); return promise.then(function(adapterPayload) { + Ember.assert("You made a `findAll` request for " + typeClass.typeClassKey + "records, but the adapter's response did not have any data", payloadIsNotBlank(adapterPayload)); store._adapterRun(function() { var payload = normalizeResponseHelper(serializer, store, typeClass, adapterPayload, null, 'findAll'); //TODO Optimize @@ -172,6 +183,7 @@ export function _queryRecord(adapter, store, typeClass, query) { promise = _guard(promise, _bind(_objectIsAlive, store)); return promise.then(function(adapterPayload) { + Ember.assert("You made a `queryRecord` request for " + typeClass.typeClassKey + "records, with query `" + query + "`, but the adapter's response did not have any data", payloadIsNotBlank(adapterPayload)); var record; store._adapterRun(function() { var payload = normalizeResponseHelper(serializer, store, typeClass, adapterPayload, null, 'queryRecord'); diff --git a/tests/integration/adapter/find-all-test.js b/tests/integration/adapter/find-all-test.js index d7ea583c381..37c5716e86f 100644 --- a/tests/integration/adapter/find-all-test.js +++ b/tests/integration/adapter/find-all-test.js @@ -145,3 +145,13 @@ test("When all records for a type are requested, records that are created on the assert.equal(get(allRecords, 'length'), 1, "the record array's length is 1"); assert.equal(allRecords.objectAt(0).get('name'), "Carsten Nielsen", "the first item in the record array is Carsten Nielsen"); }); + +test('When all records are requested, assert the payload is not blank', (assert) => { + env.registry.register('adapter:person', DS.Adapter.extend({ + findAll: () => Ember.RSVP.resolve({}) + })); + + assert.expectAssertion(() => { + run(() => store.findAll('person')); + }, /the adapter's response did not have any data/); +}); diff --git a/tests/integration/adapter/find-test.js b/tests/integration/adapter/find-test.js index 04608c5c507..36f7fb3100e 100644 --- a/tests/integration/adapter/find-test.js +++ b/tests/integration/adapter/find-test.js @@ -137,3 +137,27 @@ test("When a single record is requested, and the promise is rejected, the record }); }); + +test('When a single record is requested, and the payload is blank', (assert) => { + env.registry.register('adapter:person', DS.Adapter.extend({ + findRecord: () => Ember.RSVP.resolve({}) + })); + + assert.expectAssertion(() => { + run(() => store.find('person', 'the-id')); + }, /the adapter's response did not have any data/); +}); + +test('When multiple records are requested, and the payload is blank', (assert) => { + env.registry.register('adapter:person', DS.Adapter.extend({ + coalesceFindRequests: true, + findMany: () => Ember.RSVP.resolve({}) + })); + + assert.expectAssertion(() => { + run(() => { + store.findRecord('person', '1'); + store.findRecord('person', '2'); + }); + }, /the adapter's response did not have any data/); +}); diff --git a/tests/integration/store/json-api-validation-test.js b/tests/integration/store/json-api-validation-test.js index fc96a46a16a..e53ab3708d4 100644 --- a/tests/integration/store/json-api-validation-test.js +++ b/tests/integration/store/json-api-validation-test.js @@ -34,7 +34,7 @@ test("when normalizeResponse returns undefined (or doesn't return), throws an er env.registry.register('adapter:person', DS.Adapter.extend({ findRecord() { - return Ember.RSVP.resolve({}); + return Ember.RSVP.resolve({ data: {} }); } })); @@ -53,7 +53,7 @@ test("when normalizeResponse returns null, throws an error", function(assert) { env.registry.register('adapter:person', DS.Adapter.extend({ findRecord() { - return Ember.RSVP.resolve({}); + return Ember.RSVP.resolve({ data: {} }); } })); @@ -73,7 +73,7 @@ test("when normalizeResponse returns an empty object, throws an error", function env.registry.register('adapter:person', DS.Adapter.extend({ findRecord() { - return Ember.RSVP.resolve({}); + return Ember.RSVP.resolve({ data: {} }); } })); @@ -97,7 +97,7 @@ test("when normalizeResponse returns a document with both data and errors, throw env.registry.register('adapter:person', DS.Adapter.extend({ findRecord() { - return Ember.RSVP.resolve({}); + return Ember.RSVP.resolve({ data: {} }); } })); From f6e675d5552f67f9513588d34afc92aafd99c1fb Mon Sep 17 00:00:00 2001 From: Stanley Stuart Date: Fri, 13 Nov 2015 10:22:11 -0600 Subject: [PATCH 05/24] upgrade node to 4 on CI --- .travis.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 782589970d8..e8dcd45020a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: node_js sudo: required dist: trusty node_js: - - "0.10" + - "4.2" before_install: - "npm config set spin false" - "npm install -g npm@^2" diff --git a/appveyor.yml b/appveyor.yml index eb67ab5838a..c3eb24b5586 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,7 +7,7 @@ init: # Test against these versions of Node.js. environment: matrix: - - nodejs_version: "0.12" + - nodejs_version: "4.2" # Install scripts. (runs after repo cloning) install: From 434527d0155acc7549f90a17aa469f0451003671 Mon Sep 17 00:00:00 2001 From: Stanley Stuart Date: Fri, 13 Nov 2015 10:38:00 -0600 Subject: [PATCH 06/24] don't run build on Appveyor due to slow --- appveyor.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index c3eb24b5586..bdbf7dbd759 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -29,7 +29,6 @@ install: test_script: # Output useful info for debugging. - npm version - - npm run build - cmd: npm run test # Don't actually build. From 90cb66bf26a63ec07a78f61cce2831c6a91fb3aa Mon Sep 17 00:00:00 2001 From: Stanley Stuart Date: Sat, 14 Nov 2015 11:00:08 -0600 Subject: [PATCH 07/24] update ember-cli to 1.13.12 --- .editorconfig | 31 ++++++++++++++++++++++---- .ember-cli | 9 ++++++++ .npmignore | 14 ++++++++++++ .watchmanconfig | 3 +++ config/ember-try.js | 1 + package.json | 2 +- tests/dummy/app/app.js | 4 ++-- tests/dummy/app/router.js | 2 +- tests/helpers/destroy-app.js | 5 +++++ tests/helpers/module-for-acceptance.js | 23 +++++++++++++++++++ tests/helpers/resolver.js | 2 +- tests/helpers/start-app.js | 6 ++--- tests/index.html | 3 ++- 13 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 .ember-cli create mode 100644 .npmignore create mode 100644 .watchmanconfig create mode 100644 tests/helpers/destroy-app.js create mode 100644 tests/helpers/module-for-acceptance.js diff --git a/.editorconfig b/.editorconfig index e20a9680d23..47c5438403c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,11 +1,34 @@ -# http://editorconfig.org +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org root = true + [*] +end_of_line = lf charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true indent_style = space indent_size = 2 -end_of_line = lf -insert_final_newline = true -trim_trailing_whitespace = true \ No newline at end of file + +[*.js] +indent_style = space +indent_size = 2 + +[*.hbs] +insert_final_newline = false +indent_style = space +indent_size = 2 + +[*.css] +indent_style = space +indent_size = 2 + +[*.html] +indent_style = space +indent_size = 2 + +[*.{diff,md}] +trim_trailing_whitespace = false diff --git a/.ember-cli b/.ember-cli new file mode 100644 index 00000000000..ee64cfed2a8 --- /dev/null +++ b/.ember-cli @@ -0,0 +1,9 @@ +{ + /** + Ember CLI sends analytics information by default. The data is completely + anonymous, but there are times when you might want to disable this behavior. + + Setting `disableAnalytics` to true will prevent any data from being sent. + */ + "disableAnalytics": false +} diff --git a/.npmignore b/.npmignore new file mode 100644 index 00000000000..49996f5a391 --- /dev/null +++ b/.npmignore @@ -0,0 +1,14 @@ +bower_components/ +tests/ +tmp/ +dist/ + +.bowerrc +.editorconfig +.ember-cli +.travis.yml +.npmignore +**/.gitkeep +bower.json +Brocfile.js +testem.json diff --git a/.watchmanconfig b/.watchmanconfig new file mode 100644 index 00000000000..e7834e3e4f3 --- /dev/null +++ b/.watchmanconfig @@ -0,0 +1,3 @@ +{ + "ignore_dirs": ["tmp", "dist"] +} diff --git a/config/ember-try.js b/config/ember-try.js index 83dab0f1846..3e88bc612a1 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -1,3 +1,4 @@ +/*jshint node:true*/ module.exports = { scenarios: [ { diff --git a/package.json b/package.json index 7f229a2eb08..cfb62ce1f53 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "broccoli-string-replace": "^0.1.1", "broccoli-uglify-sourcemap": "^1.0.1", "broccoli-yuidoc": "^2.1.0", - "ember-cli": "1.13.8", + "ember-cli": "1.13.12", "ember-cli-app-version": "0.5.0", "ember-cli-content-security-policy": "0.4.0", "ember-cli-dependency-checker": "^1.0.1", diff --git a/tests/dummy/app/app.js b/tests/dummy/app/app.js index 8d66b958758..8b234d6d57b 100644 --- a/tests/dummy/app/app.js +++ b/tests/dummy/app/app.js @@ -3,14 +3,14 @@ import Resolver from 'ember/resolver'; import loadInitializers from 'ember/load-initializers'; import config from './config/environment'; -var App; +let App; Ember.MODEL_FACTORY_INJECTIONS = true; App = Ember.Application.extend({ modulePrefix: config.modulePrefix, podModulePrefix: config.podModulePrefix, - Resolver: Resolver + Resolver }); loadInitializers(App, config.modulePrefix); diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index cef554b3d9e..3bba78ebc80 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -1,7 +1,7 @@ import Ember from 'ember'; import config from './config/environment'; -var Router = Ember.Router.extend({ +const Router = Ember.Router.extend({ location: config.locationType }); diff --git a/tests/helpers/destroy-app.js b/tests/helpers/destroy-app.js new file mode 100644 index 00000000000..c3d4d1abb5d --- /dev/null +++ b/tests/helpers/destroy-app.js @@ -0,0 +1,5 @@ +import Ember from 'ember'; + +export default function destroyApp(application) { + Ember.run(application, 'destroy'); +} diff --git a/tests/helpers/module-for-acceptance.js b/tests/helpers/module-for-acceptance.js new file mode 100644 index 00000000000..ed23003db40 --- /dev/null +++ b/tests/helpers/module-for-acceptance.js @@ -0,0 +1,23 @@ +import { module } from 'qunit'; +import startApp from '../helpers/start-app'; +import destroyApp from '../helpers/destroy-app'; + +export default function(name, options = {}) { + module(name, { + beforeEach() { + this.application = startApp(); + + if (options.beforeEach) { + options.beforeEach.apply(this, arguments); + } + }, + + afterEach() { + destroyApp(this.application); + + if (options.afterEach) { + options.afterEach.apply(this, arguments); + } + } + }); +} diff --git a/tests/helpers/resolver.js b/tests/helpers/resolver.js index 28f4ece46a0..ebfb4e4d455 100644 --- a/tests/helpers/resolver.js +++ b/tests/helpers/resolver.js @@ -1,7 +1,7 @@ import Resolver from 'ember/resolver'; import config from '../../config/environment'; -var resolver = Resolver.create(); +const resolver = Resolver.create(); resolver.namespace = { modulePrefix: config.modulePrefix, diff --git a/tests/helpers/start-app.js b/tests/helpers/start-app.js index 0f7aab1afb5..e098f1d5be6 100644 --- a/tests/helpers/start-app.js +++ b/tests/helpers/start-app.js @@ -3,12 +3,12 @@ import Application from '../../app'; import config from '../../config/environment'; export default function startApp(attrs) { - var application; + let application; - var attributes = Ember.merge({}, config.APP); + let attributes = Ember.merge({}, config.APP); attributes = Ember.merge(attributes, attrs); // use defaults, but you can override; - Ember.run(function() { + Ember.run(() => { application = Application.create(attributes); application.setupForTesting(); application.injectTestHelpers(); diff --git a/tests/index.html b/tests/index.html index bd598bf0d51..5e88e5e10c2 100644 --- a/tests/index.html +++ b/tests/index.html @@ -18,13 +18,14 @@ {{content-for 'test-head-footer'}} - {{content-for 'body'}} {{content-for 'test-body'}} + + {{content-for 'body-footer'}} From dba19186508738220434f87ef37c4712eb77dce3 Mon Sep 17 00:00:00 2001 From: bmac Date: Tue, 17 Nov 2015 10:30:37 -0500 Subject: [PATCH 08/24] [BUGFIX beta] Warn instead of asserting when a mapped key doesn't match an attribute or relationship --- addon/serializers/json-serializer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addon/serializers/json-serializer.js b/addon/serializers/json-serializer.js index cd196f7ea0c..625f12cfff7 100644 --- a/addon/serializers/json-serializer.js +++ b/addon/serializers/json-serializer.js @@ -763,7 +763,9 @@ export default Serializer.extend({ @return {String} key */ _getMappedKey: function(key, modelClass) { - Ember.assert('There is no attribute or relationship with the name `' + key + '` on `' + modelClass.modelName + '`. Check your serializers attrs hash.', get(modelClass, 'attributes').has(key) || get(modelClass, 'relationshipsByName').has(key)); + Ember.warn('There is no attribute or relationship with the name `' + key + '` on `' + modelClass.modelName + '`. Check your serializers attrs hash.', get(modelClass, 'attributes').has(key) || get(modelClass, 'relationshipsByName').has(key), { + id: 'ds.serializer.no-mapped-attrs-key' + }); var attrs = get(this, 'attrs'); var mappedKey; From 838d51b9a23ee6cd4d5fa617080a6cb5a1078e77 Mon Sep 17 00:00:00 2001 From: bmac Date: Tue, 17 Nov 2015 13:31:34 -0500 Subject: [PATCH 09/24] Update the changelog for Ember Data 2.2.0 --- CHANGELOG.md | 43 +++++++++++++++++++++++++++++++++++++++++++ package.json | 1 - 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3762fb3e559..6cc4674ba75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,49 @@ ### Master +### Release 2.2.0 (November 17, 2015) +- [#3937](https://github.com/emberjs/data/pull/3937) [BUGFIX beta] Warn instead of asserting when a mapped key doesn't mat… +- [#3868](https://github.com/emberjs/data/pull/3868) Reset changed attributes when matching data is pushed +- [#3875](https://github.com/emberjs/data/pull/3875) [BUGFIX beta] serialize type for embedded, polymorphic belongsTo +- [#3900](https://github.com/emberjs/data/pull/3900) [DOC fix] errors pointers should start with a / +- [#3905](https://github.com/emberjs/data/pull/3905) [BUGFIX release] Update the dependencies for Ember 2.x +- [#3909](https://github.com/emberjs/data/pull/3909) [BUGFIX beta] Correctly handle object level errors in json api +- [#3910](https://github.com/emberjs/data/pull/3910) [BUGFIX release] Normalize attrs keys +- [#3912](https://github.com/emberjs/data/pull/3912) Use public API for container/registry when possible.] +- [#3835](https://github.com/emberjs/data/pull/3835) [BUGFIX] extract polymorphic belongsTo in RESTSerializer +- [#3887](https://github.com/emberjs/data/pull/3887) [BUGFIX release] update ember-inflector to resolve default Inflector … +- [#3888](https://github.com/emberjs/data/pull/3888) [BUGFIX release] import from ember-inflector to use the default instance +- [#3832](https://github.com/emberjs/data/pull/3832) Fix API docs for JSONAPISerializer.normalize +- [#3837](https://github.com/emberjs/data/pull/3837) [BUGFIX] Attribute/relationship named "type" of embedded record is considered before normalization +- [#3846](https://github.com/emberjs/data/pull/3846) [BUGFIX beta] Attribute/relationship named "type" of primary record i… +- [#3847](https://github.com/emberjs/data/pull/3847) [BUGFIX beta] JSONAPI serializer not respecting 'attrs' hash +- [#3857](https://github.com/emberjs/data/pull/3857) [BUGFIX beta] rollbackAttributes() works after multiple failed saves +- [#3859](https://github.com/emberjs/data/pull/3859) [BUGFIX beta] Correctly handle invalid errors without payload or pointer +- [#3861](https://github.com/emberjs/data/pull/3861) [BUGFIX beta] Assert that an array is returned from the normalized re… +- [#3867](https://github.com/emberjs/data/pull/3867) Allow serializers to normalize response, remove old internal serializers code +- [#3697](https://github.com/emberjs/data/pull/3697) Fix typo in CHANGELOG +- [#3215](https://github.com/emberjs/data/pull/3215) remove Map/MapWithDefault polyfills, use Ember's ones +- [#3711](https://github.com/emberjs/data/pull/3711) Explicitly set length after setting a new content property +- [#3714](https://github.com/emberjs/data/pull/3714) Update the location of the custom store in the API doc example +- [#3699](https://github.com/emberjs/data/pull/3699) [refactor] add some tests asserting polymorphic relationships can be … +- [#3751](https://github.com/emberjs/data/pull/3751) Remove normalizePayload, associated docs, and mention of functionality. +- [#3732](https://github.com/emberjs/data/pull/3732) follow up fixes for #3701 +- [#3746](https://github.com/emberjs/data/pull/3746) Improve test coverage for store#findRecord() +- [#3722](https://github.com/emberjs/data/pull/3722) Shape and cleanup +- [#3739](https://github.com/emberjs/data/pull/3739) store example should use findRecord() +- [#3734](https://github.com/emberjs/data/pull/3734) Revert "Explicitly set length after setting a new content property" +- [#3783](https://github.com/emberjs/data/pull/3783) Update changelog for 2.0.1 release +- [#3771](https://github.com/emberjs/data/pull/3771) update coalesceFindRequests doc for JSONAPIAdapter +- [#3774](https://github.com/emberjs/data/pull/3774) Fix embedded key serialization bug and refactor key serialization +- [#3773](https://github.com/emberjs/data/pull/3773) Break apart embedded serialize methods in EmbeddedRecordsMixin +- [#3777](https://github.com/emberjs/data/pull/3777) Remove unused test module +- [#3788](https://github.com/emberjs/data/pull/3788) Port pr #3725 to the release 2.0 branch +- [#3795](https://github.com/emberjs/data/pull/3795) Trigger an assertion when calling `findRecord` with falsy (except 0) id +- [#3808](https://github.com/emberjs/data/pull/3808) Update internal-model.js +- [#3814](https://github.com/emberjs/data/pull/3814) [BUGFIX] Do not deserialize when a relationship named `type` exists +- [#3816](https://github.com/emberjs/data/pull/3816) run optional feature tests on AppVeyor +- [#3817](https://github.com/emberjs/data/pull/3817) Update the changelog for Ember Data 2.1.0 + ### Release 1.13.14 (October 18, 2015) - [#3665](https://github.com/emberjs/data/pull/3665) [BUGFIX beta] Fix usage of registry for 2.1.0+. - [#3825](https://github.com/emberjs/data/pull/3825) [BUGFIX] Restore IE8 compatibility by using Ember.create diff --git a/package.json b/package.json index cfb62ce1f53..4bcf8a4c991 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,6 @@ "ember-cli-inject-live-reload": "^1.3.1", "ember-cli-qunit": "^1.0.0", "ember-cli-release": "0.2.3", - "ember-cli-sri": "^1.0.3", "ember-cli-uglify": "^1.2.0", "ember-disable-prototype-extensions": "^1.0.0", "ember-disable-proxy-controllers": "^1.0.0", From 3fc52c4aeb09d13f258963209076be700d6b4c8c Mon Sep 17 00:00:00 2001 From: bmac Date: Tue, 17 Nov 2015 14:49:22 -0500 Subject: [PATCH 10/24] Bump the version number to 2.4.0-canary --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4bcf8a4c991..9970990d1e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ember-data", - "version": "2.3.0+canary", + "version": "2.4.0-canary", "description": "A data layer for your Ember applications.", "repository": "git://github.com/emberjs/data.git", "directories": { From 666f7a6d2c588e553a8313e3d2df36ec8e73186f Mon Sep 17 00:00:00 2001 From: Mikhail Topolskiy Date: Wed, 18 Nov 2015 16:30:41 +0300 Subject: [PATCH 11/24] Remove JSONSerializer#normalizeId JSONSerializer#normalizeId is unused, extractId/coerceId are used instead --- addon/serializers/json-serializer.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/addon/serializers/json-serializer.js b/addon/serializers/json-serializer.js index 625f12cfff7..22552cf1b98 100644 --- a/addon/serializers/json-serializer.js +++ b/addon/serializers/json-serializer.js @@ -740,19 +740,6 @@ export default Serializer.extend({ } }, - /** - @method normalizeId - @private - */ - normalizeId: function(hash) { - var primaryKey = get(this, 'primaryKey'); - - if (primaryKey === 'id') { return; } - - hash.id = hash[primaryKey]; - delete hash[primaryKey]; - }, - /** Looks up the property key that was set by the custom `attr` mapping passed to the serializer. From 38ef355b128be114192b7419d013c6343a72aa12 Mon Sep 17 00:00:00 2001 From: bmac Date: Wed, 18 Nov 2015 10:25:22 -0500 Subject: [PATCH 12/24] Mark `adapterFor` and `serializerFor` as public --- addon/system/store.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addon/system/store.js b/addon/system/store.js index baa97c34ec4..d112e667562 100644 --- a/addon/system/store.js +++ b/addon/system/store.js @@ -1937,7 +1937,7 @@ Store = Service.extend({ the value of the `defaultAdapter`. @method adapterFor - @private + @public @param {String} modelName @return DS.Adapter */ @@ -1973,7 +1973,7 @@ Store = Service.extend({ to an instance of `DS.JSONSerializer`. @method serializerFor - @private + @public @param {String} modelName the record to serialize @return {DS.Serializer} */ From 06405d7275f59b5dcff2aaf9f407bbc97ad02b83 Mon Sep 17 00:00:00 2001 From: Stanley Stuart Date: Thu, 19 Nov 2015 16:29:11 -0600 Subject: [PATCH 13/24] [BUGFIX beta] create an empty sourcemap for bower users refs https://github.com/components/ember-data/issues/32 --- lib/javascripts.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/javascripts.js b/lib/javascripts.js index 761dd2ca8ec..2e39d30c0a5 100644 --- a/lib/javascripts.js +++ b/lib/javascripts.js @@ -8,6 +8,7 @@ var version = require('./version'); var path = require('path'); var Funnel = require('broccoli-funnel'); var versionReplace = require('./version-replace'); +var fileCreator = require('broccoli-file-creator'); function babelOptions(libraryName, _options) { _options = _options || {}; @@ -132,6 +133,8 @@ module.exports = function(tree) { var debug = collapse(javascripts, 'ember-data.js'); var production = collapse(strippedJavascripts, 'ember-data.prod.js'); var minified = stew.rename(minify(production), 'ember-data.prod.js', 'ember-data.min.js'); + // Hack to get around https://github.com/emberjs/data/blob/v2.1.0/lib/ember-addon/index.js#L28 + var emptySourcemapFile = fileCreator('ember-data.js.map', ''); - return merge([debug, production, minified]); + return merge([debug, production, minified, emptySourcemapFile]); }; From 4ece826843e700933fab76ae4dcdb1ca3ba49e5b Mon Sep 17 00:00:00 2001 From: Chad Hietala Date: Thu, 19 Nov 2015 12:06:29 -0800 Subject: [PATCH 14/24] [PERF] Ajax should join an existing run if one exists --- addon/adapters/rest-adapter.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addon/adapters/rest-adapter.js b/addon/adapters/rest-adapter.js index fedd8c72c0a..01820dea83b 100644 --- a/addon/adapters/rest-adapter.js +++ b/addon/adapters/rest-adapter.js @@ -824,9 +824,9 @@ export default Adapter.extend(BuildURLMixin, { ); if (response instanceof AdapterError) { - Ember.run(null, reject, response); + Ember.run.join(null, reject, response); } else { - Ember.run(null, resolve, response); + Ember.run.join(null, resolve, response); } }; @@ -849,7 +849,7 @@ export default Adapter.extend(BuildURLMixin, { } } - Ember.run(null, reject, error); + Ember.run.join(null, reject, error); }; Ember.$.ajax(hash); From f23f02fd6684faaeb2918a08b03c7e41fde9f755 Mon Sep 17 00:00:00 2001 From: Alex Speller Date: Sun, 22 Nov 2015 03:29:22 +0000 Subject: [PATCH 15/24] Fix incorrect reference --- addon/system/store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/system/store.js b/addon/system/store.js index d112e667562..3ee59aabb4f 100644 --- a/addon/system/store.js +++ b/addon/system/store.js @@ -1054,7 +1054,7 @@ Store = Service.extend({ locally created records of the type, however, it will not make a request to the backend to retrieve additional records. If you would like to request all the records from the backend please use - [store.find](#method_find). + [store.findAll](#method_findAll). Also note that multiple calls to `peekAll` for a given type will always return the same `RecordArray`. From 8d0230c359d787afdddda041813a36c1d976e5ab Mon Sep 17 00:00:00 2001 From: Marten Schilstra Date: Fri, 20 Nov 2015 10:05:11 +0100 Subject: [PATCH 16/24] Report better error when `type` is missing from a JSONApi response --- addon/serializers/json-api-serializer.js | 7 +++++++ .../serializers/json-api-serializer-test.js | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/addon/serializers/json-api-serializer.js b/addon/serializers/json-api-serializer.js index b398ebeefaa..8b53ea568c5 100644 --- a/addon/serializers/json-api-serializer.js +++ b/addon/serializers/json-api-serializer.js @@ -136,6 +136,10 @@ const JSONAPISerializer = JSONSerializer.extend({ @private */ _normalizeResourceHelper: function(resourceHash) { + Ember.assert(this.warnMessageForUndefinedType(), !Ember.isNone(resourceHash.type), { + id: 'ds.serializer.type-is-undefined' + }); + let modelName = this.modelNameFromPayloadKey(resourceHash.type); if (!this.store._hasModelFor(modelName)) { @@ -465,6 +469,9 @@ const JSONAPISerializer = JSONSerializer.extend({ Ember.runInDebug(function() { JSONAPISerializer.reopen({ + warnMessageForUndefinedType: function() { + return 'Encountered a resource object with an undefined type (resolved resource using ' + this.constructor.toString() + ')'; + }, warnMessageNoModelForType: function(modelName, originalType) { return 'Encountered a resource object with type "' + originalType + '", but no model was found for model name "' + modelName + '" (resolved model name using ' + this.constructor.toString() + '.modelNameFromPayloadKey("' + originalType + '"))'; } diff --git a/tests/integration/serializers/json-api-serializer-test.js b/tests/integration/serializers/json-api-serializer-test.js index 7536f865bce..6d8af4f3954 100644 --- a/tests/integration/serializers/json-api-serializer-test.js +++ b/tests/integration/serializers/json-api-serializer-test.js @@ -134,6 +134,23 @@ test('Warns when normalizing an unknown type', function(assert) { }, /Encountered a resource object with type "UnknownType", but no model was found for model name "unknown-type"/); }); +test('Warns when normalizing with type missing', function(assert) { + var documentHash = { + data: { + id: '1', + attributes: { + foo: 'bar' + } + } + }; + + assert.throws(function() { + run(function() { + env.store.serializerFor('user').normalizeResponse(env.store, User, documentHash, '1', 'findRecord'); + }); + }, /Encountered a resource object with an undefined type/); +}); + test('Serializer should respect the attrs hash when extracting attributes and relationships', function(assert) { env.registry.register("serializer:user", DS.JSONAPISerializer.extend({ attrs: { From 071aa101bdb8fdeafa8be7e0f59cfcecb4ac3982 Mon Sep 17 00:00:00 2001 From: Austin Burdine Date: Sat, 28 Nov 2015 12:35:10 -0700 Subject: [PATCH 17/24] fix incorrect argument description... ...in `store.queryRecord` Docs incorrectly say that passed in modelName can be a subclass of DS.Model. That behavior has been removed. --- addon/system/store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/system/store.js b/addon/system/store.js index 3ee59aabb4f..f4e4a8026dd 100644 --- a/addon/system/store.js +++ b/addon/system/store.js @@ -960,7 +960,7 @@ Store = Service.extend({ once the server returns. @method queryRecord - @param {String or subclass of DS.Model} type + @param {String} modelName @param {any} query an opaque query to be used by the adapter @return {Promise} promise */ From 840b48781ad21edc61cef306e92aae53a7db0c7f Mon Sep 17 00:00:00 2001 From: Jeffrey Biles Date: Mon, 30 Nov 2015 11:48:40 -0600 Subject: [PATCH 18/24] Use findRecord syntax in unloadRecord documentation Just a small update to the new syntax. --- addon/system/store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/system/store.js b/addon/system/store.js index f4e4a8026dd..8d645d68326 100644 --- a/addon/system/store.js +++ b/addon/system/store.js @@ -407,7 +407,7 @@ Store = Service.extend({ Example ```javascript - store.find('post', 1).then(function(post) { + store.findRecord('post', 1).then(function(post) { store.unloadRecord(post); }); ``` From 0057b0435f1f484b20d93f1db4ea88c26d3f4b17 Mon Sep 17 00:00:00 2001 From: Aaron Renoir Date: Tue, 13 Oct 2015 19:31:13 -0700 Subject: [PATCH 19/24] fix transitioning into invalid state remove events from error class add functionality to become valid if errors are removed depricate adding errors change deprecations to regular warnings --- addon/system/model/errors.js | 93 +++++++++++++++++++++++--- addon/system/model/internal-model.js | 13 +++- addon/system/model/model.js | 3 +- addon/system/model/states.js | 8 +++ tests/integration/records/save-test.js | 12 +++- 5 files changed, 110 insertions(+), 19 deletions(-) diff --git a/addon/system/model/errors.js b/addon/system/model/errors.js index 415fcf9407c..1d11f6e0a60 100644 --- a/addon/system/model/errors.js +++ b/addon/system/model/errors.js @@ -107,12 +107,31 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @param {Object} target @param {Function} becameInvalid @param {Function} becameValid + @deprecated */ registerHandlers: function(target, becameInvalid, becameValid) { + Ember.deprecate( + `Record errors will no longer be evented.`, false, { + id: 'ds.errors.registerHandlers', + until: '3.0.0' + }); + + this._registerHandlers(target, becameInvalid, becameValid); + }, + + + /** + Register with target handler + + @method _registerHandlers + @private + */ + _registerHandlers: function(target, becameInvalid, becameValid) { this.on('becameInvalid', target, becameInvalid); this.on('becameValid', target, becameValid); }, + /** @property errorsByAttributeName @type {Ember.MapWithDefault} @@ -214,19 +233,35 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @method add @param {String} attribute @param {(Array|String)} messages + @deprecated */ add: function(attribute, messages) { + Ember.warn(`Interacting with a record errors object will no longer change the record state.`, false, { + id: 'ds.errors.add' + }); + var wasEmpty = get(this, 'isEmpty'); + this._add(attribute, messages); + + if (wasEmpty && !get(this, 'isEmpty')) { + this.trigger('becameInvalid'); + } + }, + + + /** + Adds error messages to a given attribute without sending event. + + @method _add + @private + */ + _add: function(attribute, messages) { messages = this._findOrCreateMessages(attribute, messages); this.addObjects(messages); get(this, 'errorsByAttributeName').get(attribute).addObjects(messages); this.notifyPropertyChange(attribute); - - if (wasEmpty && !get(this, 'isEmpty')) { - this.trigger('becameInvalid'); - } }, /** @@ -277,8 +312,29 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @method remove @param {String} attribute + @deprecated */ remove: function(attribute) { + Ember.warn(`Interacting with a record errors object will no longer change the record state.`, false, { + id: 'ds.errors.remove' + }); + + if (get(this, 'isEmpty')) { return; } + + this._remove(attribute); + + if (get(this, 'isEmpty')) { + this.trigger('becameValid'); + } + }, + + /** + Removes all error messages from the given attribute without sending event. + + @method _remove + @private + */ + _remove: function(attribute) { if (get(this, 'isEmpty')) { return; } let content = this.rejectBy('attribute', attribute); @@ -286,10 +342,6 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { get(this, 'errorsByAttributeName').delete(attribute); this.notifyPropertyChange(attribute); - - if (get(this, 'isEmpty')) { - this.trigger('becameValid'); - } }, /** @@ -312,8 +364,28 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { ``` @method clear + @deprecated */ clear: function() { + Ember.warn(`Interacting with a record errors object will no longer change the record state.`, false, { + id: 'ds.errors.clear' + }); + + if (get(this, 'isEmpty')) { return; } + + this._clear(); + this.trigger('becameValid'); + }, + + + /** + Removes all error messages. + to the record. + + @method _clear + @private + */ + _clear: function() { if (get(this, 'isEmpty')) { return; } let errorsByAttributeName = get(this, 'errorsByAttributeName'); @@ -328,11 +400,10 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { this.notifyPropertyChange(attribute); }, this); - this._super(); - - this.trigger('becameValid'); + Ember.ArrayProxy.prototype.clear.call(this); }, + /** Checks if there is error messages for the given attribute. diff --git a/addon/system/model/internal-model.js b/addon/system/model/internal-model.js index 13d47f608c2..1f4b30746b4 100644 --- a/addon/system/model/internal-model.js +++ b/addon/system/model/internal-model.js @@ -676,17 +676,24 @@ InternalModel.prototype = { addErrorMessageToAttribute: function(attribute, message) { var record = this.getRecord(); - get(record, 'errors').add(attribute, message); + get(record, 'errors')._add(attribute, message); }, removeErrorMessageFromAttribute: function(attribute) { var record = this.getRecord(); - get(record, 'errors').remove(attribute); + get(record, 'errors')._remove(attribute); }, clearErrorMessages: function() { var record = this.getRecord(); - get(record, 'errors').clear(); + get(record, 'errors')._clear(); + }, + + hasErrors: function() { + var record = this.getRecord(); + var errors = get(record, 'errors'); + + return !Ember.isEmpty(errors); }, // FOR USE DURING COMMIT PROCESS diff --git a/addon/system/model/model.js b/addon/system/model/model.js index bfa760cd6fb..dcc5a8bccdc 100644 --- a/addon/system/model/model.js +++ b/addon/system/model/model.js @@ -351,14 +351,13 @@ var Model = Ember.Object.extend(Ember.Evented, { errors: Ember.computed(function() { let errors = Errors.create(); - errors.registerHandlers(this._internalModel, + errors._registerHandlers(this._internalModel, function() { this.send('becameInvalid'); }, function() { this.send('becameValid'); }); - return errors; }).readOnly(), diff --git a/addon/system/model/states.js b/addon/system/model/states.js index f6fae3a4df0..e4c0cb9997a 100644 --- a/addon/system/model/states.js +++ b/addon/system/model/states.js @@ -326,6 +326,10 @@ var DirtyState = { internalModel.removeErrorMessageFromAttribute(context.name); didSetProperty(internalModel, context); + + if (!internalModel.hasErrors()) { + this.becameValid(internalModel); + } }, becameInvalid: Ember.K, @@ -695,6 +699,10 @@ var RootState = { internalModel.removeErrorMessageFromAttribute(context.name); didSetProperty(internalModel, context); + + if (!internalModel.hasErrors()) { + this.becameValid(internalModel); + } }, becameInvalid: Ember.K, diff --git a/tests/integration/records/save-test.js b/tests/integration/records/save-test.js index 748d375537f..a8e09a5ce82 100644 --- a/tests/integration/records/save-test.js +++ b/tests/integration/records/save-test.js @@ -58,7 +58,9 @@ test("Will reject save on error", function(assert) { }); env.adapter.createRecord = function(store, type, snapshot) { - return Ember.RSVP.reject(); + var error = new DS.InvalidError([{ title: 'not valid' }]); + + return Ember.RSVP.reject(error); }; run(function() { @@ -77,8 +79,10 @@ test("Retry is allowed in a failure handler", function(assert) { var count = 0; env.adapter.createRecord = function(store, type, snapshot) { + var error = new DS.InvalidError([{ title: 'not valid' }]); + if (count++ === 0) { - return Ember.RSVP.reject(); + return Ember.RSVP.reject(error); } else { return Ember.RSVP.resolve({ id: 123 }); } @@ -181,7 +185,9 @@ test("Will reject save on invalid", function(assert) { }); env.adapter.createRecord = function(store, type, snapshot) { - return Ember.RSVP.reject({ title: 'invalid' }); + var error = new DS.InvalidError([{ title: 'not valid' }]); + + return Ember.RSVP.reject(error); }; run(function() { From 110127a668909e17075c2c8cf520dad5526486cf Mon Sep 17 00:00:00 2001 From: bmac Date: Mon, 30 Nov 2015 17:18:15 -0500 Subject: [PATCH 20/24] Add a better error message when findRecord returns an array Closes #3950 --- addon/system/store/finders.js | 1 + tests/integration/store-test.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/addon/system/store/finders.js b/addon/system/store/finders.js index e9fb4530dd3..c5005b16a09 100644 --- a/addon/system/store/finders.js +++ b/addon/system/store/finders.js @@ -35,6 +35,7 @@ export function _find(adapter, store, typeClass, id, internalModel, options) { Ember.assert("You made a `find` request for a " + typeClass.typeClassKey + " with id " + id + ", but the adapter's response did not have any data", payloadIsNotBlank(adapterPayload)); return store._adapterRun(function() { var payload = normalizeResponseHelper(serializer, store, typeClass, adapterPayload, id, 'findRecord'); + Ember.assert('Ember Data expected the primary data returned from a `findRecord` response to be an object but instead it found an array.', !Array.isArray(payload.data)); //TODO Optimize var record = store.push(payload); return record._internalModel; diff --git a/tests/integration/store-test.js b/tests/integration/store-test.js index c371cd72130..9e5a114f70f 100644 --- a/tests/integration/store-test.js +++ b/tests/integration/store-test.js @@ -571,3 +571,17 @@ test("Store should accept a null value for `data`", function(assert) { }); }); }); + +test('store#findRecord that returns an array should assert', assert => { + initializeStore(DS.JSONAPIAdapter.extend({ + findRecord: function() { + return { data: [] }; + } + })); + + assert.expectAssertion(function() { + run(function() { + store.findRecord('car', 1); + }); + }, /expected the primary data returned from a `findRecord` response to be an object but instead it found an array/); +}); From 16827a1ce8c74b3eb426ecf1e60d75e01f512256 Mon Sep 17 00:00:00 2001 From: Stanley Stuart Date: Wed, 2 Dec 2015 12:45:15 -0600 Subject: [PATCH 21/24] Revert "[DOC fix] Adds missing space before list" --- addon/serializers/embedded-records-mixin.js | 1 - 1 file changed, 1 deletion(-) diff --git a/addon/serializers/embedded-records-mixin.js b/addon/serializers/embedded-records-mixin.js index 8cb8f4f6d71..9f5a610d2c8 100644 --- a/addon/serializers/embedded-records-mixin.js +++ b/addon/serializers/embedded-records-mixin.js @@ -85,7 +85,6 @@ var camelize = Ember.String.camelize; to modify it to fit your specific needs.** For example review the docs for each method of this mixin: - * [normalize](/api/data/classes/DS.EmbeddedRecordsMixin.html#method_normalize) * [serializeBelongsTo](/api/data/classes/DS.EmbeddedRecordsMixin.html#method_serializeBelongsTo) * [serializeHasMany](/api/data/classes/DS.EmbeddedRecordsMixin.html#method_serializeHasMany) From ef6c167fc6c8092aafb8a3ad4b053debc6ad530e Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Fri, 13 Nov 2015 09:54:20 -0500 Subject: [PATCH 22/24] [CLEANUP] `ember watson:methodify addon/` Convert function declaration into ES6 syntax. --- addon/adapters/build-url-mixin.js | 28 ++-- addon/adapters/json-api-adapter.js | 8 +- addon/adapters/rest-adapter.js | 42 +++--- addon/serializers/embedded-records-mixin.js | 36 ++--- addon/serializers/json-api-serializer.js | 40 +++--- addon/serializers/json-serializer.js | 82 +++++------ addon/serializers/rest-serializer.js | 28 ++-- addon/system/adapter.js | 12 +- addon/system/debug/debug-adapter.js | 18 +-- addon/system/debug/debug-info.js | 2 +- addon/system/many-array.js | 24 ++-- addon/system/model/attributes.js | 10 +- addon/system/model/errors.js | 26 ++-- addon/system/model/internal-model.js | 116 ++++++++-------- addon/system/model/model.js | 42 +++--- addon/system/model/states.js | 88 ++++++------ addon/system/promise-proxies.js | 2 +- addon/system/record-array-manager.js | 38 +++--- .../adapter-populated-record-array.js | 4 +- .../record-arrays/filtered-record-array.js | 4 +- addon/system/record-arrays/record-array.js | 16 +-- addon/system/relationships/belongs-to.js | 6 +- addon/system/relationships/ext.js | 22 +-- addon/system/relationships/has-many.js | 6 +- .../relationships/state/relationship.js | 42 +++--- addon/system/serializer.js | 2 +- addon/system/snapshot.js | 16 +-- addon/system/store.js | 128 +++++++++--------- .../system/store/container-instance-cache.js | 10 +- addon/system/store/serializers.js | 2 +- addon/transforms/boolean.js | 4 +- addon/transforms/date.js | 4 +- addon/transforms/number.js | 4 +- addon/transforms/string.js | 4 +- 34 files changed, 458 insertions(+), 458 deletions(-) diff --git a/addon/adapters/build-url-mixin.js b/addon/adapters/build-url-mixin.js index 1baf0d7b176..4987b408378 100644 --- a/addon/adapters/build-url-mixin.js +++ b/addon/adapters/build-url-mixin.js @@ -49,7 +49,7 @@ export default Ember.Mixin.create({ @param {Object} query object of query parameters to send for query requests. @return {String} url */ - buildURL: function(modelName, id, snapshot, requestType, query) { + buildURL(modelName, id, snapshot, requestType, query) { switch (requestType) { case 'findRecord': return this.urlForFindRecord(id, modelName, snapshot); @@ -83,7 +83,7 @@ export default Ember.Mixin.create({ @param {String} id @return {String} url */ - _buildURL: function(modelName, id) { + _buildURL(modelName, id) { var url = []; var host = get(this, 'host'); var prefix = this.urlPrefix(); @@ -112,7 +112,7 @@ export default Ember.Mixin.create({ * @param {DS.Snapshot} snapshot * @return {String} url */ - urlForFindRecord: function(id, modelName, snapshot) { + urlForFindRecord(id, modelName, snapshot) { return this._buildURL(modelName, id); }, @@ -121,7 +121,7 @@ export default Ember.Mixin.create({ * @param {String} modelName * @return {String} url */ - urlForFindAll: function(modelName) { + urlForFindAll(modelName) { return this._buildURL(modelName); }, @@ -131,7 +131,7 @@ export default Ember.Mixin.create({ * @param {String} modelName * @return {String} url */ - urlForQuery: function(query, modelName) { + urlForQuery(query, modelName) { return this._buildURL(modelName); }, @@ -141,7 +141,7 @@ export default Ember.Mixin.create({ * @param {String} modelName * @return {String} url */ - urlForQueryRecord: function(query, modelName) { + urlForQueryRecord(query, modelName) { return this._buildURL(modelName); }, @@ -152,7 +152,7 @@ export default Ember.Mixin.create({ * @param {Array} snapshots * @return {String} url */ - urlForFindMany: function(ids, modelName, snapshots) { + urlForFindMany(ids, modelName, snapshots) { return this._buildURL(modelName); }, @@ -162,7 +162,7 @@ export default Ember.Mixin.create({ * @param {String} modelName * @return {String} url */ - urlForFindHasMany: function(id, modelName) { + urlForFindHasMany(id, modelName) { return this._buildURL(modelName, id); }, @@ -172,7 +172,7 @@ export default Ember.Mixin.create({ * @param {String} modelName * @return {String} url */ - urlForFindBelongsTo: function(id, modelName) { + urlForFindBelongsTo(id, modelName) { return this._buildURL(modelName, id); }, @@ -182,7 +182,7 @@ export default Ember.Mixin.create({ * @param {DS.Snapshot} snapshot * @return {String} url */ - urlForCreateRecord: function(modelName, snapshot) { + urlForCreateRecord(modelName, snapshot) { return this._buildURL(modelName); }, @@ -193,7 +193,7 @@ export default Ember.Mixin.create({ * @param {DS.Snapshot} snapshot * @return {String} url */ - urlForUpdateRecord: function(id, modelName, snapshot) { + urlForUpdateRecord(id, modelName, snapshot) { return this._buildURL(modelName, id); }, @@ -204,7 +204,7 @@ export default Ember.Mixin.create({ * @param {DS.Snapshot} snapshot * @return {String} url */ - urlForDeleteRecord: function(id, modelName, snapshot) { + urlForDeleteRecord(id, modelName, snapshot) { return this._buildURL(modelName, id); }, @@ -215,7 +215,7 @@ export default Ember.Mixin.create({ @param {String} parentURL @return {String} urlPrefix */ - urlPrefix: function(path, parentURL) { + urlPrefix(path, parentURL) { var host = get(this, 'host'); var namespace = get(this, 'namespace'); var url = []; @@ -277,7 +277,7 @@ export default Ember.Mixin.create({ @param {String} modelName @return {String} path **/ - pathForType: function(modelName) { + pathForType(modelName) { var camelized = Ember.String.camelize(modelName); return Ember.String.pluralize(camelized); } diff --git a/addon/adapters/json-api-adapter.js b/addon/adapters/json-api-adapter.js index 1f713a167cb..f5c9d80c58f 100644 --- a/addon/adapters/json-api-adapter.js +++ b/addon/adapters/json-api-adapter.js @@ -21,7 +21,7 @@ export default RESTAdapter.extend({ @param {Object} options @return {Object} */ - ajaxOptions: function(url, type, options) { + ajaxOptions(url, type, options) { let hash = this._super(...arguments); if (hash.contentType) { @@ -96,7 +96,7 @@ export default RESTAdapter.extend({ @param {Array} snapshots @return {Promise} promise */ - findMany: function(store, type, ids, snapshots) { + findMany(store, type, ids, snapshots) { var url = this.buildURL(type.modelName, ids, snapshots, 'findMany'); return this.ajax(url, 'GET', { data: { filter: { id: ids.join(',') } } }); }, @@ -106,7 +106,7 @@ export default RESTAdapter.extend({ @param {String} modelName @return {String} path **/ - pathForType: function(modelName) { + pathForType(modelName) { var dasherized = Ember.String.dasherize(modelName); return Ember.String.pluralize(dasherized); }, @@ -119,7 +119,7 @@ export default RESTAdapter.extend({ @param {DS.Snapshot} snapshot @return {Promise} promise */ - updateRecord: function(store, type, snapshot) { + updateRecord(store, type, snapshot) { var data = {}; var serializer = store.serializerFor(type.modelName); diff --git a/addon/adapters/rest-adapter.js b/addon/adapters/rest-adapter.js index 01820dea83b..26098e3eb58 100644 --- a/addon/adapters/rest-adapter.js +++ b/addon/adapters/rest-adapter.js @@ -233,7 +233,7 @@ export default Adapter.extend(BuildURLMixin, { @param {Object} obj @return {Object} */ - sortQueryParams: function(obj) { + sortQueryParams(obj) { var keys = Object.keys(obj); var len = keys.length; if (len < 2) { @@ -370,7 +370,7 @@ export default Adapter.extend(BuildURLMixin, { @param {DS.Snapshot} snapshot @return {Promise} promise */ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { return this.ajax(this.buildURL(type.modelName, id, snapshot, 'findRecord'), 'GET'); }, @@ -388,7 +388,7 @@ export default Adapter.extend(BuildURLMixin, { @param {DS.SnapshotRecordArray} snapshotRecordArray @return {Promise} promise */ - findAll: function(store, type, sinceToken, snapshotRecordArray) { + findAll(store, type, sinceToken, snapshotRecordArray) { var query, url; if (sinceToken) { @@ -417,7 +417,7 @@ export default Adapter.extend(BuildURLMixin, { @param {Object} query @return {Promise} promise */ - query: function(store, type, query) { + query(store, type, query) { var url = this.buildURL(type.modelName, null, null, 'query', query); if (this.sortQueryParams) { @@ -444,7 +444,7 @@ export default Adapter.extend(BuildURLMixin, { @param {Object} query @return {Promise} promise */ - queryRecord: function(store, type, query) { + queryRecord(store, type, query) { var url = this.buildURL(type.modelName, null, null, 'queryRecord', query); if (this.sortQueryParams) { @@ -487,7 +487,7 @@ export default Adapter.extend(BuildURLMixin, { @param {Array} snapshots @return {Promise} promise */ - findMany: function(store, type, ids, snapshots) { + findMany(store, type, ids, snapshots) { var url = this.buildURL(type.modelName, ids, snapshots, 'findMany'); return this.ajax(url, 'GET', { data: { ids: ids } }); }, @@ -519,7 +519,7 @@ export default Adapter.extend(BuildURLMixin, { @param {String} url @return {Promise} promise */ - findHasMany: function(store, snapshot, url, relationship) { + findHasMany(store, snapshot, url, relationship) { var id = snapshot.id; var type = snapshot.modelName; @@ -555,7 +555,7 @@ export default Adapter.extend(BuildURLMixin, { @param {String} url @return {Promise} promise */ - findBelongsTo: function(store, snapshot, url, relationship) { + findBelongsTo(store, snapshot, url, relationship) { var id = snapshot.id; var type = snapshot.modelName; @@ -579,7 +579,7 @@ export default Adapter.extend(BuildURLMixin, { @param {DS.Snapshot} snapshot @return {Promise} promise */ - createRecord: function(store, type, snapshot) { + createRecord(store, type, snapshot) { var data = {}; var serializer = store.serializerFor(type.modelName); var url = this.buildURL(type.modelName, null, snapshot, 'createRecord'); @@ -605,7 +605,7 @@ export default Adapter.extend(BuildURLMixin, { @param {DS.Snapshot} snapshot @return {Promise} promise */ - updateRecord: function(store, type, snapshot) { + updateRecord(store, type, snapshot) { var data = {}; var serializer = store.serializerFor(type.modelName); @@ -628,13 +628,13 @@ export default Adapter.extend(BuildURLMixin, { @param {DS.Snapshot} snapshot @return {Promise} promise */ - deleteRecord: function(store, type, snapshot) { + deleteRecord(store, type, snapshot) { var id = snapshot.id; return this.ajax(this.buildURL(type.modelName, id, snapshot, 'deleteRecord'), "DELETE"); }, - _stripIDFromURL: function(store, snapshot) { + _stripIDFromURL(store, snapshot) { var url = this.buildURL(snapshot.modelName, snapshot.id, snapshot); var expandedURL = url.split('/'); @@ -676,8 +676,8 @@ export default Adapter.extend(BuildURLMixin, { @return {Array} an array of arrays of records, each of which is to be loaded separately by `findMany`. */ - groupRecordsForFindMany: function (store, snapshots) { - var groups = MapWithDefault.create({ defaultValue: function() { return []; } }); + groupRecordsForFindMany(store, snapshots) { + var groups = MapWithDefault.create({ defaultValue() { return []; } }); var adapter = this; var maxURLLength = this.maxURLLength; @@ -745,7 +745,7 @@ export default Adapter.extend(BuildURLMixin, { @param {Object} payload @return {Object | DS.AdapterError} response */ - handleResponse: function(status, headers, payload) { + handleResponse(status, headers, payload) { if (this.isSuccess(status, headers, payload)) { return payload; } else if (this.isInvalid(status, headers, payload)) { @@ -767,7 +767,7 @@ export default Adapter.extend(BuildURLMixin, { @param {Object} payload @return {Boolean} */ - isSuccess: function(status, headers, payload) { + isSuccess(status, headers, payload) { return status >= 200 && status < 300 || status === 304; }, @@ -781,7 +781,7 @@ export default Adapter.extend(BuildURLMixin, { @param {Object} payload @return {Boolean} */ - isInvalid: function(status, headers, payload) { + isInvalid(status, headers, payload) { return status === 422; }, @@ -809,7 +809,7 @@ export default Adapter.extend(BuildURLMixin, { @param {Object} options @return {Promise} promise */ - ajax: function(url, type, options) { + ajax(url, type, options) { var adapter = this; return new Ember.RSVP.Promise(function(resolve, reject) { @@ -864,7 +864,7 @@ export default Adapter.extend(BuildURLMixin, { @param {Object} options @return {Object} */ - ajaxOptions: function(url, type, options) { + ajaxOptions(url, type, options) { var hash = options || {}; hash.url = url; hash.type = type; @@ -892,7 +892,7 @@ export default Adapter.extend(BuildURLMixin, { @param {String} responseText @return {Object} */ - parseErrorResponse: function(responseText) { + parseErrorResponse(responseText) { var json = responseText; try { @@ -910,7 +910,7 @@ export default Adapter.extend(BuildURLMixin, { @param {Object} payload @return {Object} errors payload */ - normalizeErrorResponse: function(status, headers, payload) { + normalizeErrorResponse(status, headers, payload) { if (payload && typeof payload === 'object' && payload.errors) { return payload.errors; } else { diff --git a/addon/serializers/embedded-records-mixin.js b/addon/serializers/embedded-records-mixin.js index 8cb8f4f6d71..bd55be8064e 100644 --- a/addon/serializers/embedded-records-mixin.js +++ b/addon/serializers/embedded-records-mixin.js @@ -122,12 +122,12 @@ export default Ember.Mixin.create({ @param {String} prop the hash has been referenced by @return {Object} the normalized hash **/ - normalize: function(typeClass, hash, prop) { + normalize(typeClass, hash, prop) { var normalizedHash = this._super(typeClass, hash, prop); return this._extractEmbeddedRecords(this, this.store, typeClass, normalizedHash); }, - keyForRelationship: function(key, typeClass, method) { + keyForRelationship(key, typeClass, method) { if ((method === 'serialize' && this.hasSerializeRecordsOption(key)) || (method === 'deserialize' && this.hasDeserializeRecordsOption(key))) { return this.keyForAttribute(key, method); @@ -187,7 +187,7 @@ export default Ember.Mixin.create({ @param {Object} json @param {Object} relationship */ - serializeBelongsTo: function(snapshot, json, relationship) { + serializeBelongsTo(snapshot, json, relationship) { var attr = relationship.key; if (this.noSerializeOptionSpecified(attr)) { this._super(snapshot, json, relationship); @@ -213,7 +213,7 @@ export default Ember.Mixin.create({ } }, - _serializeEmbeddedBelongsTo: function(snapshot, json, relationship) { + _serializeEmbeddedBelongsTo(snapshot, json, relationship) { let embeddedSnapshot = snapshot.belongsTo(relationship.key); let serializedKey = this.keyForAttribute(relationship.key, 'serialize'); if (!embeddedSnapshot) { @@ -313,7 +313,7 @@ export default Ember.Mixin.create({ @param {Object} json @param {Object} relationship */ - serializeHasMany: function(snapshot, json, relationship) { + serializeHasMany(snapshot, json, relationship) { var attr = relationship.key; if (this.noSerializeOptionSpecified(attr)) { this._super(snapshot, json, relationship); @@ -329,7 +329,7 @@ export default Ember.Mixin.create({ } }, - _serializeEmbeddedHasMany: function(snapshot, json, relationship) { + _serializeEmbeddedHasMany(snapshot, json, relationship) { let serializedKey = this.keyForAttribute(relationship.key, 'serialize'); Ember.warn( @@ -344,7 +344,7 @@ export default Ember.Mixin.create({ /* Returns an array of embedded records serialized to JSON */ - _generateSerializedHasMany: function(snapshot, relationship) { + _generateSerializedHasMany(snapshot, relationship) { let hasMany = snapshot.hasMany(relationship.key); return Ember.A(hasMany).map((embeddedSnapshot) => { var embeddedJson = embeddedSnapshot.record.serialize({ includeId: true }); @@ -369,7 +369,7 @@ export default Ember.Mixin.create({ @param {Object} relationship @param {Object} json */ - removeEmbeddedForeignKey: function (snapshot, embeddedSnapshot, relationship, json) { + removeEmbeddedForeignKey(snapshot, embeddedSnapshot, relationship, json) { if (relationship.kind === 'hasMany') { return; } else if (relationship.kind === 'belongsTo') { @@ -386,26 +386,26 @@ export default Ember.Mixin.create({ }, // checks config for attrs option to embedded (always) - serialize and deserialize - hasEmbeddedAlwaysOption: function (attr) { + hasEmbeddedAlwaysOption(attr) { var option = this.attrsOption(attr); return option && option.embedded === 'always'; }, // checks config for attrs option to serialize ids - hasSerializeRecordsOption: function(attr) { + hasSerializeRecordsOption(attr) { var alwaysEmbed = this.hasEmbeddedAlwaysOption(attr); var option = this.attrsOption(attr); return alwaysEmbed || (option && (option.serialize === 'records')); }, // checks config for attrs option to serialize records - hasSerializeIdsOption: function(attr) { + hasSerializeIdsOption(attr) { var option = this.attrsOption(attr); return option && (option.serialize === 'ids' || option.serialize === 'id'); }, // checks config for attrs option to serialize records - noSerializeOptionSpecified: function(attr) { + noSerializeOptionSpecified(attr) { var option = this.attrsOption(attr); return !(option && (option.serialize || option.embedded)); }, @@ -413,13 +413,13 @@ export default Ember.Mixin.create({ // checks config for attrs option to deserialize records // a defined option object for a resource is treated the same as // `deserialize: 'records'` - hasDeserializeRecordsOption: function(attr) { + hasDeserializeRecordsOption(attr) { var alwaysEmbed = this.hasEmbeddedAlwaysOption(attr); var option = this.attrsOption(attr); return alwaysEmbed || (option && option.deserialize === 'records'); }, - attrsOption: function(attr) { + attrsOption(attr) { var attrs = this.get('attrs'); return attrs && (attrs[camelize(attr)] || attrs[attr]); }, @@ -428,7 +428,7 @@ export default Ember.Mixin.create({ @method _extractEmbeddedRecords @private */ - _extractEmbeddedRecords: function(serializer, store, typeClass, partial) { + _extractEmbeddedRecords(serializer, store, typeClass, partial) { typeClass.eachRelationship((key, relationship) => { if (serializer.hasDeserializeRecordsOption(key)) { if (relationship.kind === "hasMany") { @@ -446,7 +446,7 @@ export default Ember.Mixin.create({ @method _extractEmbeddedHasMany @private */ - _extractEmbeddedHasMany: function(store, key, hash, relationshipMeta) { + _extractEmbeddedHasMany(store, key, hash, relationshipMeta) { let relationshipHash = get(hash, `data.relationships.${key}.data`); if (!relationshipHash) { return; @@ -471,7 +471,7 @@ export default Ember.Mixin.create({ @method _extractEmbeddedBelongsTo @private */ - _extractEmbeddedBelongsTo: function(store, key, hash, relationshipMeta) { + _extractEmbeddedBelongsTo(store, key, hash, relationshipMeta) { let relationshipHash = get(hash, `data.relationships.${key}.data`); if (!relationshipHash) { return; @@ -494,7 +494,7 @@ export default Ember.Mixin.create({ @method _normalizeEmbeddedRelationship @private */ - _normalizeEmbeddedRelationship: function(store, relationshipMeta, relationshipHash) { + _normalizeEmbeddedRelationship(store, relationshipMeta, relationshipHash) { let modelName = relationshipMeta.type; if (relationshipMeta.options.polymorphic) { modelName = relationshipHash.type; diff --git a/addon/serializers/json-api-serializer.js b/addon/serializers/json-api-serializer.js index 8b53ea568c5..1162ecebd95 100644 --- a/addon/serializers/json-api-serializer.js +++ b/addon/serializers/json-api-serializer.js @@ -102,7 +102,7 @@ const JSONAPISerializer = JSONSerializer.extend({ @return {Object} @private */ - _normalizeDocumentHelper: function(documentHash) { + _normalizeDocumentHelper(documentHash) { if (Ember.typeOf(documentHash.data) === 'object') { documentHash.data = this._normalizeResourceHelper(documentHash.data); @@ -123,7 +123,7 @@ const JSONAPISerializer = JSONSerializer.extend({ @return {Object} @private */ - _normalizeRelationshipDataHelper: function(relationshipDataHash) { + _normalizeRelationshipDataHelper(relationshipDataHash) { let type = this.modelNameFromPayloadKey(relationshipDataHash.type); relationshipDataHash.type = type; return relationshipDataHash; @@ -135,7 +135,7 @@ const JSONAPISerializer = JSONSerializer.extend({ @return {Object} @private */ - _normalizeResourceHelper: function(resourceHash) { + _normalizeResourceHelper(resourceHash) { Ember.assert(this.warnMessageForUndefinedType(), !Ember.isNone(resourceHash.type), { id: 'ds.serializer.type-is-undefined' }); @@ -160,7 +160,7 @@ const JSONAPISerializer = JSONSerializer.extend({ @param {DS.Store} store @param {Object} payload */ - pushPayload: function(store, payload) { + pushPayload(store, payload) { let normalizedPayload = this._normalizeDocumentHelper(payload); store.push(normalizedPayload); }, @@ -176,7 +176,7 @@ const JSONAPISerializer = JSONSerializer.extend({ @return {Object} JSON-API Document @private */ - _normalizeResponse: function(store, primaryModelClass, payload, id, requestType, isSingle) { + _normalizeResponse(store, primaryModelClass, payload, id, requestType, isSingle) { let normalizedPayload = this._normalizeDocumentHelper(payload); return normalizedPayload; }, @@ -187,7 +187,7 @@ const JSONAPISerializer = JSONSerializer.extend({ @param {Object} resourceHash @return {Object} */ - extractAttributes: function(modelClass, resourceHash) { + extractAttributes(modelClass, resourceHash) { var attributes = {}; if (resourceHash.attributes) { @@ -207,7 +207,7 @@ const JSONAPISerializer = JSONSerializer.extend({ @param {Object} relationshipHash @return {Object} */ - extractRelationship: function(relationshipHash) { + extractRelationship(relationshipHash) { if (Ember.typeOf(relationshipHash.data) === 'object') { relationshipHash.data = this._normalizeRelationshipDataHelper(relationshipHash.data); @@ -226,7 +226,7 @@ const JSONAPISerializer = JSONSerializer.extend({ @param {Object} resourceHash @return {Object} */ - extractRelationships: function(modelClass, resourceHash) { + extractRelationships(modelClass, resourceHash) { let relationships = {}; if (resourceHash.relationships) { @@ -251,7 +251,7 @@ const JSONAPISerializer = JSONSerializer.extend({ @return {String} @private */ - _extractType: function(modelClass, resourceHash) { + _extractType(modelClass, resourceHash) { return this.modelNameFromPayloadKey(resourceHash.type); }, @@ -260,7 +260,7 @@ const JSONAPISerializer = JSONSerializer.extend({ @param {String} key @return {String} the model's modelName */ - modelNameFromPayloadKey: function(key) { + modelNameFromPayloadKey(key) { return singularize(normalizeModelName(key)); }, @@ -269,7 +269,7 @@ const JSONAPISerializer = JSONSerializer.extend({ @param {String} modelName @return {String} */ - payloadKeyFromModelName: function(modelName) { + payloadKeyFromModelName(modelName) { return pluralize(modelName); }, @@ -279,7 +279,7 @@ const JSONAPISerializer = JSONSerializer.extend({ @param {Object} resourceHash the resource hash from the adapter @return {Object} the normalized resource hash */ - normalize: function(modelClass, resourceHash) { + normalize(modelClass, resourceHash) { if (resourceHash.attributes) { this.normalizeUsingDeclaredMapping(modelClass, resourceHash.attributes); } @@ -326,7 +326,7 @@ const JSONAPISerializer = JSONSerializer.extend({ @param {String} method @return {String} normalized key */ - keyForAttribute: function(key, method) { + keyForAttribute(key, method) { return dasherize(key); }, @@ -356,7 +356,7 @@ const JSONAPISerializer = JSONSerializer.extend({ @param {String} method @return {String} normalized key */ - keyForRelationship: function(key, typeClass, method) { + keyForRelationship(key, typeClass, method) { return dasherize(key); }, @@ -366,7 +366,7 @@ const JSONAPISerializer = JSONSerializer.extend({ @param {Object} options @return {Object} json */ - serialize: function(snapshot, options) { + serialize(snapshot, options) { let data = this._super(...arguments); data.type = this.payloadKeyFromModelName(snapshot.modelName); return { data }; @@ -379,7 +379,7 @@ const JSONAPISerializer = JSONSerializer.extend({ @param {String} key @param {Object} attribute */ - serializeAttribute: function(snapshot, json, key, attribute) { + serializeAttribute(snapshot, json, key, attribute) { const type = attribute.type; if (this._canSerialize(key)) { @@ -407,7 +407,7 @@ const JSONAPISerializer = JSONSerializer.extend({ @param {Object} json @param {Object} relationship */ - serializeBelongsTo: function(snapshot, json, relationship) { + serializeBelongsTo(snapshot, json, relationship) { var key = relationship.key; if (this._canSerialize(key)) { @@ -440,7 +440,7 @@ const JSONAPISerializer = JSONSerializer.extend({ @param {Object} json @param {Object} relationship */ - serializeHasMany: function(snapshot, json, relationship) { + serializeHasMany(snapshot, json, relationship) { var key = relationship.key; if (this._shouldSerializeHasMany(snapshot, key, relationship)) { @@ -469,10 +469,10 @@ const JSONAPISerializer = JSONSerializer.extend({ Ember.runInDebug(function() { JSONAPISerializer.reopen({ - warnMessageForUndefinedType: function() { + warnMessageForUndefinedType() { return 'Encountered a resource object with an undefined type (resolved resource using ' + this.constructor.toString() + ')'; }, - warnMessageNoModelForType: function(modelName, originalType) { + warnMessageNoModelForType(modelName, originalType) { return 'Encountered a resource object with type "' + originalType + '", but no model was found for model name "' + modelName + '" (resolved model name using ' + this.constructor.toString() + '.modelNameFromPayloadKey("' + originalType + '"))'; } }); diff --git a/addon/serializers/json-serializer.js b/addon/serializers/json-serializer.js index 22552cf1b98..69299ccf236 100644 --- a/addon/serializers/json-serializer.js +++ b/addon/serializers/json-serializer.js @@ -182,7 +182,7 @@ export default Serializer.extend({ @param {Object} data The data to transform @return {Object} data The transformed data object */ - applyTransforms: function(typeClass, data) { + applyTransforms(typeClass, data) { typeClass.eachTransformedAttribute((key, typeClass) => { if (!data.hasOwnProperty(key)) { return; } @@ -227,7 +227,7 @@ export default Serializer.extend({ @param {String} requestType @return {Object} JSON-API Document */ - normalizeResponse: function(store, primaryModelClass, payload, id, requestType) { + normalizeResponse(store, primaryModelClass, payload, id, requestType) { switch (requestType) { case 'findRecord': return this.normalizeFindRecordResponse(...arguments); @@ -261,7 +261,7 @@ export default Serializer.extend({ @param {String} requestType @return {Object} JSON-API Document */ - normalizeFindRecordResponse: function(store, primaryModelClass, payload, id, requestType) { + normalizeFindRecordResponse(store, primaryModelClass, payload, id, requestType) { return this.normalizeSingleResponse(...arguments); }, @@ -274,7 +274,7 @@ export default Serializer.extend({ @param {String} requestType @return {Object} JSON-API Document */ - normalizeQueryRecordResponse: function(store, primaryModelClass, payload, id, requestType) { + normalizeQueryRecordResponse(store, primaryModelClass, payload, id, requestType) { return this.normalizeSingleResponse(...arguments); }, @@ -287,7 +287,7 @@ export default Serializer.extend({ @param {String} requestType @return {Object} JSON-API Document */ - normalizeFindAllResponse: function(store, primaryModelClass, payload, id, requestType) { + normalizeFindAllResponse(store, primaryModelClass, payload, id, requestType) { return this.normalizeArrayResponse(...arguments); }, @@ -300,7 +300,7 @@ export default Serializer.extend({ @param {String} requestType @return {Object} JSON-API Document */ - normalizeFindBelongsToResponse: function(store, primaryModelClass, payload, id, requestType) { + normalizeFindBelongsToResponse(store, primaryModelClass, payload, id, requestType) { return this.normalizeSingleResponse(...arguments); }, @@ -313,7 +313,7 @@ export default Serializer.extend({ @param {String} requestType @return {Object} JSON-API Document */ - normalizeFindHasManyResponse: function(store, primaryModelClass, payload, id, requestType) { + normalizeFindHasManyResponse(store, primaryModelClass, payload, id, requestType) { return this.normalizeArrayResponse(...arguments); }, @@ -326,7 +326,7 @@ export default Serializer.extend({ @param {String} requestType @return {Object} JSON-API Document */ - normalizeFindManyResponse: function(store, primaryModelClass, payload, id, requestType) { + normalizeFindManyResponse(store, primaryModelClass, payload, id, requestType) { return this.normalizeArrayResponse(...arguments); }, @@ -339,7 +339,7 @@ export default Serializer.extend({ @param {String} requestType @return {Object} JSON-API Document */ - normalizeQueryResponse: function(store, primaryModelClass, payload, id, requestType) { + normalizeQueryResponse(store, primaryModelClass, payload, id, requestType) { return this.normalizeArrayResponse(...arguments); }, @@ -352,7 +352,7 @@ export default Serializer.extend({ @param {String} requestType @return {Object} JSON-API Document */ - normalizeCreateRecordResponse: function(store, primaryModelClass, payload, id, requestType) { + normalizeCreateRecordResponse(store, primaryModelClass, payload, id, requestType) { return this.normalizeSaveResponse(...arguments); }, @@ -365,7 +365,7 @@ export default Serializer.extend({ @param {String} requestType @return {Object} JSON-API Document */ - normalizeDeleteRecordResponse: function(store, primaryModelClass, payload, id, requestType) { + normalizeDeleteRecordResponse(store, primaryModelClass, payload, id, requestType) { return this.normalizeSaveResponse(...arguments); }, @@ -378,7 +378,7 @@ export default Serializer.extend({ @param {String} requestType @return {Object} JSON-API Document */ - normalizeUpdateRecordResponse: function(store, primaryModelClass, payload, id, requestType) { + normalizeUpdateRecordResponse(store, primaryModelClass, payload, id, requestType) { return this.normalizeSaveResponse(...arguments); }, @@ -391,7 +391,7 @@ export default Serializer.extend({ @param {String} requestType @return {Object} JSON-API Document */ - normalizeSaveResponse: function(store, primaryModelClass, payload, id, requestType) { + normalizeSaveResponse(store, primaryModelClass, payload, id, requestType) { return this.normalizeSingleResponse(...arguments); }, @@ -404,7 +404,7 @@ export default Serializer.extend({ @param {String} requestType @return {Object} JSON-API Document */ - normalizeSingleResponse: function(store, primaryModelClass, payload, id, requestType) { + normalizeSingleResponse(store, primaryModelClass, payload, id, requestType) { return this._normalizeResponse(store, primaryModelClass, payload, id, requestType, true); }, @@ -417,7 +417,7 @@ export default Serializer.extend({ @param {String} requestType @return {Object} JSON-API Document */ - normalizeArrayResponse: function(store, primaryModelClass, payload, id, requestType) { + normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) { return this._normalizeResponse(store, primaryModelClass, payload, id, requestType, false); }, @@ -432,7 +432,7 @@ export default Serializer.extend({ @return {Object} JSON-API Document @private */ - _normalizeResponse: function(store, primaryModelClass, payload, id, requestType, isSingle) { + _normalizeResponse(store, primaryModelClass, payload, id, requestType, isSingle) { let documentHash = { data: null, included: [] @@ -501,7 +501,7 @@ export default Serializer.extend({ @param {Object} hash @return {Object} */ - normalize: function(modelClass, resourceHash) { + normalize(modelClass, resourceHash) { let data = null; if (resourceHash) { @@ -528,7 +528,7 @@ export default Serializer.extend({ @param {Object} resourceHash @return {String} */ - extractId: function(modelClass, resourceHash) { + extractId(modelClass, resourceHash) { var primaryKey = get(this, 'primaryKey'); var id = resourceHash[primaryKey]; return coerceId(id); @@ -544,7 +544,7 @@ export default Serializer.extend({ @param {Object} resourceHash @return {Object} */ - extractAttributes: function(modelClass, resourceHash) { + extractAttributes(modelClass, resourceHash) { var attributeKey; var attributes = {}; @@ -568,7 +568,7 @@ export default Serializer.extend({ @param {Object} relationshipHash @return {Object} */ - extractRelationship: function(relationshipModelName, relationshipHash) { + extractRelationship(relationshipModelName, relationshipHash) { if (Ember.isNone(relationshipHash)) { return null; } /* When `relationshipHash` is an object it usually means that the relationship @@ -608,7 +608,7 @@ export default Serializer.extend({ @param {Object} relationshipOptions @return {Object} */ - extractPolymorphicRelationship: function(relationshipModelName, relationshipHash, relationshipOptions) { + extractPolymorphicRelationship(relationshipModelName, relationshipHash, relationshipOptions) { return this.extractRelationship(relationshipModelName, relationshipHash); }, @@ -622,7 +622,7 @@ export default Serializer.extend({ @param {Object} resourceHash @return {Object} */ - extractRelationships: function(modelClass, resourceHash) { + extractRelationships(modelClass, resourceHash) { let relationships = {}; modelClass.eachRelationship((key, relationshipMeta) => { @@ -667,7 +667,7 @@ export default Serializer.extend({ @param {String} key @return {String} the model's modelName */ - modelNameFromPayloadKey: function(key) { + modelNameFromPayloadKey(key) { return normalizeModelName(key); }, @@ -676,7 +676,7 @@ export default Serializer.extend({ @method normalizeAttributes @private */ - normalizeAttributes: function(typeClass, hash) { + normalizeAttributes(typeClass, hash) { var payloadKey; if (this.keyForAttribute) { @@ -695,7 +695,7 @@ export default Serializer.extend({ @method normalizeRelationships @private */ - normalizeRelationships: function(typeClass, hash) { + normalizeRelationships(typeClass, hash) { var payloadKey; if (this.keyForRelationship) { @@ -714,7 +714,7 @@ export default Serializer.extend({ @method normalizeUsingDeclaredMapping @private */ - normalizeUsingDeclaredMapping: function(modelClass, hash) { + normalizeUsingDeclaredMapping(modelClass, hash) { var attrs = get(this, 'attrs'); var payloadKey, normalizedKey, key; @@ -749,7 +749,7 @@ export default Serializer.extend({ @param {String} key @return {String} key */ - _getMappedKey: function(key, modelClass) { + _getMappedKey(key, modelClass) { Ember.warn('There is no attribute or relationship with the name `' + key + '` on `' + modelClass.modelName + '`. Check your serializers attrs hash.', get(modelClass, 'attributes').has(key) || get(modelClass, 'relationshipsByName').has(key), { id: 'ds.serializer.no-mapped-attrs-key' }); @@ -780,7 +780,7 @@ export default Serializer.extend({ @param {String} key @return {boolean} true if the key can be serialized */ - _canSerialize: function(key) { + _canSerialize(key) { var attrs = get(this, 'attrs'); return !attrs || !attrs[key] || attrs[key].serialize !== false; @@ -796,7 +796,7 @@ export default Serializer.extend({ @param {String} key @return {boolean} true if the key must be serialized */ - _mustSerialize: function(key) { + _mustSerialize(key) { var attrs = get(this, 'attrs'); return attrs && attrs[key] && attrs[key].serialize === true; @@ -812,7 +812,7 @@ export default Serializer.extend({ @param {String} relationshipType @return {boolean} true if the hasMany relationship should be serialized */ - _shouldSerializeHasMany: function (snapshot, key, relationship) { + _shouldSerializeHasMany(snapshot, key, relationship) { var relationshipType = snapshot.type.determineRelationshipType(relationship, this.store); if (this._mustSerialize(key)) { return true; @@ -973,7 +973,7 @@ export default Serializer.extend({ @param {Object} options @return {Object} json */ - serialize: function(snapshot, options) { + serialize(snapshot, options) { var json = {}; if (options && options.includeId) { @@ -1025,7 +1025,7 @@ export default Serializer.extend({ @param {DS.Snapshot} snapshot @param {Object} options */ - serializeIntoHash: function(hash, typeClass, snapshot, options) { + serializeIntoHash(hash, typeClass, snapshot, options) { merge(hash, this.serialize(snapshot, options)); }, @@ -1054,7 +1054,7 @@ export default Serializer.extend({ @param {String} key @param {Object} attribute */ - serializeAttribute: function(snapshot, json, key, attribute) { + serializeAttribute(snapshot, json, key, attribute) { var type = attribute.type; if (this._canSerialize(key)) { @@ -1103,7 +1103,7 @@ export default Serializer.extend({ @param {Object} json @param {Object} relationship */ - serializeBelongsTo: function(snapshot, json, relationship) { + serializeBelongsTo(snapshot, json, relationship) { var key = relationship.key; if (this._canSerialize(key)) { @@ -1155,7 +1155,7 @@ export default Serializer.extend({ @param {Object} json @param {Object} relationship */ - serializeHasMany: function(snapshot, json, relationship) { + serializeHasMany(snapshot, json, relationship) { var key = relationship.key; if (this._shouldSerializeHasMany(snapshot, key, relationship)) { @@ -1232,7 +1232,7 @@ export default Serializer.extend({ @param {DS.Model} modelClass @param {Object} payload */ - extractMeta: function(store, modelClass, payload) { + extractMeta(store, modelClass, payload) { if (payload && payload.hasOwnProperty('meta')) { let meta = payload.meta; delete payload.meta; @@ -1269,7 +1269,7 @@ export default Serializer.extend({ @param {(String|Number)} id @return {Object} json The deserialized errors */ - extractErrors: function(store, typeClass, payload, id) { + extractErrors(store, typeClass, payload, id) { if (payload && typeof payload === 'object' && payload.errors) { payload = errorsArrayToHash(payload.errors); @@ -1316,7 +1316,7 @@ export default Serializer.extend({ @param {String} method @return {String} normalized key */ - keyForAttribute: function(key, method) { + keyForAttribute(key, method) { return key; }, @@ -1343,7 +1343,7 @@ export default Serializer.extend({ @param {String} method @return {String} normalized key */ - keyForRelationship: function(key, typeClass, method) { + keyForRelationship(key, typeClass, method) { return key; }, @@ -1356,7 +1356,7 @@ export default Serializer.extend({ @param {String} kind `belongsTo` or `hasMany` @return {String} normalized key */ - keyForLink: function(key, kind) { + keyForLink(key, kind) { return key; }, @@ -1369,7 +1369,7 @@ export default Serializer.extend({ @param {Boolean} skipAssertion @return {DS.Transform} transform */ - transformFor: function(attributeType, skipAssertion) { + transformFor(attributeType, skipAssertion) { var transform = getOwner(this).lookup('transform:' + attributeType); Ember.assert("Unable to find transform for '" + attributeType + "'", skipAssertion || !!transform); diff --git a/addon/serializers/rest-serializer.js b/addon/serializers/rest-serializer.js index 256f0a1ce54..0b9325142a0 100644 --- a/addon/serializers/rest-serializer.js +++ b/addon/serializers/rest-serializer.js @@ -80,7 +80,7 @@ var RESTSerializer = JSONSerializer.extend({ @param {String} method @return {String} normalized key */ - keyForPolymorphicType: function(key, typeClass, method) { + keyForPolymorphicType(key, typeClass, method) { var relationshipKey = this.keyForRelationship(key); return `${relationshipKey}Type`; @@ -152,7 +152,7 @@ var RESTSerializer = JSONSerializer.extend({ @param {String} prop @return {Object} */ - normalize: function(modelClass, resourceHash, prop) { + normalize(modelClass, resourceHash, prop) { if (this.normalizeHash && this.normalizeHash[prop]) { this.normalizeHash[prop](resourceHash); } @@ -171,7 +171,7 @@ var RESTSerializer = JSONSerializer.extend({ @return {Object} @private */ - _normalizeArray: function(store, modelName, arrayHash, prop) { + _normalizeArray(store, modelName, arrayHash, prop) { let documentHash = { data: [], included: [] @@ -192,7 +192,7 @@ var RESTSerializer = JSONSerializer.extend({ return documentHash; }, - _normalizePolymorphicRecord: function(store, hash, prop, primaryModelClass, primarySerializer) { + _normalizePolymorphicRecord(store, hash, prop, primaryModelClass, primarySerializer) { let serializer, modelClass; const primaryHasTypeAttribute = modelHasAttributeOrRelationshipNamedType(primaryModelClass); // Support polymorphic records in async relationships @@ -217,7 +217,7 @@ var RESTSerializer = JSONSerializer.extend({ @return {Object} JSON-API Document @private */ - _normalizeResponse: function(store, primaryModelClass, payload, id, requestType, isSingle) { + _normalizeResponse(store, primaryModelClass, payload, id, requestType, isSingle) { let documentHash = { data: null, included: [] @@ -338,7 +338,7 @@ var RESTSerializer = JSONSerializer.extend({ return documentHash; }, - isPrimaryType: function(store, typeName, primaryTypeClass) { + isPrimaryType(store, typeName, primaryTypeClass) { var typeClass = store.modelFor(typeName); return typeClass.modelName === primaryTypeClass.modelName; }, @@ -374,7 +374,7 @@ var RESTSerializer = JSONSerializer.extend({ @param {DS.Store} store @param {Object} payload */ - pushPayload: function(store, payload) { + pushPayload(store, payload) { let documentHash = { data: [], included: [] @@ -462,7 +462,7 @@ var RESTSerializer = JSONSerializer.extend({ @param {String} key @return {String} the model's modelName */ - modelNameFromPayloadKey: function(key) { + modelNameFromPayloadKey(key) { return singularize(normalizeModelName(key)); }, @@ -619,7 +619,7 @@ var RESTSerializer = JSONSerializer.extend({ @param {Object} options @return {Object} json */ - serialize: function(snapshot, options) { + serialize(snapshot, options) { return this._super(...arguments); }, @@ -647,7 +647,7 @@ var RESTSerializer = JSONSerializer.extend({ @param {DS.Snapshot} snapshot @param {Object} options */ - serializeIntoHash: function(hash, typeClass, snapshot, options) { + serializeIntoHash(hash, typeClass, snapshot, options) { var normalizedRootKey = this.payloadKeyFromModelName(typeClass.modelName); hash[normalizedRootKey] = this.serialize(snapshot, options); }, @@ -697,7 +697,7 @@ var RESTSerializer = JSONSerializer.extend({ @param {String} modelName @return {String} */ - payloadKeyFromModelName: function(modelName) { + payloadKeyFromModelName(modelName) { return camelize(modelName); }, @@ -711,7 +711,7 @@ var RESTSerializer = JSONSerializer.extend({ @param {Object} json @param {Object} relationship */ - serializePolymorphicType: function(snapshot, json, relationship) { + serializePolymorphicType(snapshot, json, relationship) { var key = relationship.key; var belongsTo = snapshot.belongsTo(key); var typeKey = this.keyForPolymorphicType(key, relationship.type, 'serialize'); @@ -751,7 +751,7 @@ var RESTSerializer = JSONSerializer.extend({ @param {Object} relationshipOptions @return {Object} */ - extractPolymorphicRelationship: function(relationshipType, relationshipHash, relationshipOptions) { + extractPolymorphicRelationship(relationshipType, relationshipHash, relationshipOptions) { var { key, resourceHash, relationshipMeta } = relationshipOptions; // A polymorphic belongsTo relationship can be present in the payload @@ -788,7 +788,7 @@ var RESTSerializer = JSONSerializer.extend({ Ember.runInDebug(function() { RESTSerializer.reopen({ - warnMessageNoModelForKey: function(prop, typeKey) { + warnMessageNoModelForKey(prop, typeKey) { return 'Encountered "' + prop + '" in payload, but no model was found for model name "' + typeKey + '" (resolved model name using ' + this.constructor.toString() + '.modelNameFromPayloadKey("' + prop + '"))'; } }); diff --git a/addon/system/adapter.js b/addon/system/adapter.js index 79a5c418449..a9f1306a677 100644 --- a/addon/system/adapter.js +++ b/addon/system/adapter.js @@ -279,7 +279,7 @@ export default Ember.Object.extend({ @param {Object} options @return {Object} serialized snapshot */ - serialize: function(snapshot, options) { + serialize(snapshot, options) { return get(snapshot.record, 'store').serializerFor(snapshot.modelName).serialize(snapshot, options); }, @@ -454,7 +454,7 @@ export default Ember.Object.extend({ @return {Array} an array of arrays of records, each of which is to be loaded separately by `findMany`. */ - groupRecordsForFindMany: function(store, snapshots) { + groupRecordsForFindMany(store, snapshots) { return [snapshots]; }, @@ -473,7 +473,7 @@ export default Ember.Object.extend({ @param {DS.Snapshot} snapshot @return {Boolean} */ - shouldReloadRecord: function(store, snapshot) { + shouldReloadRecord(store, snapshot) { return false; }, @@ -491,7 +491,7 @@ export default Ember.Object.extend({ @param {DS.SnapshotRecordArray} snapshotRecordArray @return {Boolean} */ - shouldReloadAll: function(store, snapshotRecordArray) { + shouldReloadAll(store, snapshotRecordArray) { return !snapshotRecordArray.length; }, @@ -511,7 +511,7 @@ export default Ember.Object.extend({ @param {DS.Snapshot} snapshot @return {Boolean} */ - shouldBackgroundReloadRecord: function(store, snapshot) { + shouldBackgroundReloadRecord(store, snapshot) { return true; }, @@ -531,7 +531,7 @@ export default Ember.Object.extend({ @param {DS.SnapshotRecordArray} snapshotRecordArray @return {Boolean} */ - shouldBackgroundReloadAll: function(store, snapshotRecordArray) { + shouldBackgroundReloadAll(store, snapshotRecordArray) { return true; } }); diff --git a/addon/system/debug/debug-adapter.js b/addon/system/debug/debug-adapter.js index f414a08cef5..fabed06a7aa 100644 --- a/addon/system/debug/debug-adapter.js +++ b/addon/system/debug/debug-adapter.js @@ -16,7 +16,7 @@ const { assert } = Ember; @private */ export default Ember.DataAdapter.extend({ - getFilters: function() { + getFilters() { return [ { name: 'isNew', desc: 'New' }, { name: 'isModified', desc: 'Modified' }, @@ -24,11 +24,11 @@ export default Ember.DataAdapter.extend({ ]; }, - detect: function(typeClass) { + detect(typeClass) { return typeClass !== Model && Model.detect(typeClass); }, - columnsForType: function(typeClass) { + columnsForType(typeClass) { var columns = [{ name: 'id', desc: 'Id' @@ -43,7 +43,7 @@ export default Ember.DataAdapter.extend({ return columns; }, - getRecords: function(modelClass, modelName) { + getRecords(modelClass, modelName) { if (arguments.length < 2) { // Legacy Ember.js < 1.13 support let containerKey = modelClass._debugContainerKey; @@ -58,7 +58,7 @@ export default Ember.DataAdapter.extend({ return this.get('store').peekAll(modelName); }, - getRecordColumnValues: function(record) { + getRecordColumnValues(record) { var count = 0; var columnValues = { id: get(record, 'id') }; @@ -72,7 +72,7 @@ export default Ember.DataAdapter.extend({ return columnValues; }, - getRecordKeywords: function(record) { + getRecordKeywords(record) { var keywords = []; var keys = Ember.A(['id']); record.eachAttribute((key) => keys.push(key)); @@ -80,7 +80,7 @@ export default Ember.DataAdapter.extend({ return keywords; }, - getRecordFilterValues: function(record) { + getRecordFilterValues(record) { return { isNew: record.get('isNew'), isModified: record.get('hasDirtyAttributes') && !record.get('isNew'), @@ -88,7 +88,7 @@ export default Ember.DataAdapter.extend({ }; }, - getRecordColor: function(record) { + getRecordColor(record) { var color = 'black'; if (record.get('isNew')) { color = 'green'; @@ -98,7 +98,7 @@ export default Ember.DataAdapter.extend({ return color; }, - observeRecord: function(record, recordUpdated) { + observeRecord(record, recordUpdated) { var releaseMethods = Ember.A(); var keysToObserve = Ember.A(['id', 'isNew', 'hasDirtyAttributes']); diff --git a/addon/system/debug/debug-info.js b/addon/system/debug/debug-info.js index 573b8393a05..afd7009c4df 100644 --- a/addon/system/debug/debug-info.js +++ b/addon/system/debug/debug-info.js @@ -18,7 +18,7 @@ Model.reopen({ @for DS.Model @private */ - _debugInfo: function() { + _debugInfo() { var attributes = ['id']; var relationships = { belongsTo: [], hasMany: [] }; var expensiveProperties = []; diff --git a/addon/system/many-array.js b/addon/system/many-array.js index 140a0a46ded..2bf8b5bd300 100644 --- a/addon/system/many-array.js +++ b/addon/system/many-array.js @@ -50,7 +50,7 @@ var set = Ember.set; @uses Ember.MutableArray, Ember.Evented */ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, { - init: function() { + init() { this._super(...arguments); this.currentState = Ember.A([]); }, @@ -62,7 +62,7 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, { length: 0, - objectAt: function(index) { + objectAt(index) { //Ember observers such as 'firstObject', 'lastObject' might do out of bounds accesses if (!this.currentState[index]) { return undefined; @@ -70,7 +70,7 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, { return this.currentState[index].getRecord(); }, - flushCanonical: function() { + flushCanonical() { //TODO make this smarter, currently its plenty stupid var toSet = this.canonicalState.filter((internalModel) => !internalModel.isDeleted()); @@ -150,7 +150,7 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, { */ meta: null, - internalReplace: function(idx, amt, objects) { + internalReplace(idx, amt, objects) { if (!objects) { objects = []; } @@ -166,7 +166,7 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, { }, //TODO(Igor) optimize - internalRemoveRecords: function(records) { + internalRemoveRecords(records) { var index; for (var i=0; i < records.length; i++) { index = this.currentState.indexOf(records[i]); @@ -175,14 +175,14 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, { }, //TODO(Igor) optimize - internalAddRecords: function(records, idx) { + internalAddRecords(records, idx) { if (idx === undefined) { idx = this.currentState.length; } this.internalReplace(idx, 0, records); }, - replace: function(idx, amt, objects) { + replace(idx, amt, objects) { var records; if (amt > 0) { records = this.currentState.slice(idx, idx+amt); @@ -206,7 +206,7 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, { @param {Number} count @private */ - loadingRecordsCount: function(count) { + loadingRecordsCount(count) { this.loadingRecordsCount = count; }, @@ -214,7 +214,7 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, { @method loadedRecord @private */ - loadedRecord: function() { + loadedRecord() { this.loadingRecordsCount--; if (this.loadingRecordsCount === 0) { set(this, 'isLoaded', true); @@ -226,7 +226,7 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, { @method reload @public */ - reload: function() { + reload() { return this.relationship.reload(); }, @@ -249,7 +249,7 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, { @method save @return {DS.PromiseArray} promise */ - save: function() { + save() { var manyArray = this; var promiseLabel = "DS: ManyArray#save " + get(this, 'type'); var promise = Ember.RSVP.all(this.invoke("save"), promiseLabel).then(function(array) { @@ -267,7 +267,7 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, { @param {Object} hash @return {DS.Model} record */ - createRecord: function(hash) { + createRecord(hash) { var store = get(this, 'store'); var type = get(this, 'type'); var record; diff --git a/addon/system/model/attributes.js b/addon/system/model/attributes.js index fe00babe6c9..8437ef103fe 100644 --- a/addon/system/model/attributes.js +++ b/addon/system/model/attributes.js @@ -158,7 +158,7 @@ Model.reopenClass({ @param {Object} [binding] the value to which the callback's `this` should be bound @static */ - eachAttribute: function(callback, binding) { + eachAttribute(callback, binding) { get(this, 'attributes').forEach((meta, name) => { callback.call(binding, name, meta); }); @@ -208,7 +208,7 @@ Model.reopenClass({ @param {Object} [binding] the value to which the callback's `this` should be bound @static */ - eachTransformedAttribute: function(callback, binding) { + eachTransformedAttribute(callback, binding) { get(this, 'transformedAttributes').forEach((type, name) => { callback.call(binding, name, type); }); @@ -217,7 +217,7 @@ Model.reopenClass({ Model.reopen({ - eachAttribute: function(callback, binding) { + eachAttribute(callback, binding) { this.constructor.eachAttribute(callback, binding); } }); @@ -318,7 +318,7 @@ export default function attr(type, options) { }; return Ember.computed({ - get: function(key) { + get(key) { var internalModel = this._internalModel; if (hasValue(internalModel, key)) { return getValue(internalModel, key); @@ -326,7 +326,7 @@ export default function attr(type, options) { return getDefaultValue(this, options, key); } }, - set: function(key, value) { + set(key, value) { var internalModel = this._internalModel; var oldValue = getValue(internalModel, key); diff --git a/addon/system/model/errors.js b/addon/system/model/errors.js index 1d11f6e0a60..4e26a004f1c 100644 --- a/addon/system/model/errors.js +++ b/addon/system/model/errors.js @@ -109,7 +109,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @param {Function} becameValid @deprecated */ - registerHandlers: function(target, becameInvalid, becameValid) { + registerHandlers(target, becameInvalid, becameValid) { Ember.deprecate( `Record errors will no longer be evented.`, false, { id: 'ds.errors.registerHandlers', @@ -126,7 +126,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @method _registerHandlers @private */ - _registerHandlers: function(target, becameInvalid, becameValid) { + _registerHandlers(target, becameInvalid, becameValid) { this.on('becameInvalid', target, becameInvalid); this.on('becameValid', target, becameValid); }, @@ -139,7 +139,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { */ errorsByAttributeName: Ember.computed(function() { return MapWithDefault.create({ - defaultValue: function() { + defaultValue() { return Ember.A(); } }); @@ -163,7 +163,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @param {String} attribute @return {Array} */ - errorsFor: function(attribute) { + errorsFor(attribute) { return get(this, 'errorsByAttributeName').get(attribute); }, @@ -197,7 +197,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @method unknownProperty @private */ - unknownProperty: function(attribute) { + unknownProperty(attribute) { var errors = this.errorsFor(attribute); if (isEmpty(errors)) { return null; } return errors; @@ -235,7 +235,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @param {(Array|String)} messages @deprecated */ - add: function(attribute, messages) { + add(attribute, messages) { Ember.warn(`Interacting with a record errors object will no longer change the record state.`, false, { id: 'ds.errors.add' }); @@ -256,7 +256,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @method _add @private */ - _add: function(attribute, messages) { + _add(attribute, messages) { messages = this._findOrCreateMessages(attribute, messages); this.addObjects(messages); get(this, 'errorsByAttributeName').get(attribute).addObjects(messages); @@ -268,7 +268,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @method _findOrCreateMessages @private */ - _findOrCreateMessages: function(attribute, messages) { + _findOrCreateMessages(attribute, messages) { var errors = this.errorsFor(attribute); return makeArray(messages).map((message) => { @@ -314,7 +314,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @param {String} attribute @deprecated */ - remove: function(attribute) { + remove(attribute) { Ember.warn(`Interacting with a record errors object will no longer change the record state.`, false, { id: 'ds.errors.remove' }); @@ -334,7 +334,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @method _remove @private */ - _remove: function(attribute) { + _remove(attribute) { if (get(this, 'isEmpty')) { return; } let content = this.rejectBy('attribute', attribute); @@ -366,7 +366,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @method clear @deprecated */ - clear: function() { + clear() { Ember.warn(`Interacting with a record errors object will no longer change the record state.`, false, { id: 'ds.errors.clear' }); @@ -385,7 +385,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @method _clear @private */ - _clear: function() { + _clear() { if (get(this, 'isEmpty')) { return; } let errorsByAttributeName = get(this, 'errorsByAttributeName'); @@ -426,7 +426,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @param {String} attribute @return {Boolean} true if there some errors on given attribute */ - has: function(attribute) { + has(attribute) { return !isEmpty(this.errorsFor(attribute)); } }); diff --git a/addon/system/model/internal-model.js b/addon/system/model/internal-model.js index 1f4b30746b4..d87e97facb5 100644 --- a/addon/system/model/internal-model.js +++ b/addon/system/model/internal-model.js @@ -112,7 +112,7 @@ InternalModel.prototype = { dirtyType: retrieveFromCurrentState('dirtyType'), constructor: InternalModel, - materializeRecord: function() { + materializeRecord() { Ember.assert("Materialized " + this.modelName + " record with id:" + this.id + "more than once", this.record === null || this.record === undefined); // lookupFactory should really return an object that creates @@ -138,15 +138,15 @@ InternalModel.prototype = { this._triggerDeferredTriggers(); }, - recordObjectWillDestroy: function() { + recordObjectWillDestroy() { this.record = null; }, - deleteRecord: function() { + deleteRecord() { this.send('deleteRecord'); }, - save: function(options) { + save(options) { var promiseLabel = "DS: Model#save " + this; var resolver = Ember.RSVP.defer(promiseLabel); @@ -154,21 +154,21 @@ InternalModel.prototype = { return resolver.promise; }, - startedReloading: function() { + startedReloading() { this.isReloading = true; if (this.record) { set(this.record, 'isReloading', true); } }, - finishedReloading: function() { + finishedReloading() { this.isReloading = false; if (this.record) { set(this.record, 'isReloading', false); } }, - reload: function() { + reload() { this.startedReloading(); var record = this; var promiseLabel = "DS: Model#reload of " + this; @@ -186,30 +186,30 @@ InternalModel.prototype = { }); }, - getRecord: function() { + getRecord() { if (!this.record) { this.materializeRecord(); } return this.record; }, - unloadRecord: function() { + unloadRecord() { this.send('unloadRecord'); }, - eachRelationship: function(callback, binding) { + eachRelationship(callback, binding) { return this.type.eachRelationship(callback, binding); }, - eachAttribute: function(callback, binding) { + eachAttribute(callback, binding) { return this.type.eachAttribute(callback, binding); }, - inverseFor: function(key) { + inverseFor(key) { return this.type.inverseFor(key); }, - setupData: function(data) { + setupData(data) { var changedKeys = this._changedKeys(data.attributes); merge(this._data, data.attributes); this.pushedData(); @@ -219,18 +219,18 @@ InternalModel.prototype = { this.didInitalizeData(); }, - becameReady: function() { + becameReady() { Ember.run.schedule('actions', this.store.recordArrayManager, this.store.recordArrayManager.recordWasLoaded, this); }, - didInitalizeData: function() { + didInitalizeData() { if (!this.dataHasInitialized) { this.becameReady(); this.dataHasInitialized = true; } }, - destroy: function() { + destroy() { if (this.record) { return this.record.destroy(); } @@ -240,7 +240,7 @@ InternalModel.prototype = { @method createSnapshot @private */ - createSnapshot: function(options) { + createSnapshot(options) { var adapterOptions = options && options.adapterOptions; var snapshot = new Snapshot(this); snapshot.adapterOptions = adapterOptions; @@ -252,7 +252,7 @@ InternalModel.prototype = { @private @param {Promise} promise */ - loadingData: function(promise) { + loadingData(promise) { this.send('loadingData', promise); }, @@ -260,7 +260,7 @@ InternalModel.prototype = { @method loadedData @private */ - loadedData: function() { + loadedData() { this.send('loadedData'); this.didInitalizeData(); }, @@ -269,7 +269,7 @@ InternalModel.prototype = { @method notFound @private */ - notFound: function() { + notFound() { this.send('notFound'); }, @@ -277,16 +277,16 @@ InternalModel.prototype = { @method pushedData @private */ - pushedData: function() { + pushedData() { this.send('pushedData'); }, - flushChangedAttributes: function() { + flushChangedAttributes() { this._inFlightAttributes = this._attributes; this._attributes = new EmptyObject(); }, - hasChangedAttributes: function() { + hasChangedAttributes() { return Object.keys(this._attributes).length > 0; }, @@ -297,7 +297,7 @@ InternalModel.prototype = { This method is needed when data for the internal model is pushed and the pushed data might acknowledge dirty attributes as confirmed. */ - updateChangedAttributes: function() { + updateChangedAttributes() { var changedAttributes = this.changedAttributes(); var changedAttributeNames = Object.keys(changedAttributes); @@ -315,7 +315,7 @@ InternalModel.prototype = { Returns an object, whose keys are changed properties, and value is an [oldProp, newProp] array. */ - changedAttributes: function() { + changedAttributes() { var oldData = this._data; var currentData = this._attributes; var inFlightData = this._inFlightAttributes; @@ -336,7 +336,7 @@ InternalModel.prototype = { @method adapterWillCommit @private */ - adapterWillCommit: function() { + adapterWillCommit() { this.send('willCommit'); }, @@ -344,7 +344,7 @@ InternalModel.prototype = { @method adapterDidDirty @private */ - adapterDidDirty: function() { + adapterDidDirty() { this.send('becomeDirty'); this.updateRecordArraysLater(); }, @@ -355,7 +355,7 @@ InternalModel.prototype = { @param {String} name @param {Object} context */ - send: function(name, context) { + send(name, context) { var currentState = get(this, 'currentState'); if (!currentState[name]) { @@ -365,31 +365,31 @@ InternalModel.prototype = { return currentState[name](this, context); }, - notifyHasManyAdded: function(key, record, idx) { + notifyHasManyAdded(key, record, idx) { if (this.record) { this.record.notifyHasManyAdded(key, record, idx); } }, - notifyHasManyRemoved: function(key, record, idx) { + notifyHasManyRemoved(key, record, idx) { if (this.record) { this.record.notifyHasManyRemoved(key, record, idx); } }, - notifyBelongsToChanged: function(key, record) { + notifyBelongsToChanged(key, record) { if (this.record) { this.record.notifyBelongsToChanged(key, record); } }, - notifyPropertyChange: function(key) { + notifyPropertyChange(key) { if (this.record) { this.record.notifyPropertyChange(key); } }, - rollbackAttributes: function() { + rollbackAttributes() { var dirtyKeys = Object.keys(this._attributes); this._attributes = new EmptyObject(); @@ -425,7 +425,7 @@ InternalModel.prototype = { @private @param {String} name */ - transitionTo: function(name) { + transitionTo(name) { // POSSIBLE TODO: Remove this code and replace with // always having direct reference to state objects @@ -467,7 +467,7 @@ InternalModel.prototype = { this.updateRecordArraysLater(); }, - _unhandledEvent: function(state, name, context) { + _unhandledEvent(state, name, context) { var errorMessage = "Attempted to handle event `" + name + "` "; errorMessage += "on " + String(this) + " while in state "; errorMessage += state.stateName + ". "; @@ -479,7 +479,7 @@ InternalModel.prototype = { throw new Ember.Error(errorMessage); }, - triggerLater: function() { + triggerLater() { var length = arguments.length; var args = new Array(length); @@ -493,7 +493,7 @@ InternalModel.prototype = { Ember.run.scheduleOnce('actions', this, '_triggerDeferredTriggers'); }, - _triggerDeferredTriggers: function() { + _triggerDeferredTriggers() { //TODO: Before 1.0 we want to remove all the events that happen on the pre materialized record, //but for now, we queue up all the events triggered before the record was materialized, and flush //them once we have the record @@ -510,7 +510,7 @@ InternalModel.prototype = { @method clearRelationships @private */ - clearRelationships: function() { + clearRelationships() { this.eachRelationship((name, relationship) => { if (this._relationships.has(name)) { var rel = this._relationships.get(name); @@ -539,7 +539,7 @@ InternalModel.prototype = { @private @param {Object} preload */ - _preloadData: function(preload) { + _preloadData(preload) { //TODO(Igor) consider the polymorphic case Object.keys(preload).forEach((key) => { var preloadValue = get(preload, key); @@ -552,7 +552,7 @@ InternalModel.prototype = { }); }, - _preloadRelationship: function(key, preloadValue) { + _preloadRelationship(key, preloadValue) { var relationshipMeta = this.type.metaForProperty(key); var type = relationshipMeta.type; if (relationshipMeta.kind === 'hasMany') { @@ -562,7 +562,7 @@ InternalModel.prototype = { } }, - _preloadHasMany: function(key, preloadValue, type) { + _preloadHasMany(key, preloadValue, type) { Ember.assert("You need to pass in an array to set a hasMany property on a record", Ember.isArray(preloadValue)); var internalModel = this; @@ -574,7 +574,7 @@ InternalModel.prototype = { this._relationships.get(key).updateRecordsFromAdapter(recordsToSet); }, - _preloadBelongsTo: function(key, preloadValue, type) { + _preloadBelongsTo(key, preloadValue, type) { var recordToSet = this._convertStringOrNumberIntoInternalModel(preloadValue, type); //We use the pathway of setting the hasMany as if it came from the adapter @@ -582,7 +582,7 @@ InternalModel.prototype = { this._relationships.get(key).setRecord(recordToSet); }, - _convertStringOrNumberIntoInternalModel: function(value, type) { + _convertStringOrNumberIntoInternalModel(value, type) { if (typeof value === 'string' || typeof value === 'number') { return this.store._internalModelForId(type, value); } @@ -597,12 +597,12 @@ InternalModel.prototype = { @method updateRecordArrays @private */ - updateRecordArrays: function() { + updateRecordArrays() { this._updatingRecordArraysLater = false; this.store.dataWasUpdated(this.type, this); }, - setId: function(id) { + setId(id) { Ember.assert('A record\'s id cannot be changed once it is in the loaded state', this.id === null || this.id === id || this.isNew()); this.id = id; if (this.record.get('id') !== id) { @@ -610,7 +610,7 @@ InternalModel.prototype = { } }, - didError: function(error) { + didError(error) { this.error = error; this.isError = true; @@ -622,7 +622,7 @@ InternalModel.prototype = { } }, - didCleanError: function() { + didCleanError() { this.error = null; this.isError = false; @@ -640,7 +640,7 @@ InternalModel.prototype = { @method adapterDidCommit */ - adapterDidCommit: function(data) { + adapterDidCommit(data) { if (data) { data = data.attributes; } @@ -667,29 +667,29 @@ InternalModel.prototype = { @method updateRecordArraysLater @private */ - updateRecordArraysLater: function() { + updateRecordArraysLater() { // quick hack (something like this could be pushed into run.once if (this._updatingRecordArraysLater) { return; } this._updatingRecordArraysLater = true; Ember.run.schedule('actions', this, this.updateRecordArrays); }, - addErrorMessageToAttribute: function(attribute, message) { + addErrorMessageToAttribute(attribute, message) { var record = this.getRecord(); get(record, 'errors')._add(attribute, message); }, - removeErrorMessageFromAttribute: function(attribute) { + removeErrorMessageFromAttribute(attribute) { var record = this.getRecord(); get(record, 'errors')._remove(attribute); }, - clearErrorMessages: function() { + clearErrorMessages() { var record = this.getRecord(); get(record, 'errors')._clear(); }, - hasErrors: function() { + hasErrors() { var record = this.getRecord(); var errors = get(record, 'errors'); @@ -702,7 +702,7 @@ InternalModel.prototype = { @method adapterDidInvalidate @private */ - adapterDidInvalidate: function(errors) { + adapterDidInvalidate(errors) { var attribute; for (attribute in errors) { @@ -720,13 +720,13 @@ InternalModel.prototype = { @method adapterDidError @private */ - adapterDidError: function(error) { + adapterDidError(error) { this.send('becameError'); this.didError(error); this._saveWasRejected(); }, - _saveWasRejected: function() { + _saveWasRejected() { var keys = Object.keys(this._inFlightAttributes); for (var i=0; i < keys.length; i++) { if (this._attributes[keys[i]] === undefined) { @@ -777,7 +777,7 @@ InternalModel.prototype = { @method _changedKeys @private */ - _changedKeys: function(updates) { + _changedKeys(updates) { var changedKeys = []; if (updates) { @@ -809,7 +809,7 @@ InternalModel.prototype = { return changedKeys; }, - toString: function() { + toString() { if (this.record) { return this.record.toString(); } else { diff --git a/addon/system/model/model.js b/addon/system/model/model.js index dcc5a8bccdc..aca930d20ab 100644 --- a/addon/system/model/model.js +++ b/addon/system/model/model.js @@ -384,7 +384,7 @@ var Model = Ember.Object.extend(Ember.Evented, { @param {Object} options @return {Object} an object whose values are primitive JSON values only */ - serialize: function(options) { + serialize(options) { return this.store.serialize(this, options); }, @@ -402,7 +402,7 @@ var Model = Ember.Object.extend(Ember.Evented, { @param {Object} options @return {Object} A JSON representation of the object. */ - toJSON: function(options) { + toJSON(options) { // container is for lazy transform lookups var serializer = this.store.serializerFor('-default'); var snapshot = this._internalModel.createSnapshot(); @@ -481,7 +481,7 @@ var Model = Ember.Object.extend(Ember.Evented, { @param {String} name @param {Object} context */ - send: function(name, context) { + send(name, context) { return this._internalModel.send(name, context); }, @@ -490,7 +490,7 @@ var Model = Ember.Object.extend(Ember.Evented, { @private @param {String} name */ - transitionTo: function(name) { + transitionTo(name) { return this._internalModel.transitionTo(name); }, @@ -523,7 +523,7 @@ var Model = Ember.Object.extend(Ember.Evented, { @method deleteRecord */ - deleteRecord: function() { + deleteRecord() { this._internalModel.deleteRecord(); }, @@ -552,7 +552,7 @@ var Model = Ember.Object.extend(Ember.Evented, { @return {Promise} a promise that will be resolved when the adapter returns successfully or rejected if the adapter returns with an error. */ - destroyRecord: function(options) { + destroyRecord(options) { this.deleteRecord(); return this.save(options); }, @@ -561,7 +561,7 @@ var Model = Ember.Object.extend(Ember.Evented, { @method unloadRecord @private */ - unloadRecord: function() { + unloadRecord() { if (this.isDestroyed) { return; } this._internalModel.unloadRecord(); }, @@ -570,7 +570,7 @@ var Model = Ember.Object.extend(Ember.Evented, { @method _notifyProperties @private */ - _notifyProperties: function(keys) { + _notifyProperties(keys) { Ember.beginPropertyChanges(); var key; for (var i = 0, length = keys.length; i < length; i++) { @@ -605,7 +605,7 @@ var Model = Ember.Object.extend(Ember.Evented, { @return {Object} an object, whose keys are changed properties, and value is an [oldProp, newProp] array. */ - changedAttributes: function() { + changedAttributes() { return this._internalModel.changedAttributes(); }, @@ -643,7 +643,7 @@ var Model = Ember.Object.extend(Ember.Evented, { @method rollbackAttributes */ - rollbackAttributes: function() { + rollbackAttributes() { this._internalModel.rollbackAttributes(); }, @@ -651,11 +651,11 @@ var Model = Ember.Object.extend(Ember.Evented, { @method _createSnapshot @private */ - _createSnapshot: function() { + _createSnapshot() { return this._internalModel.createSnapshot(); }, - toStringExtension: function() { + toStringExtension() { return get(this, 'id'); }, @@ -678,7 +678,7 @@ var Model = Ember.Object.extend(Ember.Evented, { @return {Promise} a promise that will be resolved when the adapter returns successfully or rejected if the adapter returns with an error. */ - save: function(options) { + save(options) { return PromiseObject.create({ promise: this._internalModel.save(options).then(() => this) }); @@ -710,7 +710,7 @@ var Model = Ember.Object.extend(Ember.Evented, { adapter returns successfully or rejected if the adapter returns with an error. */ - reload: function() { + reload() { return PromiseObject.create({ promise: this._internalModel.reload().then(() => this) }); @@ -725,7 +725,7 @@ var Model = Ember.Object.extend(Ember.Evented, { @private @param {String} name */ - trigger: function(name) { + trigger(name) { var length = arguments.length; var args = new Array(length - 1); @@ -737,7 +737,7 @@ var Model = Ember.Object.extend(Ember.Evented, { this._super(...arguments); }, - willDestroy: function() { + willDestroy() { //TODO Move! this._super(...arguments); this._internalModel.clearRelationships(); @@ -747,21 +747,21 @@ var Model = Ember.Object.extend(Ember.Evented, { // This is a temporary solution until we refactor DS.Model to not // rely on the data property. - willMergeMixin: function(props) { + willMergeMixin(props) { var constructor = this.constructor; Ember.assert('`' + intersection(Object.keys(props), RESERVED_MODEL_PROPS)[0] + '` is a reserved property name on DS.Model objects. Please choose a different property name for ' + constructor.toString(), !intersection(Object.keys(props), RESERVED_MODEL_PROPS)[0]); Ember.assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: DS.attr('')` from " + constructor.toString(), Object.keys(props).indexOf('id') === -1); }, - attr: function() { + attr() { Ember.assert("The `attr` method is not available on DS.Model, a DS.Snapshot was probably expected. Are you passing a DS.Model instead of a DS.Snapshot to your serializer?", false); }, - belongsTo: function() { + belongsTo() { Ember.assert("The `belongsTo` method is not available on DS.Model, a DS.Snapshot was probably expected. Are you passing a DS.Model instead of a DS.Snapshot to your serializer?", false); }, - hasMany: function() { + hasMany() { Ember.assert("The `hasMany` method is not available on DS.Model, a DS.Snapshot was probably expected. Are you passing a DS.Model instead of a DS.Snapshot to your serializer?", false); }, @@ -793,7 +793,7 @@ Model.reopenClass({ @private @static */ - create: function() { + create() { throw new Ember.Error("You should not call `create` on a model. Instead, call `store.createRecord` with the attributes you would like to set."); }, diff --git a/addon/system/model/states.js b/addon/system/model/states.js index e4c0cb9997a..a8fff59bb55 100644 --- a/addon/system/model/states.js +++ b/addon/system/model/states.js @@ -240,11 +240,11 @@ var DirtyState = { //loadingData event, though it seems fine? loadingData: Ember.K, - propertyWasReset: function(internalModel, name) { + propertyWasReset(internalModel, name) { if (!internalModel.hasChangedAttributes()) { internalModel.send('rolledBack'); } }, - pushedData: function(internalModel) { + pushedData(internalModel) { internalModel.updateChangedAttributes(); if (!internalModel.hasChangedAttributes()) { @@ -254,23 +254,23 @@ var DirtyState = { becomeDirty: Ember.K, - willCommit: function(internalModel) { + willCommit(internalModel) { internalModel.transitionTo('inFlight'); }, - reloadRecord: function(internalModel, resolve) { + reloadRecord(internalModel, resolve) { resolve(internalModel.store.reloadRecord(internalModel)); }, - rolledBack: function(internalModel) { + rolledBack(internalModel) { internalModel.transitionTo('loaded.saved'); }, - becameInvalid: function(internalModel) { + becameInvalid(internalModel) { internalModel.transitionTo('invalid'); }, - rollback: function(internalModel) { + rollback(internalModel) { internalModel.rollbackAttributes(); internalModel.triggerLater('ready'); } @@ -293,19 +293,19 @@ var DirtyState = { // TODO: More robust semantics around save-while-in-flight willCommit: Ember.K, - didCommit: function(internalModel) { + didCommit(internalModel) { var dirtyType = get(this, 'dirtyType'); internalModel.transitionTo('saved'); internalModel.send('invokeLifecycleCallbacks', dirtyType); }, - becameInvalid: function(internalModel) { + becameInvalid(internalModel) { internalModel.transitionTo('invalid'); internalModel.send('invokeLifecycleCallbacks'); }, - becameError: function(internalModel) { + becameError(internalModel) { internalModel.transitionTo('uncommitted'); internalModel.triggerLater('becameError', internalModel); } @@ -318,11 +318,11 @@ var DirtyState = { isValid: false, // EVENTS - deleteRecord: function(internalModel) { + deleteRecord(internalModel) { internalModel.transitionTo('deleted.uncommitted'); }, - didSetProperty: function(internalModel, context) { + didSetProperty(internalModel, context) { internalModel.removeErrorMessageFromAttribute(context.name); didSetProperty(internalModel, context); @@ -336,22 +336,22 @@ var DirtyState = { becomeDirty: Ember.K, pushedData: Ember.K, - willCommit: function(internalModel) { + willCommit(internalModel) { internalModel.clearErrorMessages(); internalModel.transitionTo('inFlight'); }, - rolledBack: function(internalModel) { + rolledBack(internalModel) { internalModel.clearErrorMessages(); internalModel.transitionTo('loaded.saved'); internalModel.triggerLater('ready'); }, - becameValid: function(internalModel) { + becameValid(internalModel) { internalModel.transitionTo('uncommitted'); }, - invokeLifecycleCallbacks: function(internalModel) { + invokeLifecycleCallbacks(internalModel) { internalModel.triggerLater('becameInvalid', internalModel); } } @@ -452,7 +452,7 @@ var RootState = { // in-flight state, rolling back the record doesn't move // you out of the in-flight state. rolledBack: Ember.K, - unloadRecord: function(internalModel) { + unloadRecord(internalModel) { // clear relationships before moving to deleted state // otherwise it fails internalModel.clearRelationships(); @@ -473,17 +473,17 @@ var RootState = { isEmpty: true, // EVENTS - loadingData: function(internalModel, promise) { + loadingData(internalModel, promise) { internalModel._loadingPromise = promise; internalModel.transitionTo('loading'); }, - loadedData: function(internalModel) { + loadedData(internalModel) { internalModel.transitionTo('loaded.created.uncommitted'); internalModel.triggerLater('ready'); }, - pushedData: function(internalModel) { + pushedData(internalModel) { internalModel.transitionTo('loaded.saved'); internalModel.triggerLater('didLoad'); internalModel.triggerLater('ready'); @@ -500,12 +500,12 @@ var RootState = { // FLAGS isLoading: true, - exit: function(internalModel) { + exit(internalModel) { internalModel._loadingPromise = null; }, // EVENTS - pushedData: function(internalModel) { + pushedData(internalModel) { internalModel.transitionTo('loaded.saved'); internalModel.triggerLater('didLoad'); internalModel.triggerLater('ready'); @@ -513,11 +513,11 @@ var RootState = { internalModel.didCleanError(); }, - becameError: function(internalModel) { + becameError(internalModel) { internalModel.triggerLater('becameError', internalModel); }, - notFound: function(internalModel) { + notFound(internalModel) { internalModel.transitionTo('empty'); } }, @@ -540,7 +540,7 @@ var RootState = { // If there are no local changes to a record, it remains // in the `saved` state. saved: { - setup: function(internalModel) { + setup(internalModel) { if (internalModel.hasChangedAttributes()) { internalModel.adapterDidDirty(); } @@ -551,30 +551,30 @@ var RootState = { pushedData: Ember.K, - becomeDirty: function(internalModel) { + becomeDirty(internalModel) { internalModel.transitionTo('updated.uncommitted'); }, - willCommit: function(internalModel) { + willCommit(internalModel) { internalModel.transitionTo('updated.inFlight'); }, - reloadRecord: function(internalModel, resolve) { + reloadRecord(internalModel, resolve) { resolve(internalModel.store.reloadRecord(internalModel)); }, - deleteRecord: function(internalModel) { + deleteRecord(internalModel) { internalModel.transitionTo('deleted.uncommitted'); }, - unloadRecord: function(internalModel) { + unloadRecord(internalModel) { // clear relationships before moving to deleted state // otherwise it fails internalModel.clearRelationships(); internalModel.transitionTo('deleted.saved'); }, - didCommit: function(internalModel) { + didCommit(internalModel) { internalModel.send('invokeLifecycleCallbacks', get(internalModel, 'lastDirtyType')); }, @@ -606,7 +606,7 @@ var RootState = { isDirty: true, // TRANSITIONS - setup: function(internalModel) { + setup(internalModel) { internalModel.updateRecordArrays(); }, @@ -619,11 +619,11 @@ var RootState = { // EVENTS - willCommit: function(internalModel) { + willCommit(internalModel) { internalModel.transitionTo('inFlight'); }, - rollback: function(internalModel) { + rollback(internalModel) { internalModel.rollbackAttributes(); internalModel.triggerLater('ready'); }, @@ -632,7 +632,7 @@ var RootState = { becomeDirty: Ember.K, deleteRecord: Ember.K, - rolledBack: function(internalModel) { + rolledBack(internalModel) { internalModel.transitionTo('loaded.saved'); internalModel.triggerLater('ready'); } @@ -652,18 +652,18 @@ var RootState = { // TODO: More robust semantics around save-while-in-flight willCommit: Ember.K, - didCommit: function(internalModel) { + didCommit(internalModel) { internalModel.transitionTo('saved'); internalModel.send('invokeLifecycleCallbacks'); }, - becameError: function(internalModel) { + becameError(internalModel) { internalModel.transitionTo('uncommitted'); internalModel.triggerLater('becameError', internalModel); }, - becameInvalid: function(internalModel) { + becameInvalid(internalModel) { internalModel.transitionTo('invalid'); internalModel.triggerLater('becameInvalid', internalModel); } @@ -676,13 +676,13 @@ var RootState = { // FLAGS isDirty: false, - setup: function(internalModel) { + setup(internalModel) { internalModel.clearRelationships(); var store = internalModel.store; store._dematerializeRecord(internalModel); }, - invokeLifecycleCallbacks: function(internalModel) { + invokeLifecycleCallbacks(internalModel) { internalModel.triggerLater('didDelete', internalModel); internalModel.triggerLater('didCommit', internalModel); }, @@ -695,7 +695,7 @@ var RootState = { invalid: { isValid: false, - didSetProperty: function(internalModel, context) { + didSetProperty(internalModel, context) { internalModel.removeErrorMessageFromAttribute(context.name); didSetProperty(internalModel, context); @@ -711,20 +711,20 @@ var RootState = { willCommit: Ember.K, - rolledBack: function(internalModel) { + rolledBack(internalModel) { internalModel.clearErrorMessages(); internalModel.transitionTo('loaded.saved'); internalModel.triggerLater('ready'); }, - becameValid: function(internalModel) { + becameValid(internalModel) { internalModel.transitionTo('uncommitted'); } } }, - invokeLifecycleCallbacks: function(internalModel, dirtyType) { + invokeLifecycleCallbacks(internalModel, dirtyType) { if (dirtyType === 'created') { internalModel.triggerLater('didCreate', internalModel); } else { diff --git a/addon/system/promise-proxies.js b/addon/system/promise-proxies.js index ac53fb5b19a..965e0cd643c 100644 --- a/addon/system/promise-proxies.js +++ b/addon/system/promise-proxies.js @@ -101,7 +101,7 @@ function proxyToContent(method) { } var PromiseManyArray = PromiseArray.extend({ - reload: function() { + reload() { //I don't think this should ever happen right now, but worth guarding if we refactor the async relationships Ember.assert('You are trying to reload an async manyArray before it has been created', get(this, 'content')); return PromiseManyArray.create({ diff --git a/addon/system/record-array-manager.js b/addon/system/record-array-manager.js index 80b85f74ca7..bd9d57a6915 100644 --- a/addon/system/record-array-manager.js +++ b/addon/system/record-array-manager.js @@ -18,9 +18,9 @@ var get = Ember.get; @extends Ember.Object */ export default Ember.Object.extend({ - init: function() { + init() { this.filteredRecordArrays = MapWithDefault.create({ - defaultValue: function() { return []; } + defaultValue() { return []; } }); this.liveRecordArrays = MapWithDefault.create({ @@ -33,13 +33,13 @@ export default Ember.Object.extend({ this._adapterPopulatedRecordArrays = []; }, - recordDidChange: function(record) { + recordDidChange(record) { if (this.changedRecords.push(record) !== 1) { return; } Ember.run.schedule('actions', this, this.updateRecordArrays); }, - recordArraysForRecord: function(record) { + recordArraysForRecord(record) { record._recordArrays = record._recordArrays || OrderedSet.create(); return record._recordArrays; }, @@ -54,7 +54,7 @@ export default Ember.Object.extend({ @method updateRecordArrays */ - updateRecordArrays: function() { + updateRecordArrays() { this.changedRecords.forEach((internalModel) => { if (get(internalModel, 'record.isDestroyed') || get(internalModel, 'record.isDestroying') || (get(internalModel, 'currentState.stateName') === 'root.deleted.saved')) { @@ -67,7 +67,7 @@ export default Ember.Object.extend({ this.changedRecords.length = 0; }, - _recordWasDeleted: function (record) { + _recordWasDeleted(record) { var recordArrays = record._recordArrays; if (!recordArrays) { return; } @@ -78,7 +78,7 @@ export default Ember.Object.extend({ }, - _recordWasChanged: function (record) { + _recordWasChanged(record) { var typeClass = record.type; var recordArrays = this.filteredRecordArrays.get(typeClass); var filter; @@ -89,7 +89,7 @@ export default Ember.Object.extend({ }, //Need to update live arrays on loading - recordWasLoaded: function(record) { + recordWasLoaded(record) { var typeClass = record.type; var recordArrays = this.filteredRecordArrays.get(typeClass); var filter; @@ -113,7 +113,7 @@ export default Ember.Object.extend({ @param {DS.Model} typeClass @param {InternalModel} record */ - updateFilterRecordArray: function(array, filter, typeClass, record) { + updateFilterRecordArray(array, filter, typeClass, record) { var shouldBeInArray = filter(record.getRecord()); var recordArrays = this.recordArraysForRecord(record); if (shouldBeInArray) { @@ -124,7 +124,7 @@ export default Ember.Object.extend({ } }, - _addRecordToRecordArray: function(array, record) { + _addRecordToRecordArray(array, record) { var recordArrays = this.recordArraysForRecord(record); if (!recordArrays.has(array)) { array.addInternalModel(record); @@ -132,7 +132,7 @@ export default Ember.Object.extend({ } }, - populateLiveRecordArray: function(array, modelName) { + populateLiveRecordArray(array, modelName) { var typeMap = this.store.typeMapFor(modelName); var records = typeMap.records; var record; @@ -158,7 +158,7 @@ export default Ember.Object.extend({ @param {String} modelName @param {Function} filter */ - updateFilter: function(array, modelName, filter) { + updateFilter(array, modelName, filter) { var typeMap = this.store.typeMapFor(modelName); var records = typeMap.records; var record; @@ -180,7 +180,7 @@ export default Ember.Object.extend({ @param {Class} typeClass @return {DS.RecordArray} */ - liveRecordArrayFor: function(typeClass) { + liveRecordArrayFor(typeClass) { return this.liveRecordArrays.get(typeClass); }, @@ -191,7 +191,7 @@ export default Ember.Object.extend({ @param {Class} typeClass @return {DS.RecordArray} */ - createRecordArray: function(typeClass) { + createRecordArray(typeClass) { var array = RecordArray.create({ type: typeClass, content: Ember.A(), @@ -212,7 +212,7 @@ export default Ember.Object.extend({ @param {Object} query (optional @return {DS.FilteredRecordArray} */ - createFilteredRecordArray: function(typeClass, filter, query) { + createFilteredRecordArray(typeClass, filter, query) { var array = FilteredRecordArray.create({ query: query, type: typeClass, @@ -235,7 +235,7 @@ export default Ember.Object.extend({ @param {Object} query @return {DS.AdapterPopulatedRecordArray} */ - createAdapterPopulatedRecordArray: function(typeClass, query) { + createAdapterPopulatedRecordArray(typeClass, query) { var array = AdapterPopulatedRecordArray.create({ type: typeClass, query: query, @@ -260,7 +260,7 @@ export default Ember.Object.extend({ @param {DS.Model} typeClass @param {Function} filter */ - registerFilteredRecordArray: function(array, typeClass, filter) { + registerFilteredRecordArray(array, typeClass, filter) { var recordArrays = this.filteredRecordArrays.get(typeClass); recordArrays.push(array); @@ -274,7 +274,7 @@ export default Ember.Object.extend({ @method unregisterRecordArray @param {DS.RecordArray} array */ - unregisterRecordArray: function(array) { + unregisterRecordArray(array) { var typeClass = array.type; // unregister filtered record array @@ -292,7 +292,7 @@ export default Ember.Object.extend({ } }, - willDestroy: function() { + willDestroy() { this._super(...arguments); this.filteredRecordArrays.forEach((value) => flatten(value).forEach(destroy)); diff --git a/addon/system/record-arrays/adapter-populated-record-array.js b/addon/system/record-arrays/adapter-populated-record-array.js index 18a2f868096..796866cf614 100644 --- a/addon/system/record-arrays/adapter-populated-record-array.js +++ b/addon/system/record-arrays/adapter-populated-record-array.js @@ -20,7 +20,7 @@ var get = Ember.get; export default RecordArray.extend({ query: null, - replace: function() { + replace() { var type = get(this, 'type').toString(); throw new Error("The result of a server query (on " + type + ") is immutable."); }, @@ -30,7 +30,7 @@ export default RecordArray.extend({ @param {Array} records @private */ - loadRecords: function(records) { + loadRecords(records) { var store = get(this, 'store'); var type = get(this, 'type'); var modelName = type.modelName; diff --git a/addon/system/record-arrays/filtered-record-array.js b/addon/system/record-arrays/filtered-record-array.js index 85f5b7def2f..7124aa8122e 100644 --- a/addon/system/record-arrays/filtered-record-array.js +++ b/addon/system/record-arrays/filtered-record-array.js @@ -46,7 +46,7 @@ export default RecordArray.extend({ filterFunction: null, isLoaded: true, - replace: function() { + replace() { var type = get(this, 'type').toString(); throw new Error("The result of a client-side filter (on " + type + ") is immutable."); }, @@ -55,7 +55,7 @@ export default RecordArray.extend({ @method updateFilter @private */ - _updateFilter: function() { + _updateFilter() { var manager = get(this, 'manager'); manager.updateFilter(this, get(this, 'type'), get(this, 'filterFunction')); }, diff --git a/addon/system/record-arrays/record-array.js b/addon/system/record-arrays/record-array.js index 0577f2ef3f4..da9e705a5e1 100644 --- a/addon/system/record-arrays/record-array.js +++ b/addon/system/record-arrays/record-array.js @@ -90,7 +90,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @param {Number} index @return {DS.Model} record */ - objectAtContent: function(index) { + objectAtContent(index) { var content = get(this, 'content'); var internalModel = content.objectAt(index); return internalModel && internalModel.getRecord(); @@ -111,7 +111,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @method update */ - update: function() { + update() { if (get(this, 'isUpdating')) { return; } var store = get(this, 'store'); @@ -128,7 +128,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @param {InternalModel} internalModel @param {number} an optional index to insert at */ - addInternalModel: function(internalModel, idx) { + addInternalModel(internalModel, idx) { var content = get(this, 'content'); if (idx === undefined) { content.addObject(internalModel); @@ -144,7 +144,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @private @param {InternalModel} internalModel */ - removeInternalModel: function(internalModel) { + removeInternalModel(internalModel) { get(this, 'content').removeObject(internalModel); }, @@ -164,7 +164,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @method save @return {DS.PromiseArray} promise */ - save: function() { + save() { var recordArray = this; var promiseLabel = "DS: RecordArray#save " + get(this, 'type'); var promise = Ember.RSVP.all(this.invoke("save"), promiseLabel).then(function(array) { @@ -174,7 +174,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { return PromiseArray.create({ promise: promise }); }, - _dissociateFromOwnRecords: function() { + _dissociateFromOwnRecords() { this.get('content').forEach((record) => { var recordArrays = record._recordArrays; @@ -188,12 +188,12 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @method _unregisterFromManager @private */ - _unregisterFromManager: function() { + _unregisterFromManager() { var manager = get(this, 'manager'); manager.unregisterRecordArray(this); }, - willDestroy: function() { + willDestroy() { this._unregisterFromManager(); this._dissociateFromOwnRecords(); set(this, 'content', undefined); diff --git a/addon/system/relationships/belongs-to.js b/addon/system/relationships/belongs-to.js index 76770cd14f6..06e0db9a7bd 100644 --- a/addon/system/relationships/belongs-to.js +++ b/addon/system/relationships/belongs-to.js @@ -100,7 +100,7 @@ export default function belongsTo(modelName, options) { }; return Ember.computed({ - get: function(key) { + get(key) { if (opts.hasOwnProperty('serialize')) { Ember.warn(`You provided a serialize option on the "${key}" property in the "${this._internalModel.modelName}" class, this belongs in the serializer. See DS.Serializer and it's implementations http://emberjs.com/api/data/classes/DS.Serializer.html`, false, { id: 'ds.model.serialize-option-in-belongs-to' @@ -115,7 +115,7 @@ export default function belongsTo(modelName, options) { return this._internalModel._relationships.get(key).getRecord(); }, - set: function(key, value) { + set(key, value) { if (value === undefined) { value = null; } @@ -137,7 +137,7 @@ export default function belongsTo(modelName, options) { `relationships/ext` to see how these observers get their dependencies. */ Model.reopen({ - notifyBelongsToChanged: function(key) { + notifyBelongsToChanged(key) { this.notifyPropertyChange(key); } }); diff --git a/addon/system/relationships/ext.js b/addon/system/relationships/ext.js index 3da55e6539a..ccd28565ac3 100644 --- a/addon/system/relationships/ext.js +++ b/addon/system/relationships/ext.js @@ -15,7 +15,7 @@ var relationshipsDescriptor = Ember.computed(function() { } var map = new MapWithDefault({ - defaultValue: function() { return []; } + defaultValue() { return []; } }); // Loop through each computed property on the class @@ -124,7 +124,7 @@ Model.reopen({ @param {String} key @param {Ember.ComputedProperty} value */ - didDefineProperty: function(proto, key, value) { + didDefineProperty(proto, key, value) { // Check if the value being set is a computed property. if (value instanceof Ember.ComputedProperty) { @@ -178,7 +178,7 @@ Model.reopenClass({ @param {store} store an instance of DS.Store @return {DS.Model} the type of the relationship, or undefined */ - typeForRelationship: function(name, store) { + typeForRelationship(name, store) { var relationship = get(this, 'relationshipsByName').get(name); return relationship && store.modelFor(relationship.type); }, @@ -216,7 +216,7 @@ Model.reopenClass({ @param {String} name the name of the relationship @return {Object} the inverse relationship, or null */ - inverseFor: function(name, store) { + inverseFor(name, store) { var inverseMap = get(this, 'inverseMap'); if (inverseMap[name]) { return inverseMap[name]; @@ -228,7 +228,7 @@ Model.reopenClass({ }, //Calculate the inverse, ignoring the cache - _findInverseFor: function(name, store) { + _findInverseFor(name, store) { var inverseType = this.typeForRelationship(name, store); if (!inverseType) { @@ -549,7 +549,7 @@ Model.reopenClass({ @param {Function} callback the callback to invoke @param {any} binding the value to which the callback's `this` should be bound */ - eachRelationship: function(callback, binding) { + eachRelationship(callback, binding) { get(this, 'relationshipsByName').forEach((relationship, name) => { callback.call(binding, name, relationship); }); @@ -566,13 +566,13 @@ Model.reopenClass({ @param {Function} callback the callback to invoke @param {any} binding the value to which the callback's `this` should be bound */ - eachRelatedType: function(callback, binding) { + eachRelatedType(callback, binding) { get(this, 'relatedTypes').forEach((type) => { callback.call(binding, type); }); }, - determineRelationshipType: function(knownSide, store) { + determineRelationshipType(knownSide, store) { var knownKey = knownSide.key; var knownKind = knownSide.kind; var inverse = this.inverseFor(knownKey, store); @@ -647,15 +647,15 @@ Model.reopen({ @param {Function} callback the callback to invoke @param {any} binding the value to which the callback's `this` should be bound */ - eachRelationship: function(callback, binding) { + eachRelationship(callback, binding) { this.constructor.eachRelationship(callback, binding); }, - relationshipFor: function(name) { + relationshipFor(name) { return get(this.constructor, 'relationshipsByName').get(name); }, - inverseFor: function(key) { + inverseFor(key) { return this.constructor.inverseFor(key, this.store); } diff --git a/addon/system/relationships/has-many.js b/addon/system/relationships/has-many.js index f0c8db4253f..50e1ea634b6 100644 --- a/addon/system/relationships/has-many.js +++ b/addon/system/relationships/has-many.js @@ -139,11 +139,11 @@ export default function hasMany(type, options) { }; return Ember.computed({ - get: function(key) { + get(key) { var relationship = this._internalModel._relationships.get(key); return relationship.getRecords(); }, - set: function(key, records) { + set(key, records) { Ember.assert("You must pass an array of records to set a hasMany relationship", isArrayLike(records)); Ember.assert(`All elements of a hasMany relationship must be instances of DS.Model, you passed ${Ember.inspect(records)}`, (function() { return Ember.A(records).every((record) => Model.detectInstance(record) ); @@ -158,7 +158,7 @@ export default function hasMany(type, options) { } Model.reopen({ - notifyHasManyAdded: function(key) { + notifyHasManyAdded(key) { //We need to notifyPropertyChange in the adding case because we need to make sure //we fetch the newly added record in case it is unloaded //TODO(Igor): Consider whether we could do this only if the record state is unloaded diff --git a/addon/system/relationships/state/relationship.js b/addon/system/relationships/state/relationship.js index 966bf90e051..db019d1cb82 100644 --- a/addon/system/relationships/state/relationship.js +++ b/addon/system/relationships/state/relationship.js @@ -24,11 +24,11 @@ Relationship.prototype = { destroy: Ember.K, - updateMeta: function(meta) { + updateMeta(meta) { this.meta = meta; }, - clear: function() { + clear() { var members = this.members.list; var member; @@ -38,11 +38,11 @@ Relationship.prototype = { } }, - removeRecords: function(records) { + removeRecords(records) { records.forEach((record) => this.removeRecord(record)); }, - addRecords: function(records, idx) { + addRecords(records, idx) { records.forEach((record) => { this.addRecord(record, idx); if (idx !== undefined) { @@ -51,7 +51,7 @@ Relationship.prototype = { }); }, - addCanonicalRecords: function(records, idx) { + addCanonicalRecords(records, idx) { for (var i=0; i this.store._backburner.schedule('syncRelationships', this, this.flushCanonical)); }, - updateLink: function(link) { + updateLink(link) { Ember.warn(`You have pushed a record of type '${this.record.type.modelName}' with '${this.key}' as a link, but the association is not an async relationship.`, this.isAsync, { id: 'ds.store.push-link-for-sync-relationship' }); @@ -196,7 +196,7 @@ Relationship.prototype = { } }, - findLink: function() { + findLink() { if (this.linkPromise) { return this.linkPromise; } else { @@ -206,7 +206,7 @@ Relationship.prototype = { } }, - updateRecordsFromAdapter: function(records) { + updateRecordsFromAdapter(records) { //TODO(Igor) move this to a proper place //TODO Once we have adapter support, we need to handle updated and canonical changes this.computeChanges(records); @@ -227,7 +227,7 @@ Relationship.prototype = { All relationships for a newly created (`store.createRecord()`) are considered known (`hasData === true`). */ - setHasData: function(value) { + setHasData(value) { this.hasData = value; }, @@ -241,7 +241,7 @@ Relationship.prototype = { Updating the link will automatically set `hasLoaded` to `false`. */ - setHasLoaded: function(value) { + setHasLoaded(value) { this.hasLoaded = value; } }; diff --git a/addon/system/serializer.js b/addon/system/serializer.js index 3bd0eebd04a..254ff4b1297 100644 --- a/addon/system/serializer.js +++ b/addon/system/serializer.js @@ -78,7 +78,7 @@ export default Ember.Object.extend({ @param {Object} hash @return {Object} */ - normalize: function(typeClass, hash) { + normalize(typeClass, hash) { return hash; } diff --git a/addon/system/snapshot.js b/addon/system/snapshot.js index 6f9464fb59f..1bf8050f62f 100644 --- a/addon/system/snapshot.js +++ b/addon/system/snapshot.js @@ -97,7 +97,7 @@ Snapshot.prototype = { @param {String} keyName @return {Object} The attribute value or undefined */ - attr: function(keyName) { + attr(keyName) { if (keyName in this._attributes) { return this._attributes[keyName]; } @@ -117,7 +117,7 @@ Snapshot.prototype = { @method attributes @return {Object} All attributes of the current snapshot */ - attributes: function() { + attributes() { return Ember.copy(this._attributes); }, @@ -135,7 +135,7 @@ Snapshot.prototype = { @method changedAttributes @return {Object} All changed attributes of the current snapshot */ - changedAttributes: function() { + changedAttributes() { let changedAttributes = new EmptyObject(); let changedAttributeKeys = Object.keys(this._changedAttributes); @@ -182,7 +182,7 @@ Snapshot.prototype = { relationship or null if the relationship is known but unset. undefined will be returned if the contents of the relationship is unknown. */ - belongsTo: function(keyName, options) { + belongsTo(keyName, options) { var id = options && options.id; var relationship, inverseRecord, hasData; var result; @@ -253,7 +253,7 @@ Snapshot.prototype = { relationship or an empty array if the relationship is known but unset. undefined will be returned if the contents of the relationship is unknown. */ - hasMany: function(keyName, options) { + hasMany(keyName, options) { var ids = options && options.ids; var relationship, members, hasData; var results; @@ -312,7 +312,7 @@ Snapshot.prototype = { @param {Function} callback the callback to execute @param {Object} [binding] the value to which the callback's `this` should be bound */ - eachAttribute: function(callback, binding) { + eachAttribute(callback, binding) { this.record.eachAttribute(callback, binding); }, @@ -332,7 +332,7 @@ Snapshot.prototype = { @param {Function} callback the callback to execute @param {Object} [binding] the value to which the callback's `this` should be bound */ - eachRelationship: function(callback, binding) { + eachRelationship(callback, binding) { this.record.eachRelationship(callback, binding); }, @@ -341,7 +341,7 @@ Snapshot.prototype = { @param {Object} options @return {Object} an object whose values are primitive JSON values only */ - serialize: function(options) { + serialize(options) { return this.record.store.serializerFor(this.modelName).serialize(this, options); } }; diff --git a/addon/system/store.js b/addon/system/store.js index 8d645d68326..036139155d5 100644 --- a/addon/system/store.js +++ b/addon/system/store.js @@ -215,7 +215,7 @@ Store = Service.extend({ @method init @private */ - init: function() { + init() { this._super(...arguments); this._backburner = new Backburner(['normalizeRelationships', 'syncRelationships', 'finished']); // internal bookkeeping; not observable @@ -260,7 +260,7 @@ Store = Service.extend({ @param {DS.Model} record the record to serialize @param {Object} options an options hash */ - serialize: function(record, options) { + serialize(record, options) { var snapshot = record._internalModel.createSnapshot(); return snapshot.serialize(options); }, @@ -322,7 +322,7 @@ Store = Service.extend({ newly created record. @return {DS.Model} record */ - createRecord: function(modelName, inputProperties) { + createRecord(modelName, inputProperties) { Ember.assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${Ember.inspect(modelName)}`, typeof modelName === 'string'); var typeClass = this.modelFor(modelName); var properties = copy(inputProperties) || new EmptyObject(); @@ -366,7 +366,7 @@ Store = Service.extend({ @param {Object} properties from the new record @return {String} if the adapter can generate one, an ID */ - _generateId: function(modelName, properties) { + _generateId(modelName, properties) { var adapter = this.adapterFor(modelName); if (adapter && adapter.generateIdForRecord) { @@ -396,7 +396,7 @@ Store = Service.extend({ @method deleteRecord @param {DS.Model} record */ - deleteRecord: function(record) { + deleteRecord(record) { record.deleteRecord(); }, @@ -415,7 +415,7 @@ Store = Service.extend({ @method unloadRecord @param {DS.Model} record */ - unloadRecord: function(record) { + unloadRecord(record) { record.unloadRecord(); }, @@ -431,7 +431,7 @@ Store = Service.extend({ @return {Promise} promise @private */ - find: function(modelName, id, options) { + find(modelName, id, options) { // The default `model` hook in Ember.Route calls `find(modelName, id)`, // that's why we have to keep this method around even though `findRecord` is // the public way to get a record by modelName and id. @@ -498,7 +498,7 @@ Store = Service.extend({ @param {Object} options @return {Promise} promise */ - findRecord: function(modelName, id, options) { + findRecord(modelName, id, options) { Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); Ember.assert(badIdFormatAssertion, (typeof id === 'string' && id.length > 0) || (typeof id === 'number' && !isNaN(id))); @@ -514,7 +514,7 @@ Store = Service.extend({ return promiseRecord(fetchedInternalModel, "DS: Store#findRecord " + internalModel.typeKey + " with id: " + get(internalModel, 'id')); }, - _findRecord: function(internalModel, options) { + _findRecord(internalModel, options) { // Refetch if the reload option is passed if (options.reload) { return this.scheduleFetch(internalModel, options); @@ -538,7 +538,7 @@ Store = Service.extend({ return Promise.resolve(internalModel); }, - _findByInternalModel: function(internalModel, options) { + _findByInternalModel(internalModel, options) { options = options || {}; if (options.preload) { @@ -550,7 +550,7 @@ Store = Service.extend({ return promiseRecord(fetchedInternalModel, "DS: Store#findRecord " + internalModel.typeKey + " with id: " + get(internalModel, 'id')); }, - _findEmptyInternalModel: function(internalModel, options) { + _findEmptyInternalModel(internalModel, options) { if (internalModel.isEmpty()) { return this.scheduleFetch(internalModel, options); } @@ -573,7 +573,7 @@ Store = Service.extend({ @param {Array} ids @return {Promise} promise */ - findByIds: function(modelName, ids) { + findByIds(modelName, ids) { Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var store = this; @@ -593,7 +593,7 @@ Store = Service.extend({ @return {Promise} promise */ // TODO rename this to have an underscore - fetchRecord: function(internalModel, options) { + fetchRecord(internalModel, options) { var typeClass = internalModel.type; var id = internalModel.id; var adapter = this.adapterFor(typeClass.modelName); @@ -605,12 +605,12 @@ Store = Service.extend({ return promise; }, - scheduleFetchMany: function(records) { + scheduleFetchMany(records) { var internalModels = records.map((record) => record._internalModel); return Promise.all(internalModels.map(this.scheduleFetch, this)); }, - scheduleFetch: function(internalModel, options) { + scheduleFetch(internalModel, options) { var typeClass = internalModel.type; if (internalModel._loadingPromise) { return internalModel._loadingPromise; } @@ -635,7 +635,7 @@ Store = Service.extend({ return promise; }, - flushAllPendingFetches: function() { + flushAllPendingFetches() { if (this.isDestroyed || this.isDestroying) { return; } @@ -644,7 +644,7 @@ Store = Service.extend({ this._pendingFetch = Map.create(); }, - _flushPendingFetchForType: function (pendingFetchItems, typeClass) { + _flushPendingFetchForType(pendingFetchItems, typeClass) { var store = this; var adapter = store.adapterFor(typeClass.modelName); var shouldCoalesce = !!adapter.findMany && adapter.coalesceFindRequests; @@ -752,7 +752,7 @@ Store = Service.extend({ @param {String|Integer} id @return {DS.Model|null} record */ - peekRecord: function(modelName, id) { + peekRecord(modelName, id) { Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); if (this.hasRecordForId(modelName, id)) { return this._internalModelForId(modelName, id).getRecord(); @@ -773,7 +773,7 @@ Store = Service.extend({ @param {DS.Model} internalModel @return {Promise} promise */ - reloadRecord: function(internalModel) { + reloadRecord(internalModel) { var modelName = internalModel.type.modelName; var adapter = this.adapterFor(modelName); var id = internalModel.id; @@ -793,7 +793,7 @@ Store = Service.extend({ @param {(String|Integer)} inputId @return {Boolean} */ - hasRecordForId: function(modelName, inputId) { + hasRecordForId(modelName, inputId) { Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var typeClass = this.modelFor(modelName); var id = coerceId(inputId); @@ -811,12 +811,12 @@ Store = Service.extend({ @param {(String|Integer)} id @return {DS.Model} record */ - recordForId: function(modelName, id) { + recordForId(modelName, id) { Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); return this._internalModelForId(modelName, id).getRecord(); }, - _internalModelForId: function(typeName, inputId) { + _internalModelForId(typeName, inputId) { var typeClass = this.modelFor(typeName); var id = coerceId(inputId); var idToRecord = this.typeMapFor(typeClass).idToRecord; @@ -837,7 +837,7 @@ Store = Service.extend({ @param {Array} internalModels @return {Promise} promise */ - findMany: function(internalModels) { + findMany(internalModels) { return Promise.all(internalModels.map((internalModel) => this._findByInternalModel(internalModel))); }, @@ -860,7 +860,7 @@ Store = Service.extend({ @param {(Relationship)} relationship @return {Promise} promise */ - findHasMany: function(owner, link, relationship) { + findHasMany(owner, link, relationship) { var adapter = this.adapterFor(owner.type.modelName); Ember.assert("You tried to load a hasMany relationship but you have no adapter (for " + owner.type + ")", adapter); @@ -877,7 +877,7 @@ Store = Service.extend({ @param {Relationship} relationship @return {Promise} promise */ - findBelongsTo: function(owner, link, relationship) { + findBelongsTo(owner, link, relationship) { var adapter = this.adapterFor(owner.type.modelName); Ember.assert("You tried to load a belongsTo relationship but you have no adapter (for " + owner.type + ")", adapter); @@ -934,7 +934,7 @@ Store = Service.extend({ @param {any} query an opaque query to be used by the adapter @return {Promise} promise */ - query: function(modelName, query) { + query(modelName, query) { Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var typeClass = this.modelFor(modelName); var array = this.recordArrayManager @@ -964,7 +964,7 @@ Store = Service.extend({ @param {any} query an opaque query to be used by the adapter @return {Promise} promise */ - queryRecord: function(modelName, query) { + queryRecord(modelName, query) { Ember.assert("You need to pass a type to the store's queryRecord method", modelName); Ember.assert("You need to pass a query hash to the store's queryRecord method", query); Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); @@ -1000,7 +1000,7 @@ Store = Service.extend({ @param {Object} options @return {DS.AdapterPopulatedRecordArray} */ - findAll: function(modelName, options) { + findAll(modelName, options) { Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var typeClass = this.modelFor(modelName); @@ -1014,7 +1014,7 @@ Store = Service.extend({ @param {DS.RecordArray} array @return {Promise} promise */ - _fetchAll: function(typeClass, array, options) { + _fetchAll(typeClass, array, options) { options = options || {}; var adapter = this.adapterFor(typeClass.modelName); var sinceToken = this.typeMapFor(typeClass).metadata.since; @@ -1041,7 +1041,7 @@ Store = Service.extend({ @param {DS.Model} typeClass @private */ - didUpdateAll: function(typeClass) { + didUpdateAll(typeClass) { var liveRecordArray = this.recordArrayManager.liveRecordArrayFor(typeClass); set(liveRecordArray, 'isUpdating', false); }, @@ -1069,7 +1069,7 @@ Store = Service.extend({ @param {String} modelName @return {DS.RecordArray} */ - peekAll: function(modelName) { + peekAll(modelName) { Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var typeClass = this.modelFor(modelName); @@ -1092,7 +1092,7 @@ Store = Service.extend({ @method unloadAll @param {String=} modelName */ - unloadAll: function(modelName) { + unloadAll(modelName) { Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), !modelName || typeof modelName === 'string'); if (arguments.length === 0) { var typeMaps = this.typeMaps; @@ -1173,7 +1173,7 @@ Store = Service.extend({ @param {Function} filter @return {DS.PromiseArray} */ - filter: function(modelName, query, filter) { + filter(modelName, query, filter) { Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); if (!Ember.ENV.ENABLE_DS_FILTER) { @@ -1224,7 +1224,7 @@ Store = Service.extend({ @param {string} id @return {boolean} */ - recordIsLoaded: function(modelName, id) { + recordIsLoaded(modelName, id) { Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); return this.hasRecordForId(modelName, id); }, @@ -1235,7 +1235,7 @@ Store = Service.extend({ @return {object} @private */ - _metadataFor: function(modelName) { + _metadataFor(modelName) { Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var typeClass = this.modelFor(modelName); return this.typeMapFor(typeClass).metadata; @@ -1247,7 +1247,7 @@ Store = Service.extend({ @param {Object} metadata metadata to set @private */ - _setMetadataFor: function(modelName, metadata) { + _setMetadataFor(modelName, metadata) { Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var typeClass = this.modelFor(modelName); Ember.merge(this.typeMapFor(typeClass).metadata, metadata); @@ -1268,7 +1268,7 @@ Store = Service.extend({ @param {Class} type @param {InternalModel} internalModel */ - dataWasUpdated: function(type, internalModel) { + dataWasUpdated(type, internalModel) { this.recordArrayManager.recordDidChange(internalModel); }, @@ -1288,7 +1288,7 @@ Store = Service.extend({ @param {Resolver} resolver @param {Object} options */ - scheduleSave: function(internalModel, resolver, options) { + scheduleSave(internalModel, resolver, options) { var snapshot = internalModel.createSnapshot(options); internalModel.flushChangedAttributes(); internalModel.adapterWillCommit(); @@ -1306,7 +1306,7 @@ Store = Service.extend({ @method flushPendingSave @private */ - flushPendingSave: function() { + flushPendingSave() { var pending = this._pendingSave.slice(); this._pendingSave = []; @@ -1344,7 +1344,7 @@ Store = Service.extend({ @param {InternalModel} internalModel the in-flight internal model @param {Object} data optional data (see above) */ - didSaveRecord: function(internalModel, dataArg) { + didSaveRecord(internalModel, dataArg) { var data; if (dataArg) { data = dataArg.data; @@ -1370,7 +1370,7 @@ Store = Service.extend({ @param {InternalModel} internalModel @param {Object} errors */ - recordWasInvalid: function(internalModel, errors) { + recordWasInvalid(internalModel, errors) { internalModel.adapterDidInvalidate(errors); }, @@ -1384,7 +1384,7 @@ Store = Service.extend({ @param {InternalModel} internalModel @param {Error} error */ - recordWasError: function(internalModel, error) { + recordWasError(internalModel, error) { internalModel.adapterDidError(error); }, @@ -1398,7 +1398,7 @@ Store = Service.extend({ @param {InternalModel} internalModel @param {Object} data */ - updateId: function(internalModel, data) { + updateId(internalModel, data) { var oldId = internalModel.id; var id = coerceId(data.id); @@ -1417,7 +1417,7 @@ Store = Service.extend({ @param {DS.Model} typeClass @return {Object} typeMap */ - typeMapFor: function(typeClass) { + typeMapFor(typeClass) { var typeMaps = get(this, 'typeMaps'); var guid = Ember.guidFor(typeClass); var typeMap = typeMaps[guid]; @@ -1448,7 +1448,7 @@ Store = Service.extend({ @param {(String|DS.Model)} type @param {Object} data */ - _load: function(data) { + _load(data) { var internalModel = this._internalModelForId(data.type, data.id); internalModel.setupData(data); @@ -1474,7 +1474,7 @@ Store = Service.extend({ in this case */ - _modelForMixin: function(modelName) { + _modelForMixin(modelName) { var normalizedModelName = normalizeModelName(modelName); // container.registry = 2.1 // container._registry = 1.11 - 2.0 @@ -1504,7 +1504,7 @@ Store = Service.extend({ @param {String} modelName @return {DS.Model} */ - modelFor: function(modelName) { + modelFor(modelName) { Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var factory = this.modelFactoryFor(modelName); @@ -1520,7 +1520,7 @@ Store = Service.extend({ return factory; }, - modelFactoryFor: function(modelName) { + modelFactoryFor(modelName) { Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var normalizedKey = normalizeModelName(modelName); @@ -1679,7 +1679,7 @@ Store = Service.extend({ @return {DS.Model|Array} the record(s) that was created or updated. */ - push: function(data) { + push(data) { var included = data.included; var i, length; if (included) { @@ -1708,11 +1708,11 @@ Store = Service.extend({ return internalModel.getRecord(); }, - _hasModelFor: function(type) { + _hasModelFor(type) { return getOwner(this)._lookupFactory(`model:${type}`); }, - _pushInternalModel: function(data) { + _pushInternalModel(data) { var modelName = data.type; Ember.assert(`You must include an 'id' for ${modelName} in an object passed to 'push'`, data.id != null && data.id !== ''); Ember.assert(`You tried to push data with a type '${modelName}' but no model could be found with that name.`, this._hasModelFor(modelName)); @@ -1744,7 +1744,7 @@ Store = Service.extend({ return internalModel; }, - _setupRelationships: function(record, type, data) { + _setupRelationships(record, type, data) { // If the payload contains relationships that are specified as // IDs, normalizeRelationships will convert them into DS.Model instances // (possibly unloaded) before we push the payload into the @@ -1814,7 +1814,7 @@ Store = Service.extend({ @param {String} modelName Optionally, a model type used to determine which serializer will be used @param {Object} inputPayload */ - pushPayload: function (modelName, inputPayload) { + pushPayload(modelName, inputPayload) { var serializer; var payload; if (!inputPayload) { @@ -1848,7 +1848,7 @@ Store = Service.extend({ @param {Object} payload @return {Object} The normalized payload */ - normalize: function (modelName, payload) { + normalize(modelName, payload) { Ember.assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${Ember.inspect(modelName)}`, typeof modelName === 'string'); var serializer = this.serializerFor(modelName); var model = this.modelFor(modelName); @@ -1866,7 +1866,7 @@ Store = Service.extend({ @param {Object} data @return {InternalModel} internal model */ - buildInternalModel: function(type, id, data) { + buildInternalModel(type, id, data) { var typeMap = this.typeMapFor(type); var idToRecord = typeMap.idToRecord; @@ -1889,7 +1889,7 @@ Store = Service.extend({ }, //Called by the state machine to notify the store that the record is ready to be interacted with - recordWasLoaded: function(record) { + recordWasLoaded(record) { this.recordArrayManager.recordWasLoaded(record); }, @@ -1905,7 +1905,7 @@ Store = Service.extend({ @private @param {InternalModel} internalModel */ - _dematerializeRecord: function(internalModel) { + _dematerializeRecord(internalModel) { var type = internalModel.type; var typeMap = this.typeMapFor(type); var id = internalModel.id; @@ -1941,14 +1941,14 @@ Store = Service.extend({ @param {String} modelName @return DS.Adapter */ - adapterFor: function(modelName) { + adapterFor(modelName) { Ember.assert(`Passing classes to store.adapterFor has been removed. Please pass a dasherized string instead of ${Ember.inspect(modelName)}`, typeof modelName === 'string'); return this.lookupAdapter(modelName); }, - _adapterRun: function (fn) { + _adapterRun(fn) { return this._backburner.run(fn); }, @@ -1977,7 +1977,7 @@ Store = Service.extend({ @param {String} modelName the record to serialize @return {DS.Serializer} */ - serializerFor: function(modelName) { + serializerFor(modelName) { Ember.assert(`Passing classes to store.serializerFor has been removed. Please pass a dasherized string instead of ${Ember.inspect(modelName)}`, typeof modelName === 'string'); @@ -2006,7 +2006,7 @@ Store = Service.extend({ @param {Array} fallbacks the fallback objects to lookup if the lookup for modelName or 'application' fails @return {Ember.Object} */ - retrieveManagedInstance: function(type, modelName, fallbacks) { + retrieveManagedInstance(type, modelName, fallbacks) { var normalizedModelName = normalizeModelName(modelName); var instance = this._instanceCache.get(type, normalizedModelName, fallbacks); @@ -2014,7 +2014,7 @@ Store = Service.extend({ return instance; }, - lookupAdapter: function(name) { + lookupAdapter(name) { return this.retrieveManagedInstance('adapter', name, this.get('_adapterFallbacks')); }, @@ -2023,11 +2023,11 @@ Store = Service.extend({ return ['application', adapter, '-json-api']; }), - lookupSerializer: function(name, fallbacks) { + lookupSerializer(name, fallbacks) { return this.retrieveManagedInstance('serializer', name, fallbacks); }, - willDestroy: function() { + willDestroy() { this._super(...arguments); this.recordArrayManager.destroy(); diff --git a/addon/system/store/container-instance-cache.js b/addon/system/store/container-instance-cache.js index 6dff1d2a348..c106dd661ed 100644 --- a/addon/system/store/container-instance-cache.js +++ b/addon/system/store/container-instance-cache.js @@ -27,7 +27,7 @@ export default function ContainerInstanceCache(owner) { ContainerInstanceCache.prototype = new EmptyObject(); Ember.merge(ContainerInstanceCache.prototype, { - get: function(type, preferredKey, fallbacks) { + get(type, preferredKey, fallbacks) { let cache = this._cache; let preferredLookupKey = `${type}:${preferredKey}`; @@ -40,7 +40,7 @@ Ember.merge(ContainerInstanceCache.prototype, { return cache[preferredLookupKey]; }, - _findInstance: function(type, fallbacks) { + _findInstance(type, fallbacks) { for (let i = 0, length = fallbacks.length; i < length; i++) { let fallback = fallbacks[i]; let lookupKey = `${type}:${fallback}`; @@ -52,7 +52,7 @@ Ember.merge(ContainerInstanceCache.prototype, { } }, - instanceFor: function(key) { + instanceFor(key) { let cache = this._cache; if (!cache[key]) { let instance = this._owner.lookup(key); @@ -63,7 +63,7 @@ Ember.merge(ContainerInstanceCache.prototype, { return cache[key]; }, - destroy: function() { + destroy() { let cache = this._cache; let cacheEntries = Object.keys(cache); @@ -79,7 +79,7 @@ Ember.merge(ContainerInstanceCache.prototype, { constructor: ContainerInstanceCache, - toString: function() { + toString() { return 'ContainerInstanceCache'; } }); diff --git a/addon/system/store/serializers.js b/addon/system/store/serializers.js index 58f4a976a40..f0e9453bfb5 100644 --- a/addon/system/store/serializers.js +++ b/addon/system/store/serializers.js @@ -7,7 +7,7 @@ export function serializerForAdapter(store, adapter, type) { if (serializer === null || serializer === undefined) { serializer = { - extract: function(store, type, payload) { return payload; } + extract(store, type, payload) { return payload; } }; } diff --git a/addon/transforms/boolean.js b/addon/transforms/boolean.js index c054f395d9c..05b81296cf8 100644 --- a/addon/transforms/boolean.js +++ b/addon/transforms/boolean.js @@ -23,7 +23,7 @@ import Transform from "ember-data/transforms/base"; @namespace DS */ export default Transform.extend({ - deserialize: function(serialized) { + deserialize(serialized) { var type = typeof serialized; if (type === "boolean") { @@ -37,7 +37,7 @@ export default Transform.extend({ } }, - serialize: function(deserialized) { + serialize(deserialized) { return Boolean(deserialized); } }); diff --git a/addon/transforms/date.js b/addon/transforms/date.js index 814dab640d1..f828b634089 100644 --- a/addon/transforms/date.js +++ b/addon/transforms/date.js @@ -21,7 +21,7 @@ import Transform from "ember-data/transforms/base"; export default Transform.extend({ - deserialize: function(serialized) { + deserialize(serialized) { var type = typeof serialized; if (type === "string") { @@ -37,7 +37,7 @@ export default Transform.extend({ } }, - serialize: function(date) { + serialize(date) { if (date instanceof Date) { return date.toISOString(); } else { diff --git a/addon/transforms/number.js b/addon/transforms/number.js index 6463756fc1f..cd8b98b4ef8 100644 --- a/addon/transforms/number.js +++ b/addon/transforms/number.js @@ -29,7 +29,7 @@ function isNumber(value) { @namespace DS */ export default Transform.extend({ - deserialize: function(serialized) { + deserialize(serialized) { var transformed; if (empty(serialized)) { @@ -41,7 +41,7 @@ export default Transform.extend({ } }, - serialize: function(deserialized) { + serialize(deserialized) { var transformed; if (empty(deserialized)) { diff --git a/addon/transforms/string.js b/addon/transforms/string.js index edce67db6a7..75db271fff4 100644 --- a/addon/transforms/string.js +++ b/addon/transforms/string.js @@ -24,10 +24,10 @@ var none = Ember.isNone; @namespace DS */ export default Transform.extend({ - deserialize: function(serialized) { + deserialize(serialized) { return none(serialized) ? null : String(serialized); }, - serialize: function(deserialized) { + serialize(deserialized) { return none(deserialized) ? null : String(deserialized); } }); From 9a57fa05aa6233425b2b04a61bbd1ec65bd4315a Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Fri, 13 Nov 2015 09:55:20 -0500 Subject: [PATCH 23/24] [CLEANUP] `ember watson:methodify tests/` Convert to ES6 function declarations in tests. --- .../helpers/ember-assertions/deprecations.js | 4 +- .../method-call-expectation.js | 10 +- .../adapter/build-url-mixin-test.js | 4 +- .../adapter/json-api-adapter-test.js | 4 +- tests/integration/adapter/queries-test.js | 4 +- .../adapter/record-persistence-test.js | 4 +- .../integration/adapter/rest-adapter-test.js | 24 ++-- tests/integration/adapter/serialize-test.js | 4 +- .../integration/adapter/store-adapter-test.js | 10 +- tests/integration/application-test.js | 26 ++--- .../non-dasherized-lookups-test.js | 8 +- .../integration/client-id-generation-test.js | 4 +- tests/integration/debug-adapter-test.js | 6 +- tests/integration/filter-test.js | 30 ++--- tests/integration/inverse-test.js | 4 +- tests/integration/lifecycle-hooks-test.js | 4 +- tests/integration/multiple_stores_test.js | 4 +- tests/integration/peek-all-test.js | 4 +- .../integration/record-array-manager-test.js | 2 +- .../records/collection-save-test.js | 4 +- .../integration/records/delete-record-test.js | 4 +- tests/integration/records/load-test.js | 4 +- .../records/property-changes-test.js | 4 +- tests/integration/records/reload-test.js | 4 +- tests/integration/records/save-test.js | 4 +- tests/integration/records/unload-test.js | 4 +- .../relationships/belongs-to-test.js | 4 +- .../relationships/has-many-test.js | 18 +-- .../relationships/many-to-many-test.js | 4 +- .../relationships/one-to-many-test.js | 4 +- .../relationships/one-to-one-test.js | 4 +- .../polymorphic-mixins-belongs-to-test.js | 4 +- .../polymorphic-mixins-has-many-test.js | 4 +- .../embedded-records-mixin-test.js | 12 +- .../serializers/json-api-serializer-test.js | 4 +- .../serializers/json-serializer-test.js | 24 ++-- .../serializers/rest-serializer-test.js | 24 ++-- tests/integration/setup-container-test.js | 4 +- tests/integration/snapshot-test.js | 4 +- tests/integration/store-test.js | 10 +- .../store/json-api-validation-test.js | 4 +- tests/integration/store/query-record-test.js | 12 +- tests/test-helper.js | 2 +- .../adapter-populated-record-array-test.js | 4 +- .../build-url-mixin/path-for-type-test.js | 4 +- .../adapters/json-api-adapter/ajax-test.js | 10 +- tests/unit/adapters/rest-adapter/ajax-test.js | 6 +- .../group-records-for-find-many-test.js | 6 +- tests/unit/many-array-test.js | 10 +- tests/unit/model-test.js | 22 ++-- tests/unit/model/errors-test.js | 4 +- tests/unit/model/internal-model-test.js | 2 +- tests/unit/model/lifecycle-callbacks-test.js | 30 ++--- tests/unit/model/merge-test.js | 12 +- tests/unit/model/relationships-test.js | 2 +- .../unit/model/relationships/has-many-test.js | 2 +- tests/unit/model/rollback-attributes-test.js | 16 +-- tests/unit/record-array-test.js | 2 +- .../filtered-record-array-test.js | 2 +- tests/unit/states-test.js | 2 +- tests/unit/store/adapter-interop-test.js | 108 +++++++++--------- tests/unit/store/create-record-test.js | 4 +- tests/unit/store/has-record-for-id-test.js | 4 +- tests/unit/store/model-for-test.js | 4 +- tests/unit/store/peek-record-test.js | 4 +- tests/unit/store/push-test.js | 18 +-- tests/unit/store/serializer-for-test.js | 4 +- tests/unit/store/unload-test.js | 10 +- 68 files changed, 311 insertions(+), 311 deletions(-) diff --git a/tests/helpers/ember-assertions/deprecations.js b/tests/helpers/ember-assertions/deprecations.js index 4e7d69e798d..88884daff4a 100644 --- a/tests/helpers/ember-assertions/deprecations.js +++ b/tests/helpers/ember-assertions/deprecations.js @@ -4,7 +4,7 @@ const deprecations = { NONE: 99, // 99 problems and a deprecation ain't one expecteds: null, actuals: null, - stubEmber: function() { + stubEmber() { if (!deprecations.originalEmberDeprecate && Ember.deprecate !== deprecations.originalEmberDeprecate) { deprecations.originalEmberDeprecate = Ember.deprecate; } @@ -13,7 +13,7 @@ const deprecations = { deprecations.actuals.push([msg, test]); }; }, - restoreEmber: function() { + restoreEmber() { Ember.deprecate = deprecations.originalEmberDeprecate; } }; diff --git a/tests/helpers/ember-assertions/method-call-expectation.js b/tests/helpers/ember-assertions/method-call-expectation.js index b7d89ade8fe..05f0d5178e3 100644 --- a/tests/helpers/ember-assertions/method-call-expectation.js +++ b/tests/helpers/ember-assertions/method-call-expectation.js @@ -7,21 +7,21 @@ export default function MethodCallExpectation(target, property, testAssert) { } MethodCallExpectation.prototype = { - handleCall: function() { + handleCall() { this.sawCall = true; return this.originalMethod.apply(this.target, arguments); }, - stubMethod: function(fn) { + stubMethod(fn) { var context = this; this.originalMethod = this.target[this.property]; this.target[this.property] = function() { return context.handleCall.apply(context, arguments); }; }, - restoreMethod: function() { + restoreMethod() { this.target[this.property] = this.originalMethod; }, - runWithStub: function(fn) { + runWithStub(fn) { try { this.stubMethod(); fn(); @@ -29,7 +29,7 @@ MethodCallExpectation.prototype = { this.restoreMethod(); } }, - assert: function(fn) { + assert(fn) { this.runWithStub(); this.testAssert.ok(this.sawCall, "Expected "+this.property+" to be called."); } diff --git a/tests/integration/adapter/build-url-mixin-test.js b/tests/integration/adapter/build-url-mixin-test.js index c01e0865d7f..a1c53ce9737 100644 --- a/tests/integration/adapter/build-url-mixin-test.js +++ b/tests/integration/adapter/build-url-mixin-test.js @@ -10,7 +10,7 @@ var passedUrl; var run = Ember.run; module("integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter", { - beforeEach: function() { + beforeEach() { Post = DS.Model.extend({ name: DS.attr("string") }); @@ -156,7 +156,7 @@ test('buildURL - with full URLs in links', function(assert) { test('buildURL - with camelized names', function(assert) { adapter.setProperties({ - pathForType: function(type) { + pathForType(type) { var decamelized = Ember.String.decamelize(type); return Ember.String.underscore(Ember.String.pluralize(decamelized)); } diff --git a/tests/integration/adapter/json-api-adapter-test.js b/tests/integration/adapter/json-api-adapter-test.js index 20e789a13c5..c6d71aed99f 100644 --- a/tests/integration/adapter/json-api-adapter-test.js +++ b/tests/integration/adapter/json-api-adapter-test.js @@ -13,7 +13,7 @@ var run = Ember.run; var User, Post, Comment, Handle, GithubHandle, TwitterHandle, Company, DevelopmentShop, DesignStudio; module('integration/adapter/json-api-adapter - JSONAPIAdapter', { - beforeEach: function() { + beforeEach() { User = DS.Model.extend({ firstName: DS.attr('string'), lastName: DS.attr('string'), @@ -76,7 +76,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', { adapter = env.adapter; }, - afterEach: function() { + afterEach() { run(env.store, 'destroy'); } }); diff --git a/tests/integration/adapter/queries-test.js b/tests/integration/adapter/queries-test.js index 8045d85b3b1..8557997fba8 100644 --- a/tests/integration/adapter/queries-test.js +++ b/tests/integration/adapter/queries-test.js @@ -10,7 +10,7 @@ var Person, env, store, adapter; var run = Ember.run; module("integration/adapter/queries - Queries", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({ updatedAt: DS.attr('string'), name: DS.attr('string'), @@ -23,7 +23,7 @@ module("integration/adapter/queries - Queries", { adapter = env.adapter; }, - afterEach: function() { + afterEach() { run(env.container, 'destroy'); } }); diff --git a/tests/integration/adapter/record-persistence-test.js b/tests/integration/adapter/record-persistence-test.js index 1eda625b1c9..d1408bc591a 100644 --- a/tests/integration/adapter/record-persistence-test.js +++ b/tests/integration/adapter/record-persistence-test.js @@ -15,7 +15,7 @@ var all = Ember.RSVP.all; var hash = Ember.RSVP.hash; module("integration/adapter/record_persistence - Persisting Records", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({ updatedAt: attr('string'), name: attr('string'), @@ -33,7 +33,7 @@ module("integration/adapter/record_persistence - Persisting Records", { store = env.store; }, - afterEach: function() { + afterEach() { run(env.container, 'destroy'); } }); diff --git a/tests/integration/adapter/rest-adapter-test.js b/tests/integration/adapter/rest-adapter-test.js index f209197b839..4d99db2543c 100644 --- a/tests/integration/adapter/rest-adapter-test.js +++ b/tests/integration/adapter/rest-adapter-test.js @@ -11,7 +11,7 @@ var run = Ember.run; var get = Ember.get; module("integration/adapter/rest_adapter - REST Adapter", { - beforeEach: function() { + beforeEach() { Post = DS.Model.extend({ name: DS.attr("string") }); @@ -332,7 +332,7 @@ test("create - a serializer's attribute mapping takes precdence over keyForAttri name: 'given_name' }, - keyForAttribute: function(attr) { + keyForAttribute(attr) { return attr.toUpperCase(); } })); @@ -354,7 +354,7 @@ test("create - a serializer's attribute mapping takes precedence over keyForRela post: 'article' }, - keyForRelationship: function(attr, kind) { + keyForRelationship(attr, kind) { return attr.toUpperCase(); } })); @@ -379,7 +379,7 @@ test("create - a serializer's attribute mapping takes precedence over keyForRela comments: 'opinions' }, - keyForRelationship: function(attr, kind) { + keyForRelationship(attr, kind) { return attr.toUpperCase(); } })); @@ -1994,14 +1994,14 @@ test('groupRecordsForFindMany groups records correctly when singular URLs are en test('normalizeKey - to set up _ids and _id', function(assert) { env.registry.register('serializer:application', DS.RESTSerializer.extend({ - keyForAttribute: function(attr) { + keyForAttribute(attr) { return Ember.String.underscore(attr); }, - keyForBelongsTo: function(belongsTo) { + keyForBelongsTo(belongsTo) { }, - keyForRelationship: function(rel, kind) { + keyForRelationship(rel, kind) { if (kind === 'belongsTo') { var underscored = Ember.String.underscore(rel); return underscored + '_id'; @@ -2166,7 +2166,7 @@ test("calls adapter.handleResponse with the jqXHR and json", function(assert) { var originalAjax = Ember.$.ajax; var jqXHR = { status: 200, - getAllResponseHeaders: function() { return ''; } + getAllResponseHeaders() { return ''; } }; var data = { post: { @@ -2200,7 +2200,7 @@ test('calls handleResponse with jqXHR, jqXHR.responseText', function(assert) { var jqXHR = { status: 400, responseText: 'Nope lol', - getAllResponseHeaders: function() { return ''; } + getAllResponseHeaders() { return ''; } }; Ember.$.ajax = function(hash) { @@ -2228,7 +2228,7 @@ test("rejects promise if DS.AdapterError is returned from adapter.handleResponse assert.expect(3); var originalAjax = Ember.$.ajax; var jqXHR = { - getAllResponseHeaders: function() { return ''; } + getAllResponseHeaders() { return ''; } }; var data = { something: 'is invalid' @@ -2259,7 +2259,7 @@ test('on error appends errorThrown for sanity', function(assert) { var originalAjax = Ember.$.ajax; var jqXHR = { responseText: 'Nope lol', - getAllResponseHeaders: function() { return ''; } + getAllResponseHeaders() { return ''; } }; var errorThrown = new Error('nope!'); @@ -2291,7 +2291,7 @@ test('on error wraps the error string in an DS.AdapterError object', function(as var originalAjax = Ember.$.ajax; var jqXHR = { responseText: '', - getAllResponseHeaders: function() { return ''; } + getAllResponseHeaders() { return ''; } }; var errorThrown = 'nope!'; diff --git a/tests/integration/adapter/serialize-test.js b/tests/integration/adapter/serialize-test.js index 90d3565b87c..de40aa3182d 100644 --- a/tests/integration/adapter/serialize-test.js +++ b/tests/integration/adapter/serialize-test.js @@ -9,7 +9,7 @@ var run = Ember.run; var env, store, adapter, serializer; module("integration/adapter/serialize - DS.Adapter integration test", { - beforeEach: function() { + beforeEach() { var Person = DS.Model.extend({ name: DS.attr('string') }); @@ -20,7 +20,7 @@ module("integration/adapter/serialize - DS.Adapter integration test", { serializer = store.serializerFor('person'); }, - afterEach: function() { + afterEach() { run(env.container, 'destroy'); } }); diff --git a/tests/integration/adapter/store-adapter-test.js b/tests/integration/adapter/store-adapter-test.js index 169539001ff..1ccc6c3c418 100644 --- a/tests/integration/adapter/store-adapter-test.js +++ b/tests/integration/adapter/store-adapter-test.js @@ -24,7 +24,7 @@ var run = Ember.run; var Person, Dog, env, store, adapter; module("integration/adapter/store-adapter - DS.Store and DS.Adapter integration test", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({ updatedAt: DS.attr('string'), name: DS.attr('string'), @@ -41,7 +41,7 @@ module("integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter = env.adapter; }, - afterEach: function() { + afterEach() { run(env.container, 'destroy'); } }); @@ -1346,7 +1346,7 @@ test("An async hasMany relationship with links should not trigger shouldBackgrou post: Post, comment: Comment, adapter: DS.RESTAdapter.extend({ - findRecord: function() { + findRecord() { return { posts: { id: 1, @@ -1355,7 +1355,7 @@ test("An async hasMany relationship with links should not trigger shouldBackgrou } }; }, - findHasMany: function() { + findHasMany() { return Ember.RSVP.resolve({ comments: [ { id: 1, name: "FIRST" }, @@ -1364,7 +1364,7 @@ test("An async hasMany relationship with links should not trigger shouldBackgrou ] }); }, - shouldBackgroundReloadRecord: function() { + shouldBackgroundReloadRecord() { assert.ok(false, 'shouldBackgroundReloadRecord should not be called'); } }) diff --git a/tests/integration/application-test.js b/tests/integration/application-test.js index ca8a01fd5a5..519d359c2fa 100644 --- a/tests/integration/application-test.js +++ b/tests/integration/application-test.js @@ -26,7 +26,7 @@ function lookup(thing) { } module("integration/application - Injecting a Custom Store", { - beforeEach: function() { + beforeEach() { run(function() { app = Application.create({ StoreService: Store.extend({ isCustom: true }), @@ -40,7 +40,7 @@ module("integration/application - Injecting a Custom Store", { container = app.__container__; }, - afterEach: function() { + afterEach() { run(app, app.destroy); Ember.BOOTED = false; } @@ -69,7 +69,7 @@ test("The JSONAPIAdapter is the default adapter when no custom adapter is provid }); module("integration/application - Injecting the Default Store", { - beforeEach: function() { + beforeEach() { run(function() { app = Application.create({ FooController: Controller.extend(), @@ -81,7 +81,7 @@ module("integration/application - Injecting the Default Store", { container = app.__container__; }, - afterEach: function() { + afterEach() { run(app, 'destroy'); Ember.BOOTED = false; } @@ -106,7 +106,7 @@ test("the DS namespace should be accessible", function(assert) { if (Ember.inject && Ember.inject.service) { module("integration/application - Using the store as a service", { - beforeEach: function() { + beforeEach() { run(function() { app = Application.create({ DoodleService: Ember.Service.extend({ store: Ember.inject.service() }) @@ -116,7 +116,7 @@ if (Ember.inject && Ember.inject.service) { container = app.__container__; }, - afterEach: function() { + afterEach() { run(app, 'destroy'); Ember.BOOTED = false; } @@ -131,11 +131,11 @@ if (Ember.inject && Ember.inject.service) { } module("integration/application - Attaching initializer", { - beforeEach: function() { + beforeEach() { App = Application.extend(); }, - afterEach: function() { + afterEach() { if (app) { run(app, app.destroy); } @@ -148,7 +148,7 @@ test("ember-data initializer is run", function(assert) { App.initializer({ name: "after-ember-data", after: "ember-data", - initialize: function() { ran = true; } + initialize() { ran = true; } }); run(function() { @@ -167,7 +167,7 @@ test("ember-data initializer does not register the store service when it was alr App.initializer({ name: "after-ember-data", before: "ember-data", - initialize: function(registry) { + initialize(registry) { registry.register('service:store', AppStore); } }); @@ -187,7 +187,7 @@ test("store initializer is run (DEPRECATED)", function(assert) { App.initializer({ name: "after-store", after: 'store', - initialize: function() { ran = true; } + initialize() { ran = true; } }); run(function() { @@ -202,7 +202,7 @@ test("injectStore initializer is run (DEPRECATED)", function(assert) { App.initializer({ name: "after-store", after: 'injectStore', - initialize: function() { ran = true; } + initialize() { ran = true; } }); run(function() { @@ -217,7 +217,7 @@ test("transforms initializer is run (DEPRECATED)", function(assert) { App.initializer({ name: "after-store", after: 'transforms', - initialize: function() { ran = true; } + initialize() { ran = true; } }); run(function() { diff --git a/tests/integration/backwards-compat/non-dasherized-lookups-test.js b/tests/integration/backwards-compat/non-dasherized-lookups-test.js index f888fd15403..4741ad62c34 100644 --- a/tests/integration/backwards-compat/non-dasherized-lookups-test.js +++ b/tests/integration/backwards-compat/non-dasherized-lookups-test.js @@ -20,7 +20,7 @@ const { let store; module('integration/backwards-compat/non-dasherized-lookups - non dasherized lookups in application code finders', { - beforeEach: function() { + beforeEach() { const PostNote = Model.extend({ name: attr('string') }); @@ -39,7 +39,7 @@ module('integration/backwards-compat/non-dasherized-lookups - non dasherized loo store = env.store; }, - afterEach: function() { + afterEach() { run(store, 'destroy'); } }); @@ -89,7 +89,7 @@ test('can lookup records using under_scored strings', function(assert) { }); module('integration/backwards-compat/non-dasherized-lookups - non dasherized lookups in application code relationship macros', { - beforeEach: function() { + beforeEach() { const PostNote = Model.extend({ notePost: belongsTo('note-post', { async: false }), @@ -122,7 +122,7 @@ module('integration/backwards-compat/non-dasherized-lookups - non dasherized loo store = env.store; }, - afterEach: function() { + afterEach() { run(store, 'destroy'); } }); diff --git a/tests/integration/client-id-generation-test.js b/tests/integration/client-id-generation-test.js index 0f7c4ee2e06..72f008b5afa 100644 --- a/tests/integration/client-id-generation-test.js +++ b/tests/integration/client-id-generation-test.js @@ -10,7 +10,7 @@ var Post, Comment, Misc, env; var run = Ember.run; module("integration/client_id_generation - Client-side ID Generation", { - beforeEach: function() { + beforeEach() { Comment = DS.Model.extend({ post: DS.belongsTo('post', { async: false }) }); @@ -30,7 +30,7 @@ module("integration/client_id_generation - Client-side ID Generation", { }); }, - afterEach: function() { + afterEach() { run(env.container, 'destroy'); } }); diff --git a/tests/integration/debug-adapter-test.js b/tests/integration/debug-adapter-test.js index 4b08bce091f..41631bb2670 100644 --- a/tests/integration/debug-adapter-test.js +++ b/tests/integration/debug-adapter-test.js @@ -9,7 +9,7 @@ var get = Ember.get; var run = Ember.run; module("DS.DebugAdapter", { - beforeEach: function() { + beforeEach() { Ember.run(function() { App = Ember.Application.create(); App.toString = function() { return 'App'; }; @@ -35,12 +35,12 @@ module("DS.DebugAdapter", { debugAdapter = App.__container__.lookup('data-adapter:main'); debugAdapter.reopen({ - getModelTypes: function() { + getModelTypes() { return Ember.A([{ klass: App.__container__.lookupFactory('model:post'), name: 'post' }]); } }); }, - afterEach: function() { + afterEach() { run(App, App.destroy); } }); diff --git a/tests/integration/filter-test.js b/tests/integration/filter-test.js index 846b56cd646..3f359de96d6 100644 --- a/tests/integration/filter-test.js +++ b/tests/integration/filter-test.js @@ -14,7 +14,7 @@ var run = Ember.run; var Person, store, env, array, recordArray; module("integration/filter - DS.Model updating", { - beforeEach: function() { + beforeEach() { array = [{ id: '1', type: 'person', @@ -47,7 +47,7 @@ module("integration/filter - DS.Model updating", { env = setupStore({ person: Person }); store = env.store; }, - afterEach: function() { + afterEach() { run(store, 'destroy'); Person = null; array = null; @@ -210,7 +210,7 @@ test("a filtered record array includes created elements", function(assert) { test("a Record Array can update its filter", function(assert) { customAdapter(env, DS.Adapter.extend({ - deleteRecord: function(store, type, snapshot) { + deleteRecord(store, type, snapshot) { return Ember.RSVP.resolve(); }, shouldBackgroundReloadRecord: () => false @@ -284,7 +284,7 @@ test("a Record Array can update its filter", function(assert) { test("a Record Array can update its filter and notify array observers", function(assert) { customAdapter(env, DS.Adapter.extend({ - deleteRecord: function(store, type, snapshot) { + deleteRecord(store, type, snapshot) { return Ember.RSVP.resolve(); }, shouldBackgroundReloadRecord: () => false @@ -319,7 +319,7 @@ test("a Record Array can update its filter and notify array observers", function var arrayObserver = { arrayWillChange: Ember.K, - arrayDidChange: function(array, idx, removed, added) { + arrayDidChange(array, idx, removed, added) { didChangeIdx = idx; didChangeRemoved += removed; didChangeAdded += added; @@ -461,7 +461,7 @@ test("a filter created after a record is already loaded works", function(assert) test("filter with query persists query on the resulting filteredRecordArray", function(assert) { customAdapter(env, DS.Adapter.extend({ - query: function(store, type, id) { + query(store, type, id) { return Ember.RSVP.resolve([{ id: id, name: "Tom Dale" @@ -489,7 +489,7 @@ test("it is possible to filter by state flags", function(assert) { var filter; customAdapter(env, DS.Adapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { return Ember.RSVP.resolve({ id: id, name: "Tom Dale" }); } })); @@ -519,7 +519,7 @@ test("it is possible to filter by state flags", function(assert) { test("it is possible to filter loaded records by dirtiness", function(assert) { customAdapter(env, DS.Adapter.extend({ - updateRecord: function() { + updateRecord() { return Ember.RSVP.resolve(); }, shouldBackgroundReloadRecord: () => false @@ -561,7 +561,7 @@ test("it is possible to filter loaded records by dirtiness", function(assert) { test("it is possible to filter created records by dirtiness", function(assert) { run(function() { customAdapter(env, DS.Adapter.extend({ - createRecord: function() { + createRecord() { return Ember.RSVP.resolve(); }, shouldBackgroundReloadRecord: () => false @@ -596,7 +596,7 @@ test("it is possible to filter created records by dirtiness", function(assert) { test("it is possible to filter created records by isReloading", function(assert) { customAdapter(env, DS.Adapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { return Ember.RSVP.resolve({ id: 1, name: "Tom Dalle" @@ -669,7 +669,7 @@ var setup = function(assert, serverCallbacks) { test("a Record Array can update its filter after server-side updates one record", function(assert) { setup(assert, { - updateRecord: function(store, type, snapshot) { + updateRecord(store, type, snapshot) { return Ember.RSVP.resolve({ id: 1, name: "Scumbag Server-side Dale" }); }, shouldBackgroundReloadRecord: () => false @@ -684,7 +684,7 @@ test("a Record Array can update its filter after server-side updates one record" test("a Record Array can update its filter after server-side updates multiple records", function(assert) { setup(assert, { - updateRecord: function(store, type, snapshot) { + updateRecord(store, type, snapshot) { switch (snapshot.id) { case "1": return Ember.RSVP.resolve({ id: 1, name: "Scumbag Server-side Dale" }); @@ -704,7 +704,7 @@ test("a Record Array can update its filter after server-side updates multiple re test("a Record Array can update its filter after server-side creates one record", function(assert) { setup(assert, { - createRecord: function(store, type, snapshot) { + createRecord(store, type, snapshot) { return Ember.RSVP.resolve({ id: 4, name: "Scumbag Server-side Tim" }); } }); @@ -718,7 +718,7 @@ test("a Record Array can update its filter after server-side creates one record" test("a Record Array can update its filter after server-side creates multiple records", function(assert) { setup(assert, { - createRecord: function(store, type, snapshot) { + createRecord(store, type, snapshot) { switch (snapshot.attr('name')) { case "Client-side Mike": return Ember.RSVP.resolve({ id: 4, name: "Scumbag Server-side Mike" }); @@ -737,7 +737,7 @@ test("a Record Array can update its filter after server-side creates multiple re test("a Record Array can update its filter after server-side creates multiple records", function(assert) { setup(assert, { - createRecord: function(store, type, snapshot) { + createRecord(store, type, snapshot) { switch (snapshot.attr('name')) { case "Client-side Mike": return Ember.RSVP.resolve({ id: 4, name: "Scumbag Server-side Mike" }); diff --git a/tests/integration/inverse-test.js b/tests/integration/inverse-test.js index c1d7b8f1e72..dab9266bce3 100644 --- a/tests/integration/inverse-test.js +++ b/tests/integration/inverse-test.js @@ -16,7 +16,7 @@ function stringify(string) { } module('integration/inverse_test - inverseFor', { - beforeEach: function() { + beforeEach() { User = DS.Model.extend({ name: attr('string'), bestFriend: belongsTo('user', { async: true, inverse: null }), @@ -51,7 +51,7 @@ module('integration/inverse_test - inverseFor', { ReflexiveModel = store.modelFor('reflexive-model'); }, - afterEach: function() { + afterEach() { run(env.container, 'destroy'); } }); diff --git a/tests/integration/lifecycle-hooks-test.js b/tests/integration/lifecycle-hooks-test.js index 4dec8fd5522..35ad90e0823 100644 --- a/tests/integration/lifecycle-hooks-test.js +++ b/tests/integration/lifecycle-hooks-test.js @@ -11,7 +11,7 @@ var resolve = Ember.RSVP.resolve; var run = Ember.run; module("integration/lifecycle_hooks - Lifecycle Hooks", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({ name: attr('string') }); @@ -21,7 +21,7 @@ module("integration/lifecycle_hooks - Lifecycle Hooks", { }); }, - afterEach: function() { + afterEach() { run(env.container, 'destroy'); } }); diff --git a/tests/integration/multiple_stores_test.js b/tests/integration/multiple_stores_test.js index c959862e5bf..c7708821b92 100644 --- a/tests/integration/multiple_stores_test.js +++ b/tests/integration/multiple_stores_test.js @@ -9,7 +9,7 @@ var SuperVillain, HomePlanet, EvilMinion; var run = Ember.run; module("integration/multiple_stores - Multiple Stores Tests", { - setup: function() { + setup() { SuperVillain = DS.Model.extend({ firstName: DS.attr('string'), lastName: DS.attr('string'), @@ -41,7 +41,7 @@ module("integration/multiple_stores - Multiple Stores Tests", { env.store_b = env.container.lookup('store:store-b'); }, - teardown: function() { + teardown() { run(env.store, 'destroy'); } }); diff --git a/tests/integration/peek-all-test.js b/tests/integration/peek-all-test.js index 263c81d2a27..b505d0a8a2e 100644 --- a/tests/integration/peek-all-test.js +++ b/tests/integration/peek-all-test.js @@ -11,7 +11,7 @@ var run = Ember.run; var Person, store, array, moreArray; module("integration/peek-all - DS.Store#peekAll()", { - beforeEach: function() { + beforeEach() { array = { data: [{ type: 'person', @@ -41,7 +41,7 @@ module("integration/peek-all - DS.Store#peekAll()", { store = createStore({ person: Person }); }, - afterEach: function() { + afterEach() { run(store, 'destroy'); Person = null; array = null; diff --git a/tests/integration/record-array-manager-test.js b/tests/integration/record-array-manager-test.js index fafc0a741f2..a0906991a60 100644 --- a/tests/integration/record-array-manager-test.js +++ b/tests/integration/record-array-manager-test.js @@ -26,7 +26,7 @@ Car.toString = function() { return "Car"; }; var manager; module("integration/record_array_manager", { - beforeEach: function() { + beforeEach() { env = setupStore({ adapter: DS.RESTAdapter.extend() }); diff --git a/tests/integration/records/collection-save-test.js b/tests/integration/records/collection-save-test.js index 96725228daa..cf35717c74d 100644 --- a/tests/integration/records/collection-save-test.js +++ b/tests/integration/records/collection-save-test.js @@ -9,7 +9,7 @@ var Post, env; var run = Ember.run; module("integration/records/collection_save - Save Collection of Records", { - beforeEach: function() { + beforeEach() { Post = DS.Model.extend({ title: DS.attr('string') }); @@ -19,7 +19,7 @@ module("integration/records/collection_save - Save Collection of Records", { env = setupStore({ post: Post }); }, - afterEach: function() { + afterEach() { run(env.container, 'destroy'); } }); diff --git a/tests/integration/records/delete-record-test.js b/tests/integration/records/delete-record-test.js index ee4ef87ccf1..54e9a86b8ff 100644 --- a/tests/integration/records/delete-record-test.js +++ b/tests/integration/records/delete-record-test.js @@ -10,7 +10,7 @@ var Person, env; var run = Ember.run; module("integration/deletedRecord - Deleting Records", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({ name: attr('string') }); @@ -22,7 +22,7 @@ module("integration/deletedRecord - Deleting Records", { }); }, - afterEach: function() { + afterEach() { Ember.run(function() { env.container.destroy(); }); diff --git a/tests/integration/records/load-test.js b/tests/integration/records/load-test.js index 690adc61cc3..c2dd0dd7eb5 100644 --- a/tests/integration/records/load-test.js +++ b/tests/integration/records/load-test.js @@ -10,7 +10,7 @@ var Post, Comment, env; var run = Ember.run; module("integration/load - Loading Records", { - beforeEach: function() { + beforeEach() { Post = DS.Model.extend({ comments: hasMany({ async: true }) }); @@ -23,7 +23,7 @@ module("integration/load - Loading Records", { env = setupStore({ post: Post, comment: Comment }); }, - afterEach: function() { + afterEach() { run(env.container, 'destroy'); } }); diff --git a/tests/integration/records/property-changes-test.js b/tests/integration/records/property-changes-test.js index 66fec67ba61..212fd19f3c7 100644 --- a/tests/integration/records/property-changes-test.js +++ b/tests/integration/records/property-changes-test.js @@ -10,7 +10,7 @@ var attr = DS.attr; var run = Ember.run; module('integration/records/property-changes - Property changes', { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({ firstName: attr('string'), lastName: attr('string') @@ -23,7 +23,7 @@ module('integration/records/property-changes - Property changes', { store = env.store; }, - afterEach: function() { + afterEach() { Ember.run(function() { env.container.destroy(); }); diff --git a/tests/integration/records/reload-test.js b/tests/integration/records/reload-test.js index 8252bb714d6..4e5af020d77 100644 --- a/tests/integration/records/reload-test.js +++ b/tests/integration/records/reload-test.js @@ -11,7 +11,7 @@ var Person, env; var run = Ember.run; module("integration/reload - Reloading Records", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({ updatedAt: attr('string'), name: attr('string'), @@ -24,7 +24,7 @@ module("integration/reload - Reloading Records", { env = setupStore({ person: Person }); }, - afterEach: function() { + afterEach() { run(env.container, 'destroy'); } }); diff --git a/tests/integration/records/save-test.js b/tests/integration/records/save-test.js index a8e09a5ce82..b467c676e01 100644 --- a/tests/integration/records/save-test.js +++ b/tests/integration/records/save-test.js @@ -9,7 +9,7 @@ var Post, env; var run = Ember.run; module("integration/records/save - Save Record", { - beforeEach: function() { + beforeEach() { Post = DS.Model.extend({ title: DS.attr('string') }); @@ -19,7 +19,7 @@ module("integration/records/save - Save Record", { env = setupStore({ post: Post }); }, - afterEach: function() { + afterEach() { run(env.container, 'destroy'); } }); diff --git a/tests/integration/records/unload-test.js b/tests/integration/records/unload-test.js index 619378f2fc9..2a145a02047 100644 --- a/tests/integration/records/unload-test.js +++ b/tests/integration/records/unload-test.js @@ -33,7 +33,7 @@ var Car = DS.Model.extend({ Car.toString = function() { return "Car"; }; module("integration/unload - Unloading Records", { - beforeEach: function() { + beforeEach() { env = setupStore({ person: Person, car: Car, @@ -41,7 +41,7 @@ module("integration/unload - Unloading Records", { }); }, - afterEach: function() { + afterEach() { Ember.run(function() { env.container.destroy(); }); diff --git a/tests/integration/relationships/belongs-to-test.js b/tests/integration/relationships/belongs-to-test.js index 507dd9998a1..66949a24a98 100644 --- a/tests/integration/relationships/belongs-to-test.js +++ b/tests/integration/relationships/belongs-to-test.js @@ -30,7 +30,7 @@ function getComputedPropertyDesc(model, key) { } module("integration/relationship/belongs_to Belongs-To Relationships", { - beforeEach: function() { + beforeEach() { User = DS.Model.extend({ name: attr('string'), messages: hasMany('message', { polymorphic: true, async: false }), @@ -98,7 +98,7 @@ module("integration/relationship/belongs_to Belongs-To Relationships", { Author = store.modelFor('author'); }, - afterEach: function() { + afterEach() { run(env.container, 'destroy'); } }); diff --git a/tests/integration/relationships/has-many-test.js b/tests/integration/relationships/has-many-test.js index 2828d6da6b9..122873d950b 100644 --- a/tests/integration/relationships/has-many-test.js +++ b/tests/integration/relationships/has-many-test.js @@ -20,7 +20,7 @@ function stringify(string) { } module("integration/relationships/has_many - Has-Many Relationships", { - beforeEach: function() { + beforeEach() { User = DS.Model.extend({ name: attr('string'), messages: hasMany('message', { polymorphic: true, async: false }), @@ -91,7 +91,7 @@ module("integration/relationships/has_many - Has-Many Relationships", { store = env.store; }, - afterEach: function() { + afterEach() { run(env.container, 'destroy'); } }); @@ -1766,12 +1766,12 @@ test("ManyArray notifies the array observers and flushes bindings when removing" chapter = env.store.peekRecord('chapter', 1); chapter.get('pages').addEnumerableObserver(this, { - willChange: function(pages, removing, addCount) { + willChange(pages, removing, addCount) { if (observe) { assert.equal(removing[0], page2, 'page2 is passed to willChange'); } }, - didChange: function(pages, removeCount, adding) { + didChange(pages, removeCount, adding) { if (observe) { assert.equal(removeCount, 1, 'removeCount is correct'); } @@ -1824,12 +1824,12 @@ test("ManyArray notifies the array observers and flushes bindings when adding", chapter = env.store.peekRecord('chapter', 1); chapter.get('pages').addEnumerableObserver(this, { - willChange: function(pages, removing, addCount) { + willChange(pages, removing, addCount) { if (observe) { assert.equal(addCount, 1, 'addCount is correct'); } }, - didChange: function(pages, removeCount, adding) { + didChange(pages, removeCount, adding) { if (observe) { assert.equal(adding[0], page2, 'page2 is passed to didChange'); } @@ -2006,13 +2006,13 @@ test("adding and removing records from hasMany relationship #2666", function(ass }); env.registry.register('adapter:comment', DS.RESTAdapter.extend({ - deleteRecord: function(record) { + deleteRecord(record) { return Ember.RSVP.resolve(); }, - updateRecord: function(record) { + updateRecord(record) { return Ember.RSVP.resolve(); }, - createRecord: function() { + createRecord() { return Ember.RSVP.resolve(); } })); diff --git a/tests/integration/relationships/many-to-many-test.js b/tests/integration/relationships/many-to-many-test.js index 45b6400b455..e2eb3499bfb 100644 --- a/tests/integration/relationships/many-to-many-test.js +++ b/tests/integration/relationships/many-to-many-test.js @@ -16,7 +16,7 @@ function stringify(string) { } module('integration/relationships/many_to_many_test - ManyToMany relationships', { - beforeEach: function() { + beforeEach() { User = DS.Model.extend({ name: attr('string'), topics: hasMany('topic', { async: true }), @@ -51,7 +51,7 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', store = env.store; }, - afterEach: function() { + afterEach() { run(function() { env.container.destroy(); }); diff --git a/tests/integration/relationships/one-to-many-test.js b/tests/integration/relationships/one-to-many-test.js index e6c5c92d9ff..d9eb6f073dd 100644 --- a/tests/integration/relationships/one-to-many-test.js +++ b/tests/integration/relationships/one-to-many-test.js @@ -18,7 +18,7 @@ function stringify(string) { } module('integration/relationships/one_to_many_test - OneToMany relationships', { - beforeEach: function() { + beforeEach() { User = DS.Model.extend({ name: attr('string'), messages: hasMany('message', { async: true }), @@ -50,7 +50,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', { store = env.store; }, - afterEach: function() { + afterEach() { run(env.container, 'destroy'); } }); diff --git a/tests/integration/relationships/one-to-one-test.js b/tests/integration/relationships/one-to-one-test.js index 91ab933dd8d..500eec53a81 100644 --- a/tests/integration/relationships/one-to-one-test.js +++ b/tests/integration/relationships/one-to-one-test.js @@ -16,7 +16,7 @@ function stringify(string) { } module('integration/relationships/one_to_one_test - OneToOne relationships', { - beforeEach: function() { + beforeEach() { User = DS.Model.extend({ name: attr('string'), bestFriend: belongsTo('user', { async: true, inverse: 'bestFriend' }), @@ -41,7 +41,7 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', { store = env.store; }, - afterEach: function() { + afterEach() { run(env.container, 'destroy'); } }); diff --git a/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js b/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js index 2f7624477be..7be85133732 100644 --- a/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js +++ b/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js @@ -16,7 +16,7 @@ function stringify(string) { } module('integration/relationships/polymorphic_mixins_belongs_to_test - Polymorphic belongsTo relationships with mixins', { - beforeEach: function() { + beforeEach() { User = DS.Model.extend({ name: attr('string'), bestMessage: belongsTo('message', { async: true, polymorphic: true }) @@ -47,7 +47,7 @@ module('integration/relationships/polymorphic_mixins_belongs_to_test - Polymorph store = env.store; }, - afterEach: function() { + afterEach() { run(env.container, 'destroy'); } }); diff --git a/tests/integration/relationships/polymorphic-mixins-has-many-test.js b/tests/integration/relationships/polymorphic-mixins-has-many-test.js index d528b00cc71..ef06a8bb159 100644 --- a/tests/integration/relationships/polymorphic-mixins-has-many-test.js +++ b/tests/integration/relationships/polymorphic-mixins-has-many-test.js @@ -17,7 +17,7 @@ function stringify(string) { } module('integration/relationships/polymorphic_mixins_has_many_test - Polymorphic hasMany relationships with mixins', { - beforeEach: function() { + beforeEach() { User = DS.Model.extend({ name: attr('string'), messages: hasMany('message', { async: true, polymorphic: true }) @@ -48,7 +48,7 @@ module('integration/relationships/polymorphic_mixins_has_many_test - Polymorphic store = env.store; }, - afterEach: function() { + afterEach() { run(env.container, 'destroy'); } }); diff --git a/tests/integration/serializers/embedded-records-mixin-test.js b/tests/integration/serializers/embedded-records-mixin-test.js index ddddfeca4d4..c2122b0e1c0 100644 --- a/tests/integration/serializers/embedded-records-mixin-test.js +++ b/tests/integration/serializers/embedded-records-mixin-test.js @@ -12,7 +12,7 @@ var run = Ember.run; var LightSaber; module("integration/embedded_records_mixin - EmbeddedRecordsMixin", { - beforeEach: function() { + beforeEach() { SuperVillain = DS.Model.extend({ firstName: DS.attr('string'), lastName: DS.attr('string'), @@ -75,7 +75,7 @@ module("integration/embedded_records_mixin - EmbeddedRecordsMixin", { //env.amsAdapter = env.container.lookup("adapter:-active-model"); }, - afterEach: function() { + afterEach() { run(env.store, 'destroy'); } }); @@ -569,7 +569,7 @@ test("normalizeResponse with embedded objects with identical relationship and at villains: { embedded: 'always' } }, //Makes the keyForRelationship and keyForAttribute collide. - keyForRelationship: function(key, type) { + keyForRelationship(key, type) { return this.keyForAttribute(key, type); } })); @@ -910,7 +910,7 @@ test("serialize with embedded objects and a custom keyForAttribute (hasMany rela }); env.registry.register('serializer:home-planet', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { - keyForAttribute: function(key) { + keyForAttribute(key) { return key + '-custom'; }, attrs: { @@ -2062,11 +2062,11 @@ test("serializing relationships with an embedded and without calls super when no var calledSerializeHasMany = false; var Serializer = DS.RESTSerializer.extend({ - serializeBelongsTo: function(snapshot, json, relationship) { + serializeBelongsTo(snapshot, json, relationship) { calledSerializeBelongsTo = true; return this._super(snapshot, json, relationship); }, - serializeHasMany: function(snapshot, json, relationship) { + serializeHasMany(snapshot, json, relationship) { calledSerializeHasMany = true; var key = relationship.key; var payloadKey = this.keyForRelationship ? this.keyForRelationship(key, "hasMany") : key; diff --git a/tests/integration/serializers/json-api-serializer-test.js b/tests/integration/serializers/json-api-serializer-test.js index 6d8af4f3954..dea465a6b63 100644 --- a/tests/integration/serializers/json-api-serializer-test.js +++ b/tests/integration/serializers/json-api-serializer-test.js @@ -13,7 +13,7 @@ var run = Ember.run; var User, Handle, GithubHandle, TwitterHandle, Company, Project; module('integration/serializers/json-api-serializer - JSONAPISerializer', { - beforeEach: function() { + beforeEach() { User = DS.Model.extend({ firstName: DS.attr('string'), lastName: DS.attr('string'), @@ -58,7 +58,7 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', { serializer = store.serializerFor('-json-api'); }, - afterEach: function() { + afterEach() { run(env.store, 'destroy'); } }); diff --git a/tests/integration/serializers/json-serializer-test.js b/tests/integration/serializers/json-serializer-test.js index e6a4bc71895..1af7b5f0a33 100644 --- a/tests/integration/serializers/json-serializer-test.js +++ b/tests/integration/serializers/json-serializer-test.js @@ -9,7 +9,7 @@ var Post, post, Comment, comment, Favorite, favorite, env; var run = Ember.run; module("integration/serializer/json - JSONSerializer", { - beforeEach: function() { + beforeEach() { Post = DS.Model.extend({ title: DS.attr('string'), comments: DS.hasMany('comment', { inverse: null, async: false }) @@ -31,7 +31,7 @@ module("integration/serializer/json - JSONSerializer", { env.store.modelFor('favorite'); }, - afterEach: function() { + afterEach() { run(env.store, 'destroy'); } }); @@ -81,7 +81,7 @@ test("serializeAttribute", function(assert) { test("serializeAttribute respects keyForAttribute", function(assert) { env.registry.register('serializer:post', DS.JSONSerializer.extend({ - keyForAttribute: function(key) { + keyForAttribute(key) { return key.toUpperCase(); } })); @@ -140,7 +140,7 @@ test("async serializeBelongsTo with null", function(assert) { test("serializeBelongsTo respects keyForRelationship", function(assert) { env.registry.register('serializer:post', DS.JSONSerializer.extend({ - keyForRelationship: function(key, type) { + keyForRelationship(key, type) { return key.toUpperCase(); } })); @@ -159,7 +159,7 @@ test("serializeBelongsTo respects keyForRelationship", function(assert) { test("serializeHasMany respects keyForRelationship", function(assert) { env.registry.register('serializer:post', DS.JSONSerializer.extend({ - keyForRelationship: function(key, type) { + keyForRelationship(key, type) { return key.toUpperCase(); } })); @@ -218,7 +218,7 @@ test("serializePolymorphicType sync", function(assert) { assert.expect(1); env.registry.register('serializer:comment', DS.JSONSerializer.extend({ - serializePolymorphicType: function(record, json, relationship) { + serializePolymorphicType(record, json, relationship) { var key = relationship.key; var belongsTo = record.belongsTo(key); json[relationship.key + "TYPE"] = belongsTo.modelName; @@ -243,7 +243,7 @@ test("serializePolymorphicType async", function(assert) { }); env.registry.register('serializer:comment', DS.JSONSerializer.extend({ - serializePolymorphicType: function(record, json, relationship) { + serializePolymorphicType(record, json, relationship) { assert.ok(true, 'serializePolymorphicType is called when serialize a polymorphic belongsTo'); } })); @@ -264,7 +264,7 @@ test("normalizeResponse normalizes each record in the array", function(assert) { ]; env.registry.register('serializer:post', DS.JSONSerializer.extend({ - normalize: function () { + normalize() { postNormalizeCount++; return this._super.apply(this, arguments); } @@ -628,7 +628,7 @@ test("Serializer should respect the primaryKey attribute when serializing record test("Serializer should respect keyForAttribute when extracting records", function(assert) { env.registry.register('serializer:post', DS.JSONSerializer.extend({ - keyForAttribute: function(key) { + keyForAttribute(key) { return key.toUpperCase(); } })); @@ -643,7 +643,7 @@ test("Serializer should respect keyForAttribute when extracting records", functi test("Serializer should respect keyForRelationship when extracting records", function(assert) { env.registry.register('serializer:post', DS.JSONSerializer.extend({ - keyForRelationship: function(key, type) { + keyForRelationship(key, type) { return key.toUpperCase(); } })); @@ -705,7 +705,7 @@ test('serializeBelongsTo with async polymorphic', function(assert) { var expected = { post: '1', postTYPE: 'post' }; env.registry.register('serializer:favorite', DS.JSONSerializer.extend({ - serializePolymorphicType: function(snapshot, json, relationship) { + serializePolymorphicType(snapshot, json, relationship) { var key = relationship.key; json[key + 'TYPE'] = snapshot.belongsTo(key).modelName; } @@ -782,7 +782,7 @@ test('extractErrors leaves payload untouched if it has no errors property', func test('normalizeResponse should extract meta using extractMeta', function(assert) { env.registry.register("serializer:post", DS.JSONSerializer.extend({ - extractMeta: function(store, modelClass, payload) { + extractMeta(store, modelClass, payload) { let meta = this._super(...arguments); meta.authors.push('Tomhuda'); return meta; diff --git a/tests/integration/serializers/rest-serializer-test.js b/tests/integration/serializers/rest-serializer-test.js index 6b8203df6f5..0cd724b24d9 100644 --- a/tests/integration/serializers/rest-serializer-test.js +++ b/tests/integration/serializers/rest-serializer-test.js @@ -9,7 +9,7 @@ var HomePlanet, league, SuperVillain, EvilMinion, YellowMinion, DoomsdayDevice, var run = Ember.run; module("integration/serializer/rest - RESTSerializer", { - beforeEach: function() { + beforeEach() { HomePlanet = DS.Model.extend({ name: DS.attr('string'), superVillains: DS.hasMany('super-villain', { async: false }) @@ -64,7 +64,7 @@ module("integration/serializer/rest - RESTSerializer", { env.store.modelFor('container'); }, - afterEach: function() { + afterEach() { run(env.store, 'destroy'); } }); @@ -79,7 +79,7 @@ test("modelNameFromPayloadKey returns always same modelName even for uncountable test('normalizeResponse should extract meta using extractMeta', function(assert) { env.registry.register("serializer:home-planet", DS.RESTSerializer.extend({ - extractMeta: function(store, modelClass, payload) { + extractMeta(store, modelClass, payload) { let meta = this._super(...arguments); meta.authors.push('Tomhuda'); return meta; @@ -257,7 +257,7 @@ test("normalizeResponse loads secondary records with correct serializer", functi var superVillainNormalizeCount = 0; env.registry.register('serializer:super-villain', DS.RESTSerializer.extend({ - normalize: function() { + normalize() { superVillainNormalizeCount++; return this._super.apply(this, arguments); } @@ -294,7 +294,7 @@ test("normalizeResponse loads secondary records with correct serializer", functi var superVillainNormalizeCount = 0; env.registry.register('serializer:super-villain', DS.RESTSerializer.extend({ - normalize: function() { + normalize() { superVillainNormalizeCount++; return this._super.apply(this, arguments); } @@ -315,7 +315,7 @@ test("normalizeResponse loads secondary records with correct serializer", functi test('normalizeHash normalizes specific parts of the payload', function(assert) { env.registry.register('serializer:application', DS.RESTSerializer.extend({ normalizeHash: { - homePlanets: function(hash) { + homePlanets(hash) { hash.id = hash._id; delete hash._id; return hash; @@ -355,7 +355,7 @@ test('normalizeHash normalizes specific parts of the payload', function(assert) test('normalizeHash works with transforms', function(assert) { env.registry.register('serializer:application', DS.RESTSerializer.extend({ normalizeHash: { - evilMinions: function(hash) { + evilMinions(hash) { hash.condition = hash._condition; delete hash._condition; return hash; @@ -364,14 +364,14 @@ test('normalizeHash works with transforms', function(assert) { })); env.registry.register('transform:condition', DS.Transform.extend({ - deserialize: function(serialized) { + deserialize(serialized) { if (serialized === 1) { return "healing"; } else { return "unknown"; } }, - serialize: function(deserialized) { + serialize(deserialized) { if (deserialized === "healing") { return 1; } else { @@ -399,7 +399,7 @@ test('normalize should allow for different levels of normalization', function(as attrs: { superVillain: 'is_super_villain' }, - keyForAttribute: function(attr) { + keyForAttribute(attr) { return Ember.String.decamelize(attr); } })); @@ -421,7 +421,7 @@ test('normalize should allow for different levels of normalization - attributes' attrs: { name: 'full_name' }, - keyForAttribute: function(attr) { + keyForAttribute(attr) { return Ember.String.decamelize(attr); } })); @@ -565,7 +565,7 @@ test('serializeIntoHash uses payloadKeyFromModelName to normalize the payload ro }); var json = {}; env.registry.register('serializer:home-planet', DS.RESTSerializer.extend({ - payloadKeyFromModelName: function(modelName) { + payloadKeyFromModelName(modelName) { return Ember.String.dasherize(modelName); } })); diff --git a/tests/integration/setup-container-test.js b/tests/integration/setup-container-test.js index 79a6e7b343a..6fabea2a7fe 100644 --- a/tests/integration/setup-container-test.js +++ b/tests/integration/setup-container-test.js @@ -17,7 +17,7 @@ var container, registry, application; */ module("integration/setup-container - Setting up a container", { - beforeEach: function() { + beforeEach() { run(function() { application = Ember.Application.create(); }); @@ -36,7 +36,7 @@ module("integration/setup-container - Setting up a container", { setupContainer(setupContainerArgument); }, - afterEach: function() { + afterEach() { run(function() { application.destroy(); }); diff --git a/tests/integration/snapshot-test.js b/tests/integration/snapshot-test.js index 6a0aa14eeac..b63a5941892 100644 --- a/tests/integration/snapshot-test.js +++ b/tests/integration/snapshot-test.js @@ -9,7 +9,7 @@ var run = Ember.run; var env, Post, Comment; module("integration/snapshot - DS.Snapshot", { - beforeEach: function() { + beforeEach() { Post = DS.Model.extend({ author: DS.attr(), title: DS.attr(), @@ -26,7 +26,7 @@ module("integration/snapshot - DS.Snapshot", { }); }, - afterEach: function() { + afterEach() { run(function() { env.store.destroy(); }); diff --git a/tests/integration/store-test.js b/tests/integration/store-test.js index c371cd72130..da609bdc517 100644 --- a/tests/integration/store-test.js +++ b/tests/integration/store-test.js @@ -35,7 +35,7 @@ function initializeStore(adapter) { } module("integration/store - destroy", { - beforeEach: function() { + beforeEach() { initializeStore(DS.Adapter.extend()); } }); @@ -62,7 +62,7 @@ test("destroying record during find doesn't cause error", function(assert) { let done = assert.async(); var TestAdapter = DS.Adapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { return new Ember.RSVP.Promise(function(resolve, reject) { Ember.run.next(function() { store.unloadAll(type.modelName); @@ -87,7 +87,7 @@ test("find calls do not resolve when the store is destroyed", function(assert) { let done = assert.async(); var TestAdapter = DS.Adapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { store.destroy(); Ember.RSVP.resolve(null); } @@ -336,7 +336,7 @@ test('store#findRecord call with `id` of type different than non-empty string or }); module("integration/store - findAll", { - beforeEach: function() { + beforeEach() { initializeStore(DS.RESTAdapter.extend()); } }); @@ -527,7 +527,7 @@ test("Using store#serializerFor should not throw an error when looking up the ap }); module("integration/store - deleteRecord", { - beforeEach: function() { + beforeEach() { initializeStore(DS.RESTAdapter.extend()); } }); diff --git a/tests/integration/store/json-api-validation-test.js b/tests/integration/store/json-api-validation-test.js index e53ab3708d4..e3481ce6888 100644 --- a/tests/integration/store/json-api-validation-test.js +++ b/tests/integration/store/json-api-validation-test.js @@ -7,7 +7,7 @@ var Person, store, env; var run = Ember.run; module("integration/store/json-validation", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({ updatedAt: DS.attr('string'), name: DS.attr('string'), @@ -21,7 +21,7 @@ module("integration/store/json-validation", { store = env.store; }, - afterEach: function() { + afterEach() { run(store, 'destroy'); } }); diff --git a/tests/integration/store/query-record-test.js b/tests/integration/store/query-record-test.js index b093c3c6e65..a695dec0354 100644 --- a/tests/integration/store/query-record-test.js +++ b/tests/integration/store/query-record-test.js @@ -9,7 +9,7 @@ var Person, store, env; var run = Ember.run; module("integration/store/query-record - Query one record with a query hash", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({ updatedAt: DS.attr('string'), name: DS.attr('string'), @@ -23,7 +23,7 @@ module("integration/store/query-record - Query one record with a query hash", { store = env.store; }, - afterEach: function() { + afterEach() { run(store, 'destroy'); } }); @@ -44,7 +44,7 @@ test("When a record is requested, the adapter's queryRecord method should be cal assert.expect(1); env.registry.register('adapter:person', DS.Adapter.extend({ - queryRecord: function(store, type, query) { + queryRecord(store, type, query) { assert.equal(type, Person, "the query method is called with the correct type"); return Ember.RSVP.resolve({ id: 1, name: "Peter Wagenet" }); } @@ -57,7 +57,7 @@ test("When a record is requested, the adapter's queryRecord method should be cal test("When a record is requested, and the promise is rejected, .queryRecord() is rejected.", function(assert) { env.registry.register('adapter:person', DS.Adapter.extend({ - queryRecord: function(store, type, query) { + queryRecord(store, type, query) { return Ember.RSVP.reject(); } })); @@ -73,14 +73,14 @@ test("When a record is requested, the serializer's normalizeQueryRecordResponse assert.expect(1); env.registry.register('serializer:person', DS.JSONAPISerializer.extend({ - normalizeQueryRecordResponse: function(store, primaryModelClass, payload, id, requestType) { + normalizeQueryRecordResponse(store, primaryModelClass, payload, id, requestType) { assert.equal(payload.data.id , '1', "the normalizeQueryRecordResponse method was called with the right payload"); return this._super(...arguments); } })); env.registry.register('adapter:person', DS.Adapter.extend({ - queryRecord: function(store, type, query) { + queryRecord(store, type, query) { return Ember.RSVP.resolve({ data: { id: '1', diff --git a/tests/test-helper.js b/tests/test-helper.js index 545280303fb..ce98f980535 100644 --- a/tests/test-helper.js +++ b/tests/test-helper.js @@ -47,7 +47,7 @@ QUnit.begin(function() { // Prevent all tests involving serialization to require a container DS.JSONSerializer.reopen({ - transformFor: function(attributeType) { + transformFor(attributeType) { return this._super(attributeType, true) || transforms[attributeType]; } }); diff --git a/tests/unit/adapter-populated-record-array-test.js b/tests/unit/adapter-populated-record-array-test.js index bc33894420d..c808c47025d 100644 --- a/tests/unit/adapter-populated-record-array-test.js +++ b/tests/unit/adapter-populated-record-array-test.js @@ -9,13 +9,13 @@ var Person, store; var run = Ember.run; var adapter = DS.Adapter.extend({ - deleteRecord: function() { + deleteRecord() { return Ember.RSVP.Promise.resolve(); } }); module("unit/adapter_populated_record_array - DS.AdapterPopulatedRecordArray", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({ name: DS.attr('string') }); diff --git a/tests/unit/adapters/build-url-mixin/path-for-type-test.js b/tests/unit/adapters/build-url-mixin/path-for-type-test.js index 3f33e8d445c..8aae7373d3d 100644 --- a/tests/unit/adapters/build-url-mixin/path-for-type-test.js +++ b/tests/unit/adapters/build-url-mixin/path-for-type-test.js @@ -6,11 +6,11 @@ import {module, test} from 'qunit'; var env, adapter; module("unit/adapters/build-url-mixin/path-for-type - DS.BuildURLMixin#pathForType", { - beforeEach: function() { + beforeEach() { // test for overriden pathForType methods which return null path values var customPathForType = { - pathForType: function(type) { + pathForType(type) { if (type === 'rootModel') { return ''; } return this._super(type); } diff --git a/tests/unit/adapters/json-api-adapter/ajax-test.js b/tests/unit/adapters/json-api-adapter/ajax-test.js index d802bfcb101..992e4adeb69 100644 --- a/tests/unit/adapters/json-api-adapter/ajax-test.js +++ b/tests/unit/adapters/json-api-adapter/ajax-test.js @@ -9,7 +9,7 @@ var Person, Place, store, adapter, env; var run = Ember.run; module("unit/adapters/json-api-adapter/ajax - building requests", { - beforeEach: function() { + beforeEach() { Person = { modelName: 'person' }; Place = { modelName: 'place' }; env = setupStore({ adapter: DS.JSONAPIAdapter, person: Person, place: Place }); @@ -17,7 +17,7 @@ module("unit/adapters/json-api-adapter/ajax - building requests", { adapter = env.adapter; }, - afterEach: function() { + afterEach() { run(function() { store.destroy(); env.container.destroy(); @@ -31,7 +31,7 @@ test("ajaxOptions() adds Accept when no other headers exist", function(assert) { var ajaxOptions = adapter.ajaxOptions(url, type, {}); var receivedHeaders = []; var fakeXHR = { - setRequestHeader: function(key, value) { + setRequestHeader(key, value) { receivedHeaders.push([key, value]); } }; @@ -46,7 +46,7 @@ test("ajaxOptions() adds Accept header to existing headers", function(assert) { var ajaxOptions = adapter.ajaxOptions(url, type, {}); var receivedHeaders = []; var fakeXHR = { - setRequestHeader: function(key, value) { + setRequestHeader(key, value) { receivedHeaders.push([key, value]); } }; @@ -63,7 +63,7 @@ test("ajaxOptions() adds Accept header to existing computed properties headers", var ajaxOptions = adapter.ajaxOptions(url, type, {}); var receivedHeaders = []; var fakeXHR = { - setRequestHeader: function(key, value) { + setRequestHeader(key, value) { receivedHeaders.push([key, value]); } }; diff --git a/tests/unit/adapters/rest-adapter/ajax-test.js b/tests/unit/adapters/rest-adapter/ajax-test.js index 12d817f5cba..ade40bc15d3 100644 --- a/tests/unit/adapters/rest-adapter/ajax-test.js +++ b/tests/unit/adapters/rest-adapter/ajax-test.js @@ -9,7 +9,7 @@ var Person, Place, store, adapter, env; var run = Ember.run; module("unit/adapters/rest-adapter/ajax - building requests", { - beforeEach: function() { + beforeEach() { Person = { modelName: 'person' }; Place = { modelName: 'place' }; env = setupStore({ adapter: DS.RESTAdapter, person: Person, place: Place }); @@ -17,7 +17,7 @@ module("unit/adapters/rest-adapter/ajax - building requests", { adapter = env.adapter; }, - afterEach: function() { + afterEach() { run(function() { store.destroy(); env.container.destroy(); @@ -58,7 +58,7 @@ test("ajaxOptions() headers are set", function(assert) { var ajaxOptions = adapter.ajaxOptions(url, type, {}); var receivedHeaders = []; var fakeXHR = { - setRequestHeader: function(key, value) { + setRequestHeader(key, value) { receivedHeaders.push([key, value]); } }; diff --git a/tests/unit/adapters/rest-adapter/group-records-for-find-many-test.js b/tests/unit/adapters/rest-adapter/group-records-for-find-many-test.js index eb230dc6d7f..2354905055e 100644 --- a/tests/unit/adapters/rest-adapter/group-records-for-find-many-test.js +++ b/tests/unit/adapters/rest-adapter/group-records-for-find-many-test.js @@ -10,16 +10,16 @@ var maxLength = -1; var lengths = Ember.A([]); module("unit/adapters/rest_adapter/group_records_for_find_many_test - DS.RESTAdapter#groupRecordsForFindMany", { - beforeEach: function() { + beforeEach() { GroupsAdapter = DS.RESTAdapter.extend({ coalesceFindRequests: true, - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { return Ember.RSVP.Promise.resolve({ id: id }); }, - ajax: function(url, type, options) { + ajax(url, type, options) { var queryString = options.data.ids.map(function(i) { return encodeURIComponent('ids[]') + '=' + encodeURIComponent(i); }).join('&'); diff --git a/tests/unit/many-array-test.js b/tests/unit/many-array-test.js index f1609d723c8..1ef1edf24e7 100644 --- a/tests/unit/many-array-test.js +++ b/tests/unit/many-array-test.js @@ -14,7 +14,7 @@ var run = Ember.run; var Post, Tag; module("unit/many_array - DS.ManyArray", { - beforeEach: function() { + beforeEach() { Post = DS.Model.extend({ title: attr('string'), tags: hasMany('tag', { async: false }) @@ -38,7 +38,7 @@ module("unit/many_array - DS.ManyArray", { store = env.store; }, - afterEach: function() { + afterEach() { run(function() { store.destroy(); }); @@ -50,7 +50,7 @@ test("manyArray.save() calls save() on all records", function(assert) { run(function() { Tag.reopen({ - save: function() { + save() { assert.ok(true, 'record.save() was called'); return Ember.RSVP.resolve(); } @@ -101,13 +101,13 @@ test("manyArray trigger arrayContentChange functions with the correct values", f var originalArrayContentWillChange = DS.ManyArray.prototype.arrayContentWillChange; var originalArrayContentDidChange = DS.ManyArray.prototype.arrayContentDidChange; DS.ManyArray.reopen({ - arrayContentWillChange: function(startIdx, removeAmt, addAmt) { + arrayContentWillChange(startIdx, removeAmt, addAmt) { willChangeStartIdx = startIdx; willChangeRemoveAmt = removeAmt; willChangeAddAmt = addAmt; return this._super.apply(this, arguments); }, - arrayContentDidChange: function(startIdx, removeAmt, addAmt) { + arrayContentDidChange(startIdx, removeAmt, addAmt) { assert.equal(startIdx, willChangeStartIdx, 'WillChange and DidChange startIdx should match'); assert.equal(removeAmt, willChangeRemoveAmt, 'WillChange and DidChange removeAmt should match'); assert.equal(addAmt, willChangeAddAmt, 'WillChange and DidChange addAmt should match'); diff --git a/tests/unit/model-test.js b/tests/unit/model-test.js index 119a9df82b4..54af7217039 100644 --- a/tests/unit/model-test.js +++ b/tests/unit/model-test.js @@ -13,7 +13,7 @@ var run = Ember.run; var Person, store, env; module("unit/model - DS.Model", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({ name: DS.attr('string'), isDrugAddict: DS.attr('boolean') @@ -25,7 +25,7 @@ module("unit/model - DS.Model", { store = env.store; }, - afterEach: function() { + afterEach() { run(function() { store.destroy(); }); @@ -476,7 +476,7 @@ test("currentState is accessible when the record is created", function(assert) { }); module("unit/model - DS.Model updating", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({ name: DS.attr('string') }); env = setupStore({ person: Person @@ -506,7 +506,7 @@ module("unit/model - DS.Model updating", { }); }); }, - afterEach: function() { + afterEach() { run(function() { store.destroy(); Person = null; @@ -555,7 +555,7 @@ test("a DS.model can define 'setUnknownProperty'", function(assert) { var Tag = DS.Model.extend({ name: DS.attr("string"), - setUnknownProperty: function(key, value) { + setUnknownProperty(key, value) { if (key === "title") { this.set("name", value); } @@ -577,7 +577,7 @@ test("a DS.model can define 'setUnknownProperty'", function(assert) { test("a defaultValue for an attribute can be a function", function(assert) { var Tag = DS.Model.extend({ createdAt: DS.attr('string', { - defaultValue: function() { + defaultValue() { return "le default value"; } }) @@ -599,7 +599,7 @@ test("a defaultValue function gets the record, options, and key", function(asser var Tag = DS.Model.extend({ createdAt: DS.attr('string', { - defaultValue: function(record, options, key) { + defaultValue(record, options, key) { assert.deepEqual(record, tag, "the record is passed in properly"); assert.equal(key, 'createdAt', "the attribute being defaulted is passed in properly"); return "le default value"; @@ -702,7 +702,7 @@ test("setting a property back to its original value removes the property from th }); module("unit/model - with a simple Person model", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({ name: DS.attr('string') }); @@ -733,7 +733,7 @@ module("unit/model - with a simple Person model", { }); }); }, - afterEach: function() { + afterEach() { run(function() { store.destroy(); Person = null; @@ -993,7 +993,7 @@ test("ensure model exits loading state, materializes data and fulfills promise o var store = createStore({ adapter: DS.Adapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { return Ember.RSVP.resolve({ id: 1, name: "John" }); } }), @@ -1145,7 +1145,7 @@ test('accessing attributes in the initializer should not throw an error', functi var Person = DS.Model.extend({ name: DS.attr('string'), - init: function() { + init() { this._super.apply(this, arguments); assert.ok(!this.get('name')); } diff --git a/tests/unit/model/errors-test.js b/tests/unit/model/errors-test.js index 26367a11d60..9569a80c4de 100644 --- a/tests/unit/model/errors-test.js +++ b/tests/unit/model/errors-test.js @@ -6,11 +6,11 @@ const AssertPrototype = QUnit.assert; var errors; module("unit/model/errors", { - beforeEach: function() { + beforeEach() { errors = DS.Errors.create(); }, - afterEach: function() { + afterEach() { } }); diff --git a/tests/unit/model/internal-model-test.js b/tests/unit/model/internal-model-test.js index c273b9752e7..a6cc3690c79 100644 --- a/tests/unit/model/internal-model-test.js +++ b/tests/unit/model/internal-model-test.js @@ -7,7 +7,7 @@ module("unit/model/internal-model - Internal Model"); function MockModelFactory () { } MockModelFactory._create = function() { - return { trigger: function() {} }; + return { trigger() {} }; }; MockModelFactory.eachRelationship = function() { }; diff --git a/tests/unit/model/lifecycle-callbacks-test.js b/tests/unit/model/lifecycle-callbacks-test.js index 6c9778d505a..04b0fb8ae2c 100644 --- a/tests/unit/model/lifecycle-callbacks-test.js +++ b/tests/unit/model/lifecycle-callbacks-test.js @@ -15,13 +15,13 @@ test("a record receives a didLoad callback when it has finished loading", functi var Person = DS.Model.extend({ name: DS.attr(), - didLoad: function() { + didLoad() { assert.ok("The didLoad callback was called"); } }); var adapter = DS.Adapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { return Ember.RSVP.resolve({ id: 1, name: "Foo" }); } }); @@ -44,7 +44,7 @@ test("TEMPORARY: a record receives a didLoad callback once it materializes if it var didLoadCalled = 0; var Person = DS.Model.extend({ name: DS.attr(), - didLoad: function() { + didLoad() { didLoadCalled++; } }); @@ -74,7 +74,7 @@ test("a record receives a didUpdate callback when it has finished updating", fun bar: DS.attr('string'), name: DS.attr('string'), - didUpdate: function() { + didUpdate() { callCount++; assert.equal(get(this, 'isSaving'), false, "record should be saving"); assert.equal(get(this, 'hasDirtyAttributes'), false, "record should not be dirty"); @@ -82,11 +82,11 @@ test("a record receives a didUpdate callback when it has finished updating", fun }); var adapter = DS.Adapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { return Ember.RSVP.resolve({ id: 1, name: "Foo" }); }, - updateRecord: function(store, type, snapshot) { + updateRecord(store, type, snapshot) { assert.equal(callCount, 0, "didUpdate callback was not called until didSaveRecord is called"); return Ember.RSVP.resolve(); @@ -122,7 +122,7 @@ test("a record receives a didCreate callback when it has finished updating", fun var callCount = 0; var Person = DS.Model.extend({ - didCreate: function() { + didCreate() { callCount++; assert.equal(get(this, 'isSaving'), false, "record should not be saving"); assert.equal(get(this, 'hasDirtyAttributes'), false, "record should not be dirty"); @@ -130,7 +130,7 @@ test("a record receives a didCreate callback when it has finished updating", fun }); var adapter = DS.Adapter.extend({ - createRecord: function(store, type, snapshot) { + createRecord(store, type, snapshot) { assert.equal(callCount, 0, "didCreate callback was not called until didSaveRecord is called"); return Ember.RSVP.resolve(); @@ -166,7 +166,7 @@ test("a record receives a didDelete callback when it has finished deleting", fun bar: DS.attr('string'), name: DS.attr('string'), - didDelete: function() { + didDelete() { callCount++; assert.equal(get(this, 'isSaving'), false, "record should not be saving"); @@ -175,11 +175,11 @@ test("a record receives a didDelete callback when it has finished deleting", fun }); var adapter = DS.Adapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { return Ember.RSVP.resolve({ id: 1, name: "Foo" }); }, - deleteRecord: function(store, type, snapshot) { + deleteRecord(store, type, snapshot) { assert.equal(callCount, 0, "didDelete callback was not called until didSaveRecord is called"); return Ember.RSVP.resolve(); @@ -219,7 +219,7 @@ test("an uncommited record also receives a didDelete callback when it is deleted bar: DS.attr('string'), name: DS.attr('string'), - didDelete: function() { + didDelete() { callCount++; assert.equal(get(this, 'isSaving'), false, "record should not be saving"); assert.equal(get(this, 'hasDirtyAttributes'), false, "record should not be dirty"); @@ -254,7 +254,7 @@ test("a record receives a becameInvalid callback when it became invalid", functi bar: DS.attr('string'), name: DS.attr('string'), - becameInvalid: function() { + becameInvalid() { callCount++; assert.equal(get(this, 'isSaving'), false, "record should not be saving"); @@ -263,11 +263,11 @@ test("a record receives a becameInvalid callback when it became invalid", functi }); var adapter = DS.Adapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { return Ember.RSVP.resolve({ id: 1, name: "Foo" }); }, - updateRecord: function(store, type, snapshot) { + updateRecord(store, type, snapshot) { assert.equal(callCount, 0, "becameInvalid callback was not called until recordWasInvalid is called"); return Ember.RSVP.reject(new DS.InvalidError([ diff --git a/tests/unit/model/merge-test.js b/tests/unit/model/merge-test.js index 4647f4b2cde..11ae3cd9a03 100644 --- a/tests/unit/model/merge-test.js +++ b/tests/unit/model/merge-test.js @@ -9,7 +9,7 @@ var Person; var run = Ember.run; module("unit/model/merge - Merging", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({ name: DS.attr(), city: DS.attr() @@ -21,7 +21,7 @@ test("When a record is in flight, changes can be made", function(assert) { assert.expect(3); var adapter = DS.Adapter.extend({ - createRecord: function(store, type, snapshot) { + createRecord(store, type, snapshot) { return Ember.RSVP.resolve({ id: 1, name: "Tom Dale" }); } }); @@ -54,7 +54,7 @@ test("Make sure snapshot is created at save time not at flush time", function(as assert.expect(5); var adapter = DS.Adapter.extend({ - updateRecord: function(store, type, snapshot) { + updateRecord(store, type, snapshot) { assert.equal(snapshot.attr('name'), 'Thomas Dale'); return Ember.RSVP.resolve(); @@ -97,7 +97,7 @@ test("When a record is in flight, pushes are applied underneath the in flight ch assert.expect(6); var adapter = DS.Adapter.extend({ - updateRecord: function(store, type, snapshot) { + updateRecord(store, type, snapshot) { // Make sure saving isn't resolved synchronously return new Ember.RSVP.Promise(function(resolve, reject) { run.next(null, resolve, { id: 1, name: "Senor Thomas Dale, Esq.", city: "Portland" }); @@ -246,7 +246,7 @@ test("A record with no changes can still be saved", function(assert) { assert.expect(1); var adapter = DS.Adapter.extend({ - updateRecord: function(store, type, snapshot) { + updateRecord(store, type, snapshot) { return Ember.RSVP.resolve({ id: 1, name: "Thomas Dale" }); } }); @@ -280,7 +280,7 @@ test("A dirty record can be reloaded", function(assert) { assert.expect(3); var adapter = DS.Adapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { return Ember.RSVP.resolve({ id: 1, name: "Thomas Dale", city: "Portland" }); } }); diff --git a/tests/unit/model/relationships-test.js b/tests/unit/model/relationships-test.js index 6c8f833165b..751acb84407 100644 --- a/tests/unit/model/relationships-test.js +++ b/tests/unit/model/relationships-test.js @@ -10,7 +10,7 @@ var run = Ember.run; var Occupation, Person, store; module("unit/model/relationships - DS.Model", { - beforeEach: function() { + beforeEach() { Occupation = DS.Model.extend(); Person = DS.Model.extend({ diff --git a/tests/unit/model/relationships/has-many-test.js b/tests/unit/model/relationships/has-many-test.js index 7904740ae67..ea6342a200d 100644 --- a/tests/unit/model/relationships/has-many-test.js +++ b/tests/unit/model/relationships/has-many-test.js @@ -10,7 +10,7 @@ var run = Ember.run; var env; module("unit/model/relationships - DS.hasMany", { - beforeEach: function() { + beforeEach() { env = setupStore(); } }); diff --git a/tests/unit/model/rollback-attributes-test.js b/tests/unit/model/rollback-attributes-test.js index f9d77bdee3c..1014af6ec95 100644 --- a/tests/unit/model/rollback-attributes-test.js +++ b/tests/unit/model/rollback-attributes-test.js @@ -9,7 +9,7 @@ var env, store, Person, Dog; var run = Ember.run; module("unit/model/rollbackAttributes - model.rollbackAttributes()", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({ firstName: DS.attr(), lastName: DS.attr() @@ -225,7 +225,7 @@ test("invalid new record's attributes can be rollbacked", function(assert) { } ]); var adapter = DS.RESTAdapter.extend({ - ajax: function(url, type, hash) { + ajax(url, type, hash) { return Ember.RSVP.reject(error); } }); @@ -255,7 +255,7 @@ test("invalid record's attributes can be rollbacked after multiple failed calls var person; var adapter = DS.RESTAdapter.extend({ - ajax: function(url, type, hash) { + ajax(url, type, hash) { var error = new DS.InvalidError(); return Ember.RSVP.reject(error); } @@ -336,7 +336,7 @@ test("invalid record's attributes can be rollbacked", function(assert) { ]); var adapter = DS.RESTAdapter.extend({ - ajax: function(url, type, hash) { + ajax(url, type, hash) { return Ember.RSVP.reject(error); } }); @@ -363,10 +363,10 @@ test("invalid record's attributes can be rollbacked", function(assert) { }); dog.get('errors').addArrayObserver({}, { - willChange: function() { + willChange() { assert.ok(true, 'errors will change'); }, - didChange: function() { + didChange() { assert.ok(true, 'errors did change'); } }); @@ -397,7 +397,7 @@ test("invalid record's attributes rolled back to correct state after set", funct ]); var adapter = DS.RESTAdapter.extend({ - ajax: function(url, type, hash) { + ajax(url, type, hash) { return Ember.RSVP.reject(error); } }); @@ -464,7 +464,7 @@ test("when destroying a record setup the record state to invalid, the record's a ]); var adapter = DS.RESTAdapter.extend({ - ajax: function(url, type, hash) { + ajax(url, type, hash) { return Ember.RSVP.reject(error); } }); diff --git a/tests/unit/record-array-test.js b/tests/unit/record-array-test.js index f2098914034..0d03cb07743 100644 --- a/tests/unit/record-array-test.js +++ b/tests/unit/record-array-test.js @@ -12,7 +12,7 @@ var Person, array; var run = Ember.run; module("unit/record_array - DS.RecordArray", { - beforeEach: function() { + beforeEach() { array = [{ id: '1', name: "Scumbag Dale" }, { id: '2', name: "Scumbag Katz" }, { id: '3', name: "Scumbag Bryn" }]; Person = DS.Model.extend({ diff --git a/tests/unit/record-arrays/filtered-record-array-test.js b/tests/unit/record-arrays/filtered-record-array-test.js index 725f7428961..a8c08be4713 100644 --- a/tests/unit/record-arrays/filtered-record-array-test.js +++ b/tests/unit/record-arrays/filtered-record-array-test.js @@ -5,7 +5,7 @@ import {module, test} from 'qunit'; var filteredArray; module("unit/record-arrays/filtered-record-array - DS.FilteredRecordArray", { - beforeEach: function() { + beforeEach() { filteredArray = DS.FilteredRecordArray.create({ type: 'recordType' }); } }); diff --git a/tests/unit/states-test.js b/tests/unit/states-test.js index 12f5e4c0372..a46274c5524 100644 --- a/tests/unit/states-test.js +++ b/tests/unit/states-test.js @@ -9,7 +9,7 @@ var get = Ember.get; var rootState, stateName; module("unit/states - Flags for record states", { - beforeEach: function() { + beforeEach() { rootState = DS.RootState; } }); diff --git a/tests/unit/store/adapter-interop-test.js b/tests/unit/store/adapter-interop-test.js index 9bdff260cbb..c665d281c7c 100644 --- a/tests/unit/store/adapter-interop-test.js +++ b/tests/unit/store/adapter-interop-test.js @@ -13,12 +13,12 @@ var TestAdapter, store, person, oldFilterEnabled; var run = Ember.run; module("unit/store/adapter-interop - DS.Store working with a DS.Adapter", { - beforeEach: function() { + beforeEach() { TestAdapter = DS.Adapter.extend(); oldFilterEnabled = Ember.ENV.ENABLE_DS_FILTER; Ember.ENV.ENABLE_DS_FILTER = false; }, - afterEach: function() { + afterEach() { run(function() { if (store) { store.destroy(); } Ember.ENV.ENABLE_DS_FILTER = oldFilterEnabled; @@ -52,7 +52,7 @@ test("Calling Store#find invokes its adapter#find", function(assert) { let done = assert.async(); var adapter = TestAdapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { assert.ok(true, "Adapter#find was called"); assert.equal(store, currentStore, "Adapter#find was called with the right store"); assert.equal(type, store.modelFor('test'), "Adapter#find was called with the type passed into Store#find"); @@ -77,10 +77,10 @@ test("Calling Store#findRecord multiple times coalesces the calls into a adapter let done = assert.async(); var adapter = TestAdapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { assert.ok(false, "Adapter#findRecord was not called"); }, - findMany: function(store, type, ids, snapshots) { + findMany(store, type, ids, snapshots) { assert.ok(true, "Adapter#findMany was called"); assert.deepEqual(ids, ["1","2"], 'Correct ids were passed in to findMany'); return Ember.RSVP.resolve([{ id: 1 }, { id: 2 }]); @@ -104,7 +104,7 @@ test("Returning a promise from `findRecord` asynchronously loads data", function assert.expect(1); var adapter = TestAdapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { return resolve({ id: 1, name: "Scumbag Dale" }); } }); @@ -125,7 +125,7 @@ test("IDs provided as numbers are coerced to strings", function(assert) { assert.expect(5); var adapter = TestAdapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { assert.equal(typeof id, 'string', "id has been normalized to a string"); return resolve({ id: 1, name: "Scumbag Sylvain" }); } @@ -223,7 +223,7 @@ test("loadMany takes an optional Object and passes it on to the Adapter", functi }); var adapter = TestAdapter.extend({ - query: function(store, type, query) { + query(store, type, query) { assert.equal(type, store.modelFor('person'), 'The type was Person'); assert.equal(query, passedQuery, "The query was passed in"); return Ember.RSVP.resolve([]); @@ -248,7 +248,7 @@ test("Find with query calls the correct normalizeResponse", function(assert) { }); var adapter = TestAdapter.extend({ - query: function(store, type, query) { + query(store, type, query) { return Ember.RSVP.resolve([]); } }); @@ -256,7 +256,7 @@ test("Find with query calls the correct normalizeResponse", function(assert) { var callCount = 0; var ApplicationSerializer = DS.JSONSerializer.extend({ - normalizeQueryResponse: function() { + normalizeQueryResponse() { callCount++; return this._super(...arguments); } @@ -349,7 +349,7 @@ test("a new record with a specific id can't be created if this id is already use }); Person.reopenClass({ - toString: function() { + toString() { return 'Person'; } }); @@ -415,7 +415,7 @@ test("initial values of attributes can be passed in as the third argument to fin assert.expect(1); var adapter = TestAdapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { assert.equal(snapshot.attr('name'), 'Test', 'Preloaded attribtue set'); return Ember.RSVP.resolve({ id: '1', name: 'Test' }); } @@ -438,7 +438,7 @@ test("initial values of attributes can be passed in as the third argument to fin test("initial values of belongsTo can be passed in as the third argument to find as records", function(assert) { assert.expect(1); var adapter = TestAdapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { assert.equal(snapshot.belongsTo('friend').attr('name'), 'Tom', 'Preloaded belongsTo set'); return new Ember.RSVP.Promise(function() {}); } @@ -476,7 +476,7 @@ test("initial values of belongsTo can be passed in as the third argument to find assert.expect(1); var adapter = TestAdapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { return Ember.RSVP.Promise.resolve({ id: id }); } }); @@ -505,7 +505,7 @@ test("initial values of belongsTo can be passed in as the third argument to find test("initial values of hasMany can be passed in as the third argument to find as records", function(assert) { assert.expect(1); var adapter = TestAdapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { assert.equal(snapshot.hasMany('friends')[0].attr('name'), 'Tom', 'Preloaded hasMany set'); return new Ember.RSVP.Promise(function() {}); } @@ -543,7 +543,7 @@ test("initial values of hasMany can be passed in as the third argument to find a assert.expect(1); var adapter = TestAdapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { assert.equal(snapshot.hasMany('friends')[0].id, '2', 'Preloaded hasMany set'); return Ember.RSVP.resolve({ id: id }); } @@ -575,7 +575,7 @@ test("records should have their ids updated when the adapter returns the id data var idCounter = 1; var adapter = TestAdapter.extend({ - createRecord: function(store, type, snapshot) { + createRecord(store, type, snapshot) { return Ember.RSVP.resolve({ name: snapshot.attr('name'), id: idCounter++ }); } }); @@ -634,7 +634,7 @@ test("store.scheduleFetchMany should not resolve until all the records are resol var Phone = DS.Model.extend(); var adapter = TestAdapter.extend({ - findRecord: function (store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { var wait = 5; var record = { id: id }; @@ -646,7 +646,7 @@ test("store.scheduleFetchMany should not resolve until all the records are resol }); }, - findMany: function(store, type, ids, snapshots) { + findMany(store, type, ids, snapshots) { var wait = 15; var records = ids.map(function(id) { @@ -691,19 +691,19 @@ test("the store calls adapter.findMany according to groupings returned by adapte var Person = DS.Model.extend(); var adapter = TestAdapter.extend({ - groupRecordsForFindMany: function(store, snapshots) { + groupRecordsForFindMany(store, snapshots) { return [ [snapshots[0]], [snapshots[1], snapshots[2]] ]; }, - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { assert.equal(id, "10", "The first group is passed to find"); return Ember.RSVP.resolve({ id: id }); }, - findMany: function(store, type, ids, snapshots) { + findMany(store, type, ids, snapshots) { var records = ids.map(function(id) { return { id: id }; }); @@ -742,14 +742,14 @@ test("the promise returned by `scheduleFetch`, when it resolves, does not depend var davidResolved = false; var adapter = TestAdapter.extend({ - groupRecordsForFindMany: function (store, snapshots) { + groupRecordsForFindMany(store, snapshots) { return [ [snapshots[0]], [snapshots[1]] ]; }, - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { var record = { id: id }; return new Ember.RSVP.Promise(function(resolve, reject) { @@ -791,14 +791,14 @@ test("the promise returned by `scheduleFetch`, when it rejects, does not depend var davidResolved = false; var adapter = TestAdapter.extend({ - groupRecordsForFindMany: function(store, snapshots) { + groupRecordsForFindMany(store, snapshots) { return [ [snapshots[0]], [snapshots[1]] ]; }, - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { var record = { id: id }; return new Ember.RSVP.Promise(function(resolve, reject) { @@ -839,7 +839,7 @@ test("store.fetchRecord reject records that were not found, even when those requ var Person = DS.Model.extend(); var adapter = TestAdapter.extend({ - findMany: function(store, type, ids, snapshots) { + findMany(store, type, ids, snapshots) { var records = ids.map(function(id) { return { id: id }; }); @@ -883,11 +883,11 @@ test("store should not call shouldReloadRecord when the record is not in the sto }); var TestAdapter = DS.Adapter.extend({ - shouldReloadRecord: function(store, type, id, snapshot) { + shouldReloadRecord(store, type, id, snapshot) { assert.ok(false, 'shouldReloadRecord should not be called when the record is not loaded'); return false; }, - findRecord: function() { + findRecord() { assert.ok(true, 'find is always called when the record is not in the store'); return { id: 1 }; } @@ -911,12 +911,12 @@ test("store should not reload record when shouldReloadRecord returns false", fun }); var TestAdapter = DS.Adapter.extend({ - shouldReloadRecord: function(store, type, id, snapshot) { + shouldReloadRecord(store, type, id, snapshot) { assert.ok(true, 'shouldReloadRecord should be called when the record is in the store'); return false; }, shouldBackgroundReloadRecord: () => false, - findRecord: function() { + findRecord() { assert.ok(false, 'find should not be called when shouldReloadRecord returns false'); } }); @@ -945,11 +945,11 @@ test("store should reload record when shouldReloadRecord returns true", function }); var TestAdapter = DS.Adapter.extend({ - shouldReloadRecord: function(store, type, id, snapshot) { + shouldReloadRecord(store, type, id, snapshot) { assert.ok(true, 'shouldReloadRecord should be called when the record is in the store'); return true; }, - findRecord: function() { + findRecord() { assert.ok(true, 'find should not be called when shouldReloadRecord returns false'); return { id: 1, name: 'Tom' }; } @@ -981,13 +981,13 @@ test("store should not call shouldBackgroundReloadRecord when the store is alrea }); var TestAdapter = DS.Adapter.extend({ - shouldReloadRecord: function(store, type, id, snapshot) { + shouldReloadRecord(store, type, id, snapshot) { return true; }, - shouldBackgroundReloadRecord: function(store, type, id, snapshot) { + shouldBackgroundReloadRecord(store, type, id, snapshot) { assert.ok(false, 'shouldBackgroundReloadRecord is not called when shouldReloadRecord returns true'); }, - findRecord: function() { + findRecord() { assert.ok(true, 'find should be called'); return { id: 1, name: 'Tom' }; } @@ -1019,11 +1019,11 @@ test("store should not reload a record when `shouldBackgroundReloadRecord` is fa }); var TestAdapter = DS.Adapter.extend({ - shouldBackgroundReloadRecord: function(store, type, id, snapshot) { + shouldBackgroundReloadRecord(store, type, id, snapshot) { assert.ok(true, 'shouldBackgroundReloadRecord is called when record is loaded form the cache'); return false; }, - findRecord: function() { + findRecord() { assert.ok(false, 'find should not be called'); return { id: 1, name: 'Tom' }; } @@ -1056,11 +1056,11 @@ test("store should reload the record in the background when `shouldBackgroundRel }); var TestAdapter = DS.Adapter.extend({ - shouldBackgroundReloadRecord: function(store, type, id, snapshot) { + shouldBackgroundReloadRecord(store, type, id, snapshot) { assert.ok(true, 'shouldBackgroundReloadRecord is called when record is loaded form the cache'); return true; }, - findRecord: function() { + findRecord() { assert.ok(true, 'find should not be called'); return { id: 1, name: 'Tom' }; } @@ -1094,14 +1094,14 @@ test("store should not reload record array when shouldReloadAll returns false", }); var TestAdapter = DS.Adapter.extend({ - shouldReloadAll: function(store, snapshot) { + shouldReloadAll(store, snapshot) { assert.ok(true, 'shouldReloadAll should be called when the record is in the store'); return false; }, - shouldBackgroundReloadAll: function(store, snapshot) { + shouldBackgroundReloadAll(store, snapshot) { return false; }, - findAll: function() { + findAll() { assert.ok(false, 'findAll should not be called when shouldReloadAll returns false'); } }); @@ -1124,11 +1124,11 @@ test("store should reload all records when shouldReloadAll returns true", functi }); var TestAdapter = DS.Adapter.extend({ - shouldReloadAll: function(store, type, id, snapshot) { + shouldReloadAll(store, type, id, snapshot) { assert.ok(true, 'shouldReloadAll should be called when the record is in the store'); return true; }, - findAll: function() { + findAll() { assert.ok(true, 'findAll should be called when shouldReloadAll returns true'); return [{ id: 1, name: 'Tom' }]; } @@ -1154,13 +1154,13 @@ test("store should not call shouldBackgroundReloadAll when the store is already }); var TestAdapter = DS.Adapter.extend({ - shouldReloadAll: function(store, type, id, snapshot) { + shouldReloadAll(store, type, id, snapshot) { return true; }, - shouldBackgroundReloadAll: function(store, type, id, snapshot) { + shouldBackgroundReloadAll(store, type, id, snapshot) { assert.ok(false, 'shouldBackgroundReloadRecord is not called when shouldReloadRecord returns true'); }, - findAll: function() { + findAll() { assert.ok(true, 'find should be called'); return [{ id: 1, name: 'Tom' }]; } @@ -1186,15 +1186,15 @@ test("store should not reload all records when `shouldBackgroundReloadAll` is fa }); var TestAdapter = DS.Adapter.extend({ - shouldReloadAll: function(store, type, id, snapshot) { + shouldReloadAll(store, type, id, snapshot) { assert.ok(true, 'shouldReloadAll is called when record is loaded form the cache'); return false; }, - shouldBackgroundReloadAll: function(store, type, id, snapshot) { + shouldBackgroundReloadAll(store, type, id, snapshot) { assert.ok(true, 'shouldBackgroundReloadAll is called when record is loaded form the cache'); return false; }, - findAll: function() { + findAll() { assert.ok(false, 'findAll should not be called'); return [{ id: 1, name: 'Tom' }]; } @@ -1221,15 +1221,15 @@ test("store should reload all records in the background when `shouldBackgroundRe }); var TestAdapter = DS.Adapter.extend({ - shouldReloadAll: function() { + shouldReloadAll() { assert.ok(true, 'shouldReloadAll is called'); return false; }, - shouldBackgroundReloadAll: function(store, snapshot) { + shouldBackgroundReloadAll(store, snapshot) { assert.ok(true, 'shouldBackgroundReloadAll is called when record is loaded form the cache'); return true; }, - findAll: function() { + findAll() { assert.ok(true, 'find should not be called'); return [{ id: 1, name: 'Tom' }]; } diff --git a/tests/unit/store/create-record-test.js b/tests/unit/store/create-record-test.js index c276ca82789..dea148fd8af 100644 --- a/tests/unit/store/create-record-test.js +++ b/tests/unit/store/create-record-test.js @@ -8,7 +8,7 @@ var store, container, Record, Storage; var run = Ember.run; module("unit/store/createRecord - Store creating records", { - beforeEach: function() { + beforeEach() { Record = DS.Model.extend({ title: DS.attr('string') }); @@ -64,7 +64,7 @@ test("allow passing relationships as well as attributes", function(assert) { }); module("unit/store/createRecord - Store with models by dash", { - beforeEach: function() { + beforeEach() { var env = setupStore({ someThing: DS.Model.extend({ foo: DS.attr('string') }) }); diff --git a/tests/unit/store/has-record-for-id-test.js b/tests/unit/store/has-record-for-id-test.js index 027f453a844..0db692b79a5 100644 --- a/tests/unit/store/has-record-for-id-test.js +++ b/tests/unit/store/has-record-for-id-test.js @@ -12,7 +12,7 @@ var belongsTo = DS.belongsTo; var run = Ember.run; module("unit/store/hasRecordForId - Store hasRecordForId", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({ firstName: attr('string'), @@ -40,7 +40,7 @@ module("unit/store/hasRecordForId - Store hasRecordForId", { }, - afterEach: function() { + afterEach() { Ember.run(store, 'destroy'); } }); diff --git a/tests/unit/store/model-for-test.js b/tests/unit/store/model-for-test.js index ffe86b7e6c9..d6d7130f7ee 100644 --- a/tests/unit/store/model-for-test.js +++ b/tests/unit/store/model-for-test.js @@ -14,7 +14,7 @@ var run = Ember.run; var env; module("unit/store/model_for - DS.Store#modelFor", { - beforeEach: function() { + beforeEach() { env = setupStore({ blogPost: DS.Model.extend(), "blog.post": DS.Model.extend() @@ -24,7 +24,7 @@ module("unit/store/model_for - DS.Store#modelFor", { registry = env.registry; }, - afterEach: function() { + afterEach() { run(function() { container.destroy(); store.destroy(); diff --git a/tests/unit/store/peek-record-test.js b/tests/unit/store/peek-record-test.js index 6586755b20a..27bd0570b01 100644 --- a/tests/unit/store/peek-record-test.js +++ b/tests/unit/store/peek-record-test.js @@ -9,7 +9,7 @@ var env, store, Person; var run = Ember.run; module("unit/store/peekRecord - Store peekRecord", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend(); Person.toString = function() { @@ -22,7 +22,7 @@ module("unit/store/peekRecord - Store peekRecord", { store = env.store; }, - afterEach: function() { + afterEach() { Ember.run(store, 'destroy'); } }); diff --git a/tests/unit/store/push-test.js b/tests/unit/store/push-test.js index c694f1e0a19..fa9ae404338 100644 --- a/tests/unit/store/push-test.js +++ b/tests/unit/store/push-test.js @@ -12,7 +12,7 @@ var belongsTo = DS.belongsTo; var run = Ember.run; module("unit/store/push - DS.Store#push", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({ firstName: attr('string'), lastName: attr('string'), @@ -48,7 +48,7 @@ module("unit/store/push - DS.Store#push", { env.registry.register('serializer:post', DS.RESTSerializer); }, - afterEach: function() { + afterEach() { run(function() { store.destroy(); }); @@ -345,13 +345,13 @@ test("Calling pushPayload allows pushing singular payload properties", function( test("Calling pushPayload should use the type's serializer for normalizing", function(assert) { assert.expect(4); env.registry.register('serializer:post', DS.RESTSerializer.extend({ - normalize: function(store, payload) { + normalize(store, payload) { assert.ok(true, "normalized is called on Post serializer"); return this._super(store, payload); } })); env.registry.register('serializer:person', DS.RESTSerializer.extend({ - normalize: function(store, payload) { + normalize(store, payload) { assert.ok(true, "normalized is called on Person serializer"); return this._super(store, payload); } @@ -383,7 +383,7 @@ test("Calling pushPayload without a type uses application serializer's pushPaylo assert.expect(1); env.registry.register('serializer:application', DS.RESTSerializer.extend({ - pushPayload: function(store, payload) { + pushPayload(store, payload) { assert.ok(true, "pushPayload is called on Application serializer"); return this._super(store, payload); } @@ -400,14 +400,14 @@ test("Calling pushPayload without a type should use a model's serializer when no assert.expect(4); env.registry.register('serializer:post', DS.RESTSerializer.extend({ - normalize: function(store, payload) { + normalize(store, payload) { assert.ok(true, "normalized is called on Post serializer"); return this._super(store, payload); } })); env.registry.register('serializer:application', DS.RESTSerializer.extend({ - normalize: function(store, payload) { + normalize(store, payload) { assert.ok(true, "normalized is called on Application serializer"); return this._super(store, payload); } @@ -669,7 +669,7 @@ test("Calling push with unknown keys should not warn by default", function(asser }); module("unit/store/push - DS.Store#push with JSON-API", { - beforeEach: function() { + beforeEach() { var Person = DS.Model.extend({ name: DS.attr('string'), cars: DS.hasMany('car', { async: false }) @@ -694,7 +694,7 @@ module("unit/store/push - DS.Store#push with JSON-API", { }, - afterEach: function() { + afterEach() { run(function() { store.destroy(); }); diff --git a/tests/unit/store/serializer-for-test.js b/tests/unit/store/serializer-for-test.js index 5b719e42858..81a3cea97d2 100644 --- a/tests/unit/store/serializer-for-test.js +++ b/tests/unit/store/serializer-for-test.js @@ -9,7 +9,7 @@ var container, store, registry, Person; var run = Ember.run; module("unit/store/serializer_for - DS.Store#serializerFor", { - beforeEach: function() { + beforeEach() { Person = DS.Model.extend({}); var env = setupStore({ person: Person }); store = env.store; @@ -17,7 +17,7 @@ module("unit/store/serializer_for - DS.Store#serializerFor", { registry = env.registry; }, - afterEach: function() { + afterEach() { run(function() { container.destroy(); store.destroy(); diff --git a/tests/unit/store/unload-test.js b/tests/unit/store/unload-test.js index 5a4cd1796cd..1375e0312e7 100644 --- a/tests/unit/store/unload-test.js +++ b/tests/unit/store/unload-test.js @@ -10,7 +10,7 @@ var run = Ember.run; var store, tryToFind, Record; module("unit/store/unload - Store unloading records", { - beforeEach: function() { + beforeEach() { Record = DS.Model.extend({ title: DS.attr('string'), @@ -18,7 +18,7 @@ module("unit/store/unload - Store unloading records", { }); store = createStore({ adapter: DS.Adapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { tryToFind = true; return Ember.RSVP.resolve({ id: id, wasFetched: true }); } @@ -27,7 +27,7 @@ module("unit/store/unload - Store unloading records", { }); }, - afterEach: function() { + afterEach() { Ember.run(store, 'destroy'); } }); @@ -119,10 +119,10 @@ test("can commit store after unload record with relationships", function(assert) var store = createStore({ adapter: DS.Adapter.extend({ - findRecord: function(store, type, id, snapshot) { + findRecord(store, type, id, snapshot) { return Ember.RSVP.resolve({ id: 1, description: 'cuisinart', brand: 1 }); }, - createRecord: function(store, type, snapshot) { + createRecord(store, type, snapshot) { return Ember.RSVP.resolve(); } }), From 828f8eaef753320bf39793b6b3f54a64c970f5a1 Mon Sep 17 00:00:00 2001 From: Trent Willis Date: Tue, 13 Oct 2015 20:59:24 -0700 Subject: [PATCH 24/24] Merge normalizeRelationships and setupRelationships methods in store --- addon/system/store.js | 59 ++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/addon/system/store.js b/addon/system/store.js index 036139155d5..84aac5db067 100644 --- a/addon/system/store.js +++ b/addon/system/store.js @@ -1351,7 +1351,7 @@ Store = Service.extend({ } if (data) { // normalize relationship IDs into records - this._backburner.schedule('normalizeRelationships', this, '_setupRelationships', internalModel, internalModel.type, data); + this._backburner.schedule('normalizeRelationships', this, '_setupRelationships', internalModel, data); this.updateId(internalModel, data); } @@ -1738,23 +1738,15 @@ Store = Service.extend({ var internalModel = this._load(data); this._backburner.join(() => { - this._backburner.schedule('normalizeRelationships', this, '_setupRelationships', internalModel, type, data); + this._backburner.schedule('normalizeRelationships', this, '_setupRelationships', internalModel, data); }); return internalModel; }, - _setupRelationships(record, type, data) { - // If the payload contains relationships that are specified as - // IDs, normalizeRelationships will convert them into DS.Model instances - // (possibly unloaded) before we push the payload into the - // store. - - data = normalizeRelationships(this, type, data); - - - // Now that the pushed record as well as any related records - // are in the store, create the data structures used to track + _setupRelationships(record, data) { + // This will convert relationships specified as IDs into DS.Model instances + // (possibly unloaded) and also create the data structures used to track // relationships. setupRelationships(this, record, data); }, @@ -2043,25 +2035,6 @@ Store = Service.extend({ }); - -function normalizeRelationships(store, type, data, record) { - data.relationships = data.relationships || {}; - type.eachRelationship(function(key, relationship) { - var kind = relationship.kind; - var value; - if (data.relationships[key] && data.relationships[key].data) { - value = data.relationships[key].data; - if (kind === 'belongsTo') { - data.relationships[key].data = deserializeRecordId(store, key, relationship, value); - } else if (kind === 'hasMany') { - data.relationships[key].data = deserializeRecordIds(store, key, relationship, value); - } - } - }); - - return data; -} - function deserializeRecordId(store, key, relationship, id) { if (isNone(id)) { return; @@ -2131,13 +2104,13 @@ function _commit(adapter, store, operation, snapshot) { } function setupRelationships(store, record, data) { - var typeClass = record.type; if (!data.relationships) { return; } - typeClass.eachRelationship((key, descriptor) => { + record.type.eachRelationship((key, descriptor) => { var kind = descriptor.kind; + if (!data.relationships[key]) { return; } @@ -2156,6 +2129,12 @@ function setupRelationships(store, record, data) { relationship = record._relationships.get(key); relationship.updateMeta(data.relationships[key].meta); } + + // If the data contains a relationship that is specified as an ID (or IDs), + // normalizeRelationship will convert them into DS.Model instances + // (possibly unloaded) before we push the payload into the store. + normalizeRelationship(store, key, descriptor, data.relationships[key]); + var value = data.relationships[key].data; if (value !== undefined) { @@ -2170,5 +2149,17 @@ function setupRelationships(store, record, data) { }); } +function normalizeRelationship(store, key, relationship, jsonPayload) { + var data = jsonPayload.data; + if (data) { + var kind = relationship.kind; + if (kind === 'belongsTo') { + jsonPayload.data = deserializeRecordId(store, key, relationship, data); + } else if (kind === 'hasMany') { + jsonPayload.data = deserializeRecordIds(store, key, relationship, data); + } + } +} + export { Store }; export default Store;