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

Remove lodash #502

Merged
merged 7 commits into from
Jun 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ install:

script:
- npm run legacy
- ember try:one $EMBER_TRY_SCENARIO --skip-cleanup
- ember try:one $EMBER_TRY_SCENARIO

after_script:
- if [ "$COVERAGE" ]; then sed 's/SF:modules\/emberfire\//SF:addon\//g' coverage/lcov.info > coverage/lcov.info.fixed; fi
Expand Down
55 changes: 28 additions & 27 deletions addon/adapters/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@ import Ember from 'ember';
import DS from 'ember-data';
import Waitable from '../mixins/waitable';
import toPromise from '../utils/to-promise';
import assign from 'lodash/object/assign';
import forEach from 'lodash/collection/forEach';
import filter from 'lodash/collection/filter';
import map from 'lodash/collection/map';
import includes from 'lodash/collection/includes';
import indexOf from 'lodash/array/indexOf';
import find from 'lodash/collection/find';

var Promise = Ember.RSVP.Promise;
const { assign, RSVP: { Promise } } = Ember;

var uniq = function (arr) {
var ret = Ember.A();

arr.forEach(function(k) {
if (indexOf(ret, k) < 0) {
if (ret.indexOf(k) < 0) {
ret.push(k);
}
});
Expand Down Expand Up @@ -521,26 +514,26 @@ export default DS.Adapter.extend(Waitable, {
var dirtyRecords = [];

// Added
var addedRecords = filter(ids, (id) => {
var addedRecords = ids.filter((id) => {
return !idsCache.includes(id);
});

// Dirty
dirtyRecords = filter(ids, (id) => {
dirtyRecords = ids.filter((id) => {
var relatedModelName = relationship.type;
return store.hasRecordForId(relatedModelName, id) && store.peekRecord(relatedModelName, id).get('hasDirtyAttributes') === true;
});

dirtyRecords = map(uniq(dirtyRecords.concat(addedRecords)), (id) => {
dirtyRecords = uniq(dirtyRecords.concat(addedRecords)).map((id) => {
return this._saveHasManyRecord(store, typeClass, relationship, recordRef, id);
});

// Removed
var removedRecords = filter(idsCache, (id) => {
return !includes(ids, id);
var removedRecords = idsCache.filter((id) => {
return !ids.includes(id);
});

removedRecords = map(removedRecords, (id) => {
removedRecords = removedRecords.map((id) => {
return this._removeHasManyRecord(store, recordRef, relationship.key, typeClass, id);
});
// Combine all the saved records
Expand Down Expand Up @@ -704,23 +697,30 @@ export default DS.Adapter.extend(Waitable, {
* @return {Object}
*/
getFirstEmbeddingParent(internalModel) {
var relationships = assign(
let relationships = assign(
{},
internalModel._implicitRelationships,
internalModel._relationships.initializedRelationships
);

var embeddingParentRel = find(relationships, (rel) => {
var members = rel.members.toArray();
var parent = members[0];
let embeddingParentRel;
let relationshipKeys = Object.keys(relationships);

for (let i = 0; i < relationshipKeys.length; i++) {
let rel = relationships[relationshipKeys[i]];
let members = rel.members.toArray();
let parent = members[0];

if (!parent || !rel.inverseKey) {
return false;
continue;
}

var parentRel = parent._relationships.get(rel.inverseKey);
return this.isRelationshipEmbedded(this.store, parent.type.modelName, parentRel.relationshipMeta);
});
let parentRel = parent._relationships.get(rel.inverseKey);
if (this.isRelationshipEmbedded(this.store, parent.type.modelName, parentRel.relationshipMeta)) {
embeddingParentRel = rel;
break;
}
}

if (embeddingParentRel) {
var parent = embeddingParentRel.members.toArray()[0];
Expand Down Expand Up @@ -766,7 +766,7 @@ export default DS.Adapter.extend(Waitable, {
return;
}

forEach(this._queue, (key) => {
this._queue.forEach((key) => {
const { payload, modelName } = this._queuedPayloads[key];
const normalizedData = store.normalize(modelName, payload);
store.push(normalizedData);
Expand Down Expand Up @@ -797,7 +797,7 @@ export default DS.Adapter.extend(Waitable, {
const key = `${modelName}-${id}`;
if (this._queuedPayloads[key]) {
// remove from original place in queue (will be added to end)
const oldPosition = indexOf(this._queue, key);
const oldPosition = this._queue.indexOf(key);
this._queue.splice(oldPosition, 1);
}
this._queuedPayloads[key] = { payload, modelName };
Expand Down Expand Up @@ -836,10 +836,11 @@ export default DS.Adapter.extend(Waitable, {
const isEmbedded = this.isRelationshipEmbedded(store, typeClass.modelName, relationship);
if (isEmbedded) {
const relationshipTypeClass = store.modelFor(relationship.type);
forEach(relationshipPayload, (obj, id) => {
for (let id in relationshipPayload) {
let obj = relationshipPayload[id];
obj.id = id;
this._updateRecordCacheForType(relationshipTypeClass, obj, store);
});
}
} else {
const ids = Object.keys(relationshipPayload);
cache[key] = Ember.A(ids);
Expand Down
17 changes: 9 additions & 8 deletions addon/initializers/emberfire.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import DS from 'ember-data';
import firebase from 'firebase';
import FirebaseAdapter from '../adapters/firebase';
import FirebaseSerializer from '../serializers/firebase';
import forEach from 'lodash/collection/forEach';

var VERSION = '0.0.0';

Expand Down Expand Up @@ -43,13 +42,15 @@ export default {
_emberfirePatched: true,

_emberfireHandleRecordPush(records) {
forEach(records, (record) => {
var modelName = record.constructor.modelName;
var adapter = this.adapterFor(modelName);
if (adapter.recordWasPushed) {
adapter.recordWasPushed(this, modelName, record);
}
});
if (typeof records !== 'undefined') {
records.forEach((record) => {
var modelName = record.constructor.modelName;
var adapter = this.adapterFor(modelName);
if (adapter.recordWasPushed) {
adapter.recordWasPushed(this, modelName, record);
}
});
}
},

push() {
Expand Down
3 changes: 2 additions & 1 deletion addon/serializers/firebase.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Ember from 'ember';
import DS from 'ember-data';
import assign from 'lodash/object/assign';
import firebase from 'firebase';

const { assign } = Ember;

/**
* The Firebase serializer helps normalize relationships and can be extended on
* a per model basis.
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"broccoli-webpack": "^1.0.0",
"chalk": "1.1.3",
"ember-cli-babel": "5.1.6",
"ember-lodash": "0.0.7",
"firebase": "^3.4.1"
},
"devDependencies": {
Expand Down Expand Up @@ -91,7 +90,6 @@
"gulp-sourcemaps": "1.6.0",
"gulp-uglify": "1.5.3",
"gulp-util": "3.0.7",
"lodash": "3.10.1",
"sinon": "^1.17.3",
"torii": "0.8.0",
"vinyl-buffer": "1.0.0",
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/serializers/firebase-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import Post from 'dummy/models/post';
import WithDate from 'dummy/models/with-date';
import Comment from 'dummy/models/comment';
import User from 'dummy/models/user';
import assign from 'lodash/object/assign';

const { assign } = Ember;

describe('FirebaseSerializer', function() {
setupTest('emberfire@serializer:firebase', {
Expand Down
10 changes: 0 additions & 10 deletions vendor/legacy/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,3 @@
* https://github.com/firebase/emberfire/
* License: MIT
*/

/**
* @license
* lodash 3.10.0 (Custom Build) <https://lodash.com/>
* Build: `lodash modularize modern exports="es" -o ./`
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Available under MIT license <https://lodash.com/license>
*/