Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Ember.EnumerableUtils with Ember.ArrayPollyfills. #3354

Merged
merged 1 commit into from
Jun 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/ember-data/lib/adapters/fixture-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
var get = Ember.get;
var fmt = Ember.String.fmt;
var indexOf = Ember.EnumerableUtils.indexOf;
var indexOf = Ember.ArrayPolyfills.indexOf;

var counter = 0;

Expand Down Expand Up @@ -169,7 +169,7 @@ export default Adapter.extend({

if (fixtures) {
fixtures = fixtures.filter(function(item) {
return indexOf(ids, item.id) !== -1;
return indexOf.call(ids, item.id) !== -1;
});
}

Expand Down Expand Up @@ -280,7 +280,7 @@ export default Adapter.extend({
var existingFixture = this.findExistingFixture(typeClass, snapshot);

if (existingFixture) {
var index = indexOf(typeClass.FIXTURES, existingFixture);
var index = indexOf.call(typeClass.FIXTURES, existingFixture);
typeClass.FIXTURES.splice(index, 1);
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/ember-data/lib/serializers/embedded-records-mixin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var get = Ember.get;
var set = Ember.set;
var forEach = Ember.EnumerableUtils.forEach;
var forEach = Ember.ArrayPolyfills.forEach;
var camelize = Ember.String.camelize;

/**
Expand Down Expand Up @@ -445,7 +445,7 @@ var EmbeddedRecordsMixin = Ember.Mixin.create({
var ids = [];

var embeddedSerializer = store.serializerFor(embeddedTypeClass.modelName);
forEach(hash[key], function(data) {
forEach.call(hash[key], function(data) {
var embeddedRecord = embeddedSerializer.normalize(embeddedTypeClass, data, null);
store.push(embeddedTypeClass.modelName, embeddedRecord);
ids.push(embeddedRecord.id);
Expand All @@ -466,7 +466,7 @@ var EmbeddedRecordsMixin = Ember.Mixin.create({

var ids = [];

forEach(hash[key], function(data) {
forEach.call(hash[key], function(data) {
var modelName = data.type;
var embeddedSerializer = store.serializerFor(modelName);
var embeddedTypeClass = store.modelFor(modelName);
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-data/lib/system/many-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { PromiseArray } from "ember-data/system/promise-proxies";
var get = Ember.get;
var set = Ember.set;
var filter = Ember.ArrayPolyfills.filter;
var map = Ember.EnumerableUtils.map;

/**
A `ManyArray` is a `MutableArray` that represents the contents of a has-many
Expand Down Expand Up @@ -193,8 +192,9 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, {
records = this.currentState.slice(idx, idx+amt);
this.get('relationship').removeRecords(records);
}
var map = objects.map || Ember.ArrayPolyfills.map;
if (objects) {
this.get('relationship').addRecords(map(objects, function(obj) { return obj._internalModel; }), idx);
this.get('relationship').addRecords(map.call(objects, function(obj) { return obj._internalModel; }), idx);
}
},
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-data/lib/system/model/errors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var get = Ember.get;
var isEmpty = Ember.isEmpty;
var map = Ember.EnumerableUtils.map;
var map = Ember.ArrayPolyfills.map;

import {
MapWithDefault
Expand Down Expand Up @@ -237,7 +237,7 @@ export default Ember.Object.extend(Ember.Enumerable, Ember.Evented, {
_findOrCreateMessages: function(attribute, messages) {
var errors = this.errorsFor(attribute);

return map(Ember.makeArray(messages), function(message) {
return map.call(Ember.makeArray(messages), function(message) {
return errors.findBy('message', message) || {
attribute: attribute,
message: message
Expand Down
15 changes: 14 additions & 1 deletion packages/ember-data/lib/system/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@ import { PromiseObject } from "ember-data/system/promise-proxies";
*/

var get = Ember.get;
var intersection = Ember.EnumerableUtils.intersection;
var forEach = Ember.ArrayPolyfills.forEach;
var indexOf = Ember.ArrayPolyfills.indexOf;

function intersection (array1, array2) {
var result = [];
forEach.call(array1, (element) => {
if (indexOf.call(array2, element) >= 0) {
result.push(element);
}
});

return result;
}

var RESERVED_MODEL_PROPS = [
'currentState', 'data', 'store'
];
Expand Down
20 changes: 9 additions & 11 deletions packages/ember-data/lib/system/record-array-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
} from "ember-data/system/map";
import OrderedSet from "ember-data/system/ordered-set";
var get = Ember.get;
var forEach = Ember.EnumerableUtils.forEach;
var indexOf = Ember.EnumerableUtils.indexOf;
var forEach = Ember.ArrayPolyfills.forEach;
var indexOf = Ember.ArrayPolyfills.indexOf;

/**
@class RecordArrayManager
Expand Down Expand Up @@ -59,7 +59,7 @@ export default Ember.Object.extend({
@method updateRecordArrays
*/
updateRecordArrays: function() {
forEach(this.changedRecords, function(record) {
forEach.call(this.changedRecords, function(record) {
if (record.isDeleted()) {
this._recordWasDeleted(record);
} else {
Expand Down Expand Up @@ -87,8 +87,7 @@ export default Ember.Object.extend({
var typeClass = record.type;
var recordArrays = this.filteredRecordArrays.get(typeClass);
var filter;

forEach(recordArrays, function(array) {
forEach.call(recordArrays, function(array) {
filter = get(array, 'filterFunction');
this.updateFilterRecordArray(array, filter, typeClass, record);
}, this);
Expand All @@ -100,7 +99,7 @@ export default Ember.Object.extend({
var recordArrays = this.filteredRecordArrays.get(typeClass);
var filter;

forEach(recordArrays, function(array) {
forEach.call(recordArrays, function(array) {
filter = get(array, 'filterFunction');
this.updateFilterRecordArray(array, filter, typeClass, record);
}, this);
Expand All @@ -122,7 +121,6 @@ export default Ember.Object.extend({
updateFilterRecordArray: function(array, filter, typeClass, record) {
var shouldBeInArray = filter(record.getRecord());
var recordArrays = this.recordArraysForRecord(record);

if (shouldBeInArray) {
this._addRecordToRecordArray(array, record);
} else {
Expand Down Expand Up @@ -286,7 +284,7 @@ export default Ember.Object.extend({

// unregister filtered record array
var recordArrays = this.filteredRecordArrays.get(typeClass);
var index = indexOf(recordArrays, array);
var index = indexOf.call(recordArrays, array);
if (index !== -1) {
recordArrays.splice(index, 1);

Expand All @@ -303,10 +301,10 @@ export default Ember.Object.extend({
this._super.apply(this, arguments);

this.filteredRecordArrays.forEach(function(value) {
forEach(flatten(value), destroy);
forEach.call(flatten(value), destroy);
});
forEach(this.liveRecordArrays, destroy);
forEach(this._adapterPopulatedRecordArrays, destroy);
forEach.call(this.liveRecordArrays, destroy);
forEach.call(this._adapterPopulatedRecordArrays, destroy);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import ManyArray from "ember-data/system/many-array";

import { assertPolymorphicType } from "ember-data/utils";

var map = Ember.EnumerableUtils.map;
var map = Ember.ArrayPolyfills.map;


var ManyRelationship = function(store, record, inverseKey, relationshipMeta) {
this._super$constructor(store, record, inverseKey, relationshipMeta);
Expand Down Expand Up @@ -157,7 +158,7 @@ ManyRelationship.prototype.fetchLink = function() {
ManyRelationship.prototype.findRecords = function() {
var manyArray = this.manyArray;
//TODO CLEANUP
return this.store.findMany(map(manyArray.toArray(), function(rec) { return rec._internalModel; })).then(function() {
return this.store.findMany(map.call(manyArray.toArray(), function(rec) { return rec._internalModel; })).then(function() {
//Goes away after the manyArray refactor
manyArray.set('isLoaded', true);
return manyArray;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import OrderedSet from "ember-data/system/ordered-set";

var forEach = Ember.EnumerableUtils.forEach;
var forEach = Ember.ArrayPolyfills.forEach;

function Relationship(store, record, inverseKey, relationshipMeta) {
this.members = new OrderedSet();
Expand Down Expand Up @@ -52,14 +52,14 @@ Relationship.prototype = {

removeRecords: function(records) {
var self = this;
forEach(records, function(record) {
forEach.call(records, function(record) {
self.removeRecord(record);
});
},

addRecords: function(records, idx) {
var self = this;
forEach(records, function(record) {
forEach.call(records, function(record) {
self.addRecord(record, idx);
if (idx !== undefined) {
idx++;
Expand Down
40 changes: 20 additions & 20 deletions packages/ember-data/lib/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ var get = Ember.get;
var set = Ember.set;
var once = Ember.run.once;
var isNone = Ember.isNone;
var forEach = Ember.EnumerableUtils.forEach;
var indexOf = Ember.EnumerableUtils.indexOf;
var map = Ember.EnumerableUtils.map;
var forEach = Ember.ArrayPolyfills.forEach;
var indexOf = Ember.ArrayPolyfills.indexOf;
var map = Ember.ArrayPolyfills.map;
var Promise = Ember.RSVP.Promise;
var copy = Ember.copy;
var Store;
Expand Down Expand Up @@ -668,7 +668,7 @@ Store = Service.extend({
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;

return promiseArray(Ember.RSVP.all(map(ids, function(id) {
return promiseArray(Ember.RSVP.all(map.call(ids, function(id) {
return store.findRecord(modelName, id);
})).then(Ember.A, null, "DS: Store#findByIds of " + modelName + " complete"));
},
Expand Down Expand Up @@ -697,8 +697,8 @@ Store = Service.extend({
},

scheduleFetchMany: function(records) {
var internalModels = map(records, function(record) { return record._internalModel; });
return Promise.all(map(internalModels, this.scheduleFetch, this));
var internalModels = map.call(records, function(record) { return record._internalModel; });
return Promise.all(map.call(internalModels, this.scheduleFetch, this));
},

scheduleFetch: function(internalModel, options) {
Expand Down Expand Up @@ -746,7 +746,7 @@ Store = Service.extend({
}

function resolveFoundRecords(records) {
forEach(records, function(record) {
forEach.call(records, function(record) {
var pair = Ember.A(pendingFetchItems).findBy('record', record);
if (pair) {
var resolver = pair.resolver;
Expand Down Expand Up @@ -776,7 +776,7 @@ Store = Service.extend({
}

function rejectRecords(records, error) {
forEach(records, function(record) {
forEach.call(records, function(record) {
var pair = Ember.A(pendingFetchItems).findBy('record', record);
if (pair) {
var resolver = pair.resolver;
Expand All @@ -802,7 +802,7 @@ Store = Service.extend({

var snapshots = Ember.A(records).invoke('createSnapshot');
var groups = adapter.groupRecordsForFindMany(this, snapshots);
forEach(groups, function (groupOfSnapshots) {
forEach.call(groups, function (groupOfSnapshots) {
var groupOfRecords = Ember.A(groupOfSnapshots).mapBy('_internalModel');
var requestedRecords = Ember.A(groupOfRecords);
var ids = requestedRecords.mapBy('id');
Expand All @@ -819,7 +819,7 @@ Store = Service.extend({
}
});
} else {
forEach(pendingFetchItems, _fetchRecord);
forEach.call(pendingFetchItems, _fetchRecord);
}
},

Expand Down Expand Up @@ -955,7 +955,7 @@ Store = Service.extend({
*/
findMany: function(internalModels) {
var store = this;
return Promise.all(map(internalModels, function(internalModel) {
return Promise.all(map.call(internalModels, function(internalModel) {
return store._findByInternalModel(internalModel);
}));
},
Expand Down Expand Up @@ -1262,9 +1262,9 @@ Store = Service.extend({
var typeMaps = this.typeMaps;
var keys = Ember.keys(typeMaps);

var types = map(keys, byType);
var types = map.call(keys, byType);

forEach(types, this.unloadAll, this);
forEach.call(types, this.unloadAll, this);
} else {
var typeClass = this.modelFor(modelName);
var typeMap = this.typeMapFor(typeClass);
Expand Down Expand Up @@ -1474,7 +1474,7 @@ Store = Service.extend({
var pending = this._pendingSave.slice();
this._pendingSave = [];

forEach(pending, function(pendingItem) {
forEach.call(pending, function(pendingItem) {
var snapshot = pendingItem.snapshot;
var resolver = pendingItem.resolver;
var record = snapshot._internalModel;
Expand Down Expand Up @@ -1774,7 +1774,7 @@ Store = Service.extend({
Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string' || typeof data === 'undefined');
var internalModel = this._pushInternalModel(modelName, data);
if (Ember.isArray(internalModel)) {
return map(internalModel, (item) => {
return map.call(internalModel, (item) => {
return item.getRecord();
});
}
Expand All @@ -1786,7 +1786,7 @@ Store = Service.extend({
//TODO Remove once the transition is complete
var result = pushPayload(this, modelName);
if (Ember.isArray(result)) {
return map(result, (item) => {
return map.call(result, (item) => {
return item._internalModel;
});
}
Expand All @@ -1797,16 +1797,16 @@ Store = Service.extend({
Ember.deprecate('store.push(type, data) has been deprecated. Please provide a JSON-API document object as the first and only argument to store.push.');

var type = this.modelFor(modelName);
var filter = Ember.EnumerableUtils.filter;
var filter = Ember.ArrayPolyfills.filter;

// If Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS is set to true and the payload
// contains unknown keys, log a warning.
if (Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS) {
Ember.warn("The payload for '" + type.modelName + "' contains these unknown keys: " +
Ember.inspect(filter(Ember.keys(data), function(key) {
Ember.inspect(filter.call(Ember.keys(data), function(key) {
return !(key === 'id' || key === 'links' || get(type, 'fields').has(key) || key.match(/Type$/));
})) + ". Make sure they've been defined in your model.",
filter(Ember.keys(data), function(key) {
filter.call(Ember.keys(data), function(key) {
return !(key === 'id' || key === 'links' || get(type, 'fields').has(key) || key.match(/Type$/));
}).length === 0
);
Expand Down Expand Up @@ -2061,7 +2061,7 @@ Store = Service.extend({
delete typeMap.idToRecord[id];
}

var loc = indexOf(typeMap.records, internalModel);
var loc = indexOf.call(typeMap.records, internalModel);
typeMap.records.splice(loc, 1);
},

Expand Down
6 changes: 3 additions & 3 deletions packages/ember-data/lib/system/store/finders.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from "ember-data/system/store/serializers";

var Promise = Ember.RSVP.Promise;
var map = Ember.EnumerableUtils.map;
var map = Ember.ArrayPolyfills.map;
var get = Ember.get;

export function _find(adapter, store, typeClass, id, internalModel, options) {
Expand Down Expand Up @@ -70,7 +70,7 @@ export function _findMany(adapter, store, typeClass, ids, internalModels) {
var payload = normalizeResponseHelper(serializer, store, typeClass, adapterPayload, null, 'findMany');
//TODO Optimize, no need to materialize here
var records = pushPayload(store, payload);
return map(records, function(record) { return record._internalModel; });
return map.call(records, function(record) { return record._internalModel; });
});
}, null, "DS: Extract payload of " + typeClass);
}
Expand All @@ -91,7 +91,7 @@ export function _findHasMany(adapter, store, internalModel, link, relationship)
var payload = normalizeResponseHelper(serializer, store, typeClass, adapterPayload, null, 'findHasMany');
//TODO Use a non record creating push
var records = pushPayload(store, payload);
var recordArray = map(records, function(record) { return record._internalModel; });
var recordArray = map.call(records, function(record) { return record._internalModel; });
if (serializer.get('isNewSerializerAPI')) {
recordArray.meta = payload.meta;
}
Expand Down
Loading