Skip to content

Commit

Permalink
Use lodash-es (#1666)
Browse files Browse the repository at this point in the history
  • Loading branch information
samselikoff authored Jun 26, 2019
1 parent 6243251 commit dcef77a
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
3 changes: 1 addition & 2 deletions addon/server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Server } from '@miragejs/server';
import { getModels } from './ember-data';
import { hasEmberData } from './utils/ember-data';
import _assign from 'lodash/assign';

export { defaultPassthroughs } from '@miragejs/server';

Expand All @@ -10,7 +9,7 @@ export default class EmberServer extends Server {
constructor(options) {
// Merge models from autogenerated Ember Data models with user defined models
if (hasEmberData && options.discoverEmberDataModels) {
options.models = _assign({}, getModels(), options.models);
options.models = Object.assign({}, getModels(), options.models);
}

super(options);
Expand Down
3 changes: 1 addition & 2 deletions addon/start-mirage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { getWithDefault } from '@ember/object';
import readModules from './utils/read-modules';
import Server from './server';
import _assign from 'lodash/assign';
import { singularize, pluralize } from 'ember-inflector';

/**
Expand Down Expand Up @@ -33,7 +32,7 @@ export default function startMirage(owner, { env, baseConfig, testConfig } = {})
let environment = env.environment;
let discoverEmberDataModels = getWithDefault(env['ember-cli-mirage'] || {}, 'discoverEmberDataModels', true);
let modules = readModules(env.modulePrefix);
let options = _assign(modules, {environment, baseConfig, testConfig, discoverEmberDataModels});
let options = Object.assign(modules, {environment, baseConfig, testConfig, discoverEmberDataModels});
options.trackRequests = env['ember-cli-mirage'].trackRequests;
options.inflector = { singularize, pluralize };

Expand Down
4 changes: 1 addition & 3 deletions addon/utils/ember-data.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* global requirejs */

import _find from 'lodash/find';

function _hasEmberData() {
let matchRegex = /^ember-data/i;
return !!_find(Object.keys(requirejs.entries), (e) => !!e.match(matchRegex));
return !!(Object.keys(requirejs.entries).find(e => !!e.match(matchRegex)));
}

/**
Expand Down
10 changes: 5 additions & 5 deletions addon/utils/read-modules.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* global requirejs, require */
/* global requirejs */
/* eslint-env node */
'use strict';

import assert from '../assert';
import _camelCase from 'lodash/camelCase';
import { camelCase } from 'lodash-es';
import { pluralize } from '../utils/inflector';
import require from 'require';

Expand All @@ -18,7 +18,7 @@ export default function(prefix) {
let modules = ['factories', 'fixtures', 'scenarios', 'models', 'serializers', 'identity-managers'];
let mirageModuleRegExp = new RegExp(`^${prefix}/mirage/(${modules.join('|')})`);
let modulesMap = modules.reduce((memo, name) => {
memo[_camelCase(name)] = {};
memo[camelCase(name)] = {};
return memo;
}, {});

Expand All @@ -29,7 +29,7 @@ export default function(prefix) {
return;
}
let moduleParts = moduleName.split('/');
let moduleType = _camelCase(moduleParts[moduleParts.length - 2]);
let moduleType = camelCase(moduleParts[moduleParts.length - 2]);
let moduleKey = moduleParts[moduleParts.length - 1];
assert(`Subdirectories under ${moduleType} are not supported`,
moduleParts[moduleParts.length - 3] === 'mirage');
Expand All @@ -53,7 +53,7 @@ export default function(prefix) {

let data = module.default;

modulesMap[moduleType][_camelCase(moduleKey)] = data;
modulesMap[moduleType][camelCase(moduleKey)] = data;
});

return modulesMap;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"ember-cli-babel": "^7.5.0",
"ember-get-config": "^0.2.2",
"ember-inflector": "^2.0.0 || ^3.0.0",
"lodash": "^4.17.11",
"lodash-es": "^4.17.11",
"pretender": "3.0.1"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { module, test } from 'qunit';
import { Server, Model, Collection, ActiveModelSerializer } from 'ember-cli-mirage';
import _uniqBy from 'lodash/uniqBy';
import { uniqBy } from 'lodash-es';
import promiseAjax from '../../../helpers/promise-ajax';

module('Integration | Route handlers | Function handler | #serialize', function(hooks) {
Expand Down Expand Up @@ -135,7 +135,7 @@ module('Integration | Route handlers | Function handler | #serialize', function(

this.server.get('/users', function(schema) {
let users = schema.users.all().models;
let uniqueNames = _uniqBy(users, 'name');
let uniqueNames = uniqBy(users, 'name');
let collection = new Collection('user', uniqueNames);
let json = this.serialize(collection, 'sparse-user');

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/serializers/base/basic-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SerializerRegistry from 'ember-cli-mirage/serializer-registry';
import schemaHelper from '../schema-helper';
import { module, test } from 'qunit';

import _uniqBy from 'lodash/uniqBy';
import { uniqBy } from 'lodash-es';

module('Integration | Serializers | Base | Basic', function(hooks) {
hooks.beforeEach(function() {
Expand Down Expand Up @@ -79,7 +79,7 @@ module('Integration | Serializers | Base | Basic', function(hooks) {
this.schema.wordSmiths.create({ name: 'Ganondorf' });

let wordSmiths = this.schema.wordSmiths.all().models;
let uniqueNames = _uniqBy(wordSmiths, 'name');
let uniqueNames = uniqBy(wordSmiths, 'name');
let result = this.registry.serialize(uniqueNames);

assert.deepEqual(result, uniqueNames);
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9458,6 +9458,11 @@ locate-path@^3.0.0:
p-locate "^3.0.0"
path-exists "^3.0.0"

lodash-es@^4.17.11:
version "4.17.11"
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.11.tgz#145ab4a7ac5c5e52a3531fb4f310255a152b4be0"
integrity sha512-DHb1ub+rMjjrxqlB3H56/6MXtm1lSksDp2rA2cNWjG8mlDUYFhUj3Di2Zn5IwSU87xLv8tNIQ7sSwE/YOX/D/Q==

lodash._baseassign@^3.0.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz#8c38a099500f215ad09e59f1722fd0c52bfe0a4e"
Expand Down

0 comments on commit dcef77a

Please sign in to comment.