Skip to content

Commit

Permalink
Merge pull request #5459 from bmac/cherry-pick-5437
Browse files Browse the repository at this point in the history
[CHORE] removes deprecated Store.filter feature
  • Loading branch information
bmac authored Apr 29, 2018
2 parents 660d9bc + fe70799 commit a860a36
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 1,450 deletions.
1 change: 0 additions & 1 deletion addon/-private/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export {

export {
RecordArray,
FilteredRecordArray,
AdapterPopulatedRecordArray
} from './system/record-arrays';

Expand Down
172 changes: 10 additions & 162 deletions addon/-private/system/record-array-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,33 @@
*/

import { A } from '@ember/array';

import { set, get } from '@ember/object';
import { run as emberRun } from '@ember/runloop';
import { assert } from '@ember/debug';
import cloneNull from './clone-null';
import {
RecordArray,
FilteredRecordArray,
AdapterPopulatedRecordArray
} from "./record-arrays";

import cloneNull from "./clone-null";
import { assert } from '@ember/debug';
} from './record-arrays';

const {
_flush,
array_flatten,
array_remove,
create,
createAdapterPopulatedRecordArray,
createFilteredRecordArray,
createRecordArray,
liveRecordArrayFor,
filteredRecordArraysFor,
recordDidChange,
registerFilteredRecordArray,
unregisterRecordArray,
updateFilter,
updateFilterRecordArray
unregisterRecordArray
} = heimdall.registerMonitor('recordArrayManager',
'_flush',
'array_fatten',
'array_remove',
'create',
'createAdapterPopulatedRecordArray',
'createFilteredRecordArray',
'createRecordArray',
'liveRecordArrayFor',
'filteredRecordArraysFor',
'recordDidChange',
'registerFilteredRecordArray',
'unregisterRecordArray',
'updateFilter',
'updateFilterRecordArray'
'unregisterRecordArray'
);

/**
Expand All @@ -58,7 +43,6 @@ export default class RecordArrayManager {
this.store = options.store;
this.isDestroying = false;
this.isDestroyed = false;
this._filteredRecordArrays = Object.create(null);
this._liveRecordArrays = Object.create(null);
this._pending = Object.create(null);
this._adapterPopulatedRecordArrays = [];
Expand Down Expand Up @@ -110,14 +94,6 @@ export default class RecordArrayManager {
}
}

// process filteredRecordArrays
if (this._filteredRecordArrays[modelName]) {
let recordArrays = this.filteredRecordArraysFor(modelName);
for (let i = 0; i < recordArrays.length; i++) {
this.updateFilterRecordArray(recordArrays[i], modelName, internalModels);
}
}

let array = this._liveRecordArrays[modelName];
if (array) {
// TODO: skip if it only changed
Expand Down Expand Up @@ -146,41 +122,6 @@ export default class RecordArrayManager {
return updateLiveRecordArray(array, internalModels);
}

/**
Update an individual filter.
@private
@method updateFilterRecordArray
@param {DS.FilteredRecordArray} array
@param {String} modelName
@param {Array} internalModels
*/
updateFilterRecordArray(array, modelName, internalModels) {
heimdall.increment(updateFilterRecordArray);

let filter = get(array, 'filterFunction');

let shouldBeInAdded = [];
let shouldBeRemoved = [];

for (let i = 0; i < internalModels.length; i++) {
let internalModel = internalModels[i];
if (internalModel.isHiddenFromRecordArrays() === false &&
filter(internalModel.getRecord())) {
if (internalModel._recordArrays.has(array)) { continue; }
shouldBeInAdded.push(internalModel);
internalModel._recordArrays.add(array);
} else {
if (internalModel._recordArrays.delete(array)) {
shouldBeRemoved.push(internalModel);
}
}
}

if (shouldBeInAdded.length > 0) { array._pushInternalModels(shouldBeInAdded); }
if (shouldBeRemoved.length > 0) { array._removeInternalModels(shouldBeRemoved); }
}

_syncLiveRecordArray(array, modelName) {
assert(`recordArrayManger.syncLiveRecordArray expects modelName not modelClass as the second param`, typeof modelName === 'string');
let pending = this._pending[modelName];
Expand Down Expand Up @@ -220,27 +161,6 @@ export default class RecordArrayManager {
}
}

/**
This method is invoked if the `filterFunction` property is
changed on a `DS.FilteredRecordArray`.
It essentially re-runs the filter from scratch. This same
method is invoked when the filter is created in th first place.
@method updateFilter
@param {Array} array
@param {String} modelName
@param {Function} filter
*/
updateFilter(array, modelName, filter) {
assert(`recordArrayManger.updateFilter expects modelName not modelClass as the second param, received ${modelName}`, typeof modelName === 'string');
heimdall.increment(updateFilter);
let modelMap = this.store._internalModelsFor(modelName);
let internalModels = modelMap.models;

this.updateFilterRecordArray(array, filter, internalModels);
}

_didUpdateAll(modelName) {
let recordArray = this._liveRecordArrays[modelName];
if (recordArray) {
Expand Down Expand Up @@ -288,21 +208,7 @@ export default class RecordArrayManager {
}
return visible;
}
/**
Get the `DS.RecordArray` for a modelName, which contains all loaded records of
given modelName.

@method filteredRecordArraysFor
@param {String} modelName
@return {DS.RecordArray}
*/
filteredRecordArraysFor(modelName) {
assert(`recordArrayManger.filteredRecordArraysFor expects modelName not modelClass as the param`, typeof modelName === 'string');

heimdall.increment(filteredRecordArraysFor);

return this._filteredRecordArrays[modelName] || (this._filteredRecordArrays[modelName] = []);
}
/**
Create a `DS.RecordArray` for a modelName.
Expand Down Expand Up @@ -330,32 +236,6 @@ export default class RecordArrayManager {
return array;
}

/**
Create a `DS.FilteredRecordArray` for a modelName and register it for updates.
@method createFilteredRecordArray
@param {String} modelName
@param {Function} filter
@param {Object} query (optional
@return {DS.FilteredRecordArray}
*/
createFilteredRecordArray(modelName, filter, query) {
assert(`recordArrayManger.createFilteredRecordArray expects modelName not modelClass as the first param, received ${modelName}`, typeof modelName === 'string');

heimdall.increment(createFilteredRecordArray);
let array = FilteredRecordArray.create({
query,
modelName,
content: A(),
store: this.store,
manager: this,
filterFunction: filter
});

this.registerFilteredRecordArray(array, modelName, filter);

return array;
}

/**
Create a `DS.AdapterPopulatedRecordArray` for a modelName with given query.
Expand Down Expand Up @@ -399,25 +279,6 @@ export default class RecordArrayManager {
return array;
}

/**
Register a RecordArray for a given modelName to be backed by
a filter function. This will cause the array to update
automatically when records of that modelName change attribute
values or states.
@method registerFilteredRecordArray
@param {DS.RecordArray} array
@param {String} modelName
@param {Function} filter
*/
registerFilteredRecordArray(array, modelName, filter) {
heimdall.increment(registerFilteredRecordArray);
assert(`recordArrayManger.registerFilteredRecordArray expects modelName not modelClass as the second param, received ${modelName}`, typeof modelName === 'string');

this.filteredRecordArraysFor(modelName).push(array);
this.updateFilter(array, modelName, filter);
}

/**
Unregister a RecordArray.
So manager will not update this array.
Expand All @@ -430,14 +291,10 @@ export default class RecordArrayManager {

let modelName = array.modelName;

// unregister filtered record array
let recordArrays = this.filteredRecordArraysFor(modelName);
let removedFromFiltered = remove(recordArrays, array);

// remove from adapter populated record array
let removedFromAdapterPopulated = remove(this._adapterPopulatedRecordArrays, array);

if (!removedFromFiltered && !removedFromAdapterPopulated) {
if (!removedFromAdapterPopulated) {

let liveRecordArrayForType = this._liveRecordArrays[modelName];
// unregister live record array
Expand All @@ -450,7 +307,6 @@ export default class RecordArrayManager {
}

willDestroy() {
Object.keys(this._filteredRecordArrays).forEach(modelName => flatten(this._filteredRecordArrays[modelName]).forEach(destroy));
Object.keys(this._liveRecordArrays).forEach(modelName => this._liveRecordArrays[modelName].destroy());
this._adapterPopulatedRecordArrays.forEach(destroy);
this.isDestroyed = true;
Expand All @@ -466,18 +322,6 @@ function destroy(entry) {
entry.destroy();
}

function flatten(list) {
heimdall.increment(array_flatten);
let length = list.length;
let result = [];

for (let i = 0; i < length; i++) {
result = result.concat(list[i]);
}

return result;
}

function remove(array, item) {
heimdall.increment(array_remove);
let index = array.indexOf(item);
Expand Down Expand Up @@ -514,6 +358,10 @@ function updateLiveRecordArray(array, internalModels) {

if (modelsToAdd.length > 0) { array._pushInternalModels(modelsToAdd); }
if (modelsToRemove.length > 0) { array._removeInternalModels(modelsToRemove); }

// return whether we performed an update.
// Necessary until 3.5 allows us to finish off ember-data-filter support.
return (modelsToAdd.length || modelsToRemove.length) > 0;
}

function removeFromAdapterPopulatedRecordArrays(internalModels) {
Expand Down
2 changes: 0 additions & 2 deletions addon/-private/system/record-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
*/

import RecordArray from "./record-arrays/record-array";
import FilteredRecordArray from "./record-arrays/filtered-record-array";
import AdapterPopulatedRecordArray from "./record-arrays/adapter-populated-record-array";

export {
RecordArray,
FilteredRecordArray,
AdapterPopulatedRecordArray
};
67 changes: 0 additions & 67 deletions addon/-private/system/record-arrays/filtered-record-array.js

This file was deleted.

Loading

0 comments on commit a860a36

Please sign in to comment.