diff --git a/packages/ember-data/lib/system/many-array.js b/packages/ember-data/lib/system/many-array.js index 1ef9915c8ad..140a0a46ded 100644 --- a/packages/ember-data/lib/system/many-array.js +++ b/packages/ember-data/lib/system/many-array.js @@ -2,7 +2,6 @@ @module ember-data */ import { PromiseArray } from "ember-data/system/promise-proxies"; -import FilteredSubset from "ember-data/system/record-arrays/filtered-subset"; var get = Ember.get; var set = Ember.set; @@ -278,37 +277,5 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, { this.pushObject(record); return record; - }, - - /** - Get a filtered subset of the underlying `ManyArray`. - The subset updates when a record would match or mismatch the - specified filter parameters. - - Example - - ```javascript - var post = store.peekRecord('post', 1) - // All the comments that are deleted locally but not yet saved to the server. - var deletedComments = post.get('comments').filterBy('isDeleted'); - ``` - - @method filterBy - @param {String} key property path - @param {*} value optional - - */ - filterBy: function(key, value) { - // only pass value to the arguments if it is present; this mimics the same - // behavior for `filterBy`: http://git.io/vIurH - var filterByArgs = [key]; - if (arguments.length === 2) { - filterByArgs.push(value); - } - - return FilteredSubset.create({ - filterByArgs, - recordArray: this - }); } }); diff --git a/packages/ember-data/lib/system/record-arrays/filtered-subset.js b/packages/ember-data/lib/system/record-arrays/filtered-subset.js deleted file mode 100644 index 4a11c95e1ca..00000000000 --- a/packages/ember-data/lib/system/record-arrays/filtered-subset.js +++ /dev/null @@ -1,15 +0,0 @@ -var FilteredSubset = Ember.ArrayProxy.extend({ - init: function() { - this._super(...arguments); - - var { filterByArgs, recordArray } = this.getProperties('filterByArgs', 'recordArray'); - var [key] = filterByArgs; - - var path = `recordArray.@each.${key}`; - Ember.defineProperty(this, 'content', Ember.computed(path, function() { - return this.filterBy.apply(recordArray, filterByArgs); - })); - } -}); - -export default FilteredSubset; diff --git a/packages/ember-data/lib/system/record-arrays/record-array.js b/packages/ember-data/lib/system/record-arrays/record-array.js index 5c5c0bb614d..0577f2ef3f4 100644 --- a/packages/ember-data/lib/system/record-arrays/record-array.js +++ b/packages/ember-data/lib/system/record-arrays/record-array.js @@ -4,7 +4,6 @@ import { PromiseArray } from "ember-data/system/promise-proxies"; import SnapshotRecordArray from "ember-data/system/snapshot-record-array"; -import FilteredSubset from "ember-data/system/record-arrays/filtered-subset"; var get = Ember.get; var set = Ember.set; @@ -97,44 +96,6 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { return internalModel && internalModel.getRecord(); }, - /** - Get a filtered subset of the underlying `RecordArray`. - The subset updates when a record would match or mismatch the - specified filter parameters. - - Example - - ```javascript - var allToms = store.all('person').filterBy('name', 'Tom'); - - allToms.get('length'); // 0, since no toms yet in store - - var tom = store.push('person', { id: 1, name: 'Tom' }); - allToms.get('length'); // Tom is added - - tom.set('name', 'Thomas'); - allToms.get('length'); // 0, since no more records with name === 'Tom' - ``` - - @method filterBy - @param {String} key property path - @param {*} value optional - - */ - filterBy: function(key, value) { - // only pass value to the arguments if it is present; this mimics the same - // behavior for `filterBy`: http://git.io/vIurH - var filterByArgs = [key]; - if (arguments.length === 2) { - filterByArgs.push(value); - } - - return FilteredSubset.create({ - filterByArgs, - recordArray: this - }); - }, - /** Used to get the latest version of all of the records in this array from the adapter. diff --git a/packages/ember-data/tests/integration/relationships/has-many-test.js b/packages/ember-data/tests/integration/relationships/has-many-test.js index 9a1cb3dca67..7e02af05c75 100644 --- a/packages/ember-data/tests/integration/relationships/has-many-test.js +++ b/packages/ember-data/tests/integration/relationships/has-many-test.js @@ -2340,75 +2340,3 @@ test("metadata should be reset between requests", function() { }); }); }); - - -test("filterBy - returns a filtered subset", function () { - var chapter, page; - run(function() { - env.store.push({ - data: { - type: 'chapter', - id: '1', - relationships: { - pages: { - data: [ - { type: 'page', id: '2' }, - { type: 'page', id: '3' } - ] - } - } - }, - included: [{ - type: 'page', - id: '2' - }, { - type: 'page', - id: '3' - }] - }); - chapter = env.store.peekRecord('chapter', 1); - page = env.store.peekRecord('page', 2); - }); - run(function() { - page.deleteRecord(); - }); - run(function() { - equal(chapter.get('pages').filterBy('isDeleted').get('length'), 1, "Can filter by deleted records"); - }); -}); - - -test("filterBy - returns a filtered subset", function () { - var chapter; - run(function() { - env.store.push({ - data: { - type: 'chapter', - id: '1', - relationships: { - pages: { - data: [ - { type: 'page', id: '2' }, - { type: 'page', id: '3' } - ] - } - } - }, - included: [{ - type: 'page', - id: '2' - }, { - type: 'page', - id: '3' - }] - }); - chapter = env.store.peekRecord('chapter', 1); - }); - run(function() { - env.store.peekRecord('page', 2).deleteRecord(); - var deletedChapters = chapter.get('pages').filterBy('isDeleted'); - equal(deletedChapters.get('length'), 1); - env.store.peekRecord('page', 3).deleteRecord(); - equal(deletedChapters.get('length'), 2); - }); -}); diff --git a/packages/ember-data/tests/unit/record-array-test.js b/packages/ember-data/tests/unit/record-array-test.js index 4642d1fe128..45069ff45c2 100644 --- a/packages/ember-data/tests/unit/record-array-test.js +++ b/packages/ember-data/tests/unit/record-array-test.js @@ -456,118 +456,3 @@ test("a record array should return a promise when updating", function() { }); ok(promise.then && typeof promise.then === "function", "#update returns a promise"); }); - -test('filterBy - returns a filtered subset', function() { - var store = createStore({ - person: Person - }); - - run(function() { - store.push({ data: [{ - id: '1', - type: 'person', - attributes: { - name: "Tom" - } - }, { - id: '2', - type: 'person', - attributes: { - name: "Yehuda" - } - }, { - id: '2', - type: 'person', - attributes: { - name: "Yehuda" - } - }] }); - }); - - var all = store.peekAll('person'); - var toms = all.filterBy('name', 'Tom'); - equal(toms.get('length'), 1); - deepEqual(toms.getEach('id'), ['1']); - - // a new record is added if filter matches - run(function() { - store.push({ data: { type: 'person', id: '4', attributes: { name: "Tom" } } }); - }); - equal(toms.get('length'), 2); - deepEqual(toms.getEach('id'), ['1', '4']); - - // a new record is not added if filter doesn't match - run(function() { - store.push({ data: { type: 'person', id: '5', attributes: { name: "Igor" } } }); - }); - equal(toms.get('length'), 2); - deepEqual(toms.getEach('id'), ['1', '4']); - - // changing the filtered value remvoves the record from the list - run(function() { - // we are using a private method here to get the record immediatly - store.recordForId('person', '1').set('name', "Thomas"); - }); - equal(toms.get('length'), 1); - deepEqual(toms.getEach('id'), ['4']); - - // change value back to original - run(function() { - store.recordForId('person', '1').set('name', "Tom"); - }); - equal(toms.get('length'), 2); - deepEqual(toms.getEach('id'), ['1', '4']); -}); - -test('filterBy - value is optional', function() { - var store = createStore({ - person: Person - }); - - run(function() { - store.push({ data: [{ - id: '1', - type: 'person', - attributes: { - name: "Tom" - } - }, { - id: '2', - type: 'person' - }] }); - }); - - var all = store.peekAll('person'); - var allWithNames = all.filterBy('name'); - equal(allWithNames.get('length'), 1); - deepEqual(allWithNames.getEach('id'), ['1']); - - // a new record is added if filter matches - run(function() { - store.push({ data: { type: 'person', id: '3', attributes: { name: "Igor" } } }); - }); - equal(allWithNames.get('length'), 2); - deepEqual(allWithNames.getEach('id'), ['1', '3']); - - // a new record is not added if filter doesn't match - run(function() { - store.push({ data: { type: 'person', id: '4' } }); - }); - equal(allWithNames.get('length'), 2); - deepEqual(allWithNames.getEach('id'), ['1', '3']); - - // changing the filtered value remvoves the record from the list - run(function() { - // we are using a private method here to get the record immediatly - store.recordForId('person', '1').set('name', null); - }); - equal(allWithNames.get('length'), 1); - deepEqual(allWithNames.getEach('id'), ['3']); - - // change value back to original - run(function() { - store.recordForId('person', '1').set('name', "Tom"); - }); - equal(allWithNames.get('length'), 2); - deepEqual(allWithNames.getEach('id'), ['1', '3']); -});