Skip to content

Commit

Permalink
Linter changes for addon, addon/adapters and addon/serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-the-pete committed Dec 27, 2016
1 parent 7f4c840 commit d40afd7
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 126 deletions.
13 changes: 6 additions & 7 deletions addon/adapters/json-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ import { instrument, deprecate } from 'ember-data/-private/debug';
@namespace DS
@extends DS.RESTAdapter
*/
var JSONAPIAdapter = RESTAdapter.extend({
const JSONAPIAdapter = RESTAdapter.extend({
defaultSerializer: '-json-api',

/**
Expand Down Expand Up @@ -250,13 +250,13 @@ var JSONAPIAdapter = RESTAdapter.extend({
if (isEnabled('ds-improved-ajax') && !this._hasCustomizedAjax()) {
return this._super(...arguments);
} else {
var url = this.buildURL(type.modelName, ids, snapshots, 'findMany');
const url = this.buildURL(type.modelName, ids, snapshots, 'findMany');
return this.ajax(url, 'GET', { data: { filter: { id: ids.join(',') } } });
}
},

pathForType(modelName) {
var dasherized = Ember.String.dasherize(modelName);
const dasherized = Ember.String.dasherize(modelName);
return Ember.String.pluralize(dasherized);
},

Expand All @@ -265,13 +265,12 @@ var JSONAPIAdapter = RESTAdapter.extend({
if (isEnabled('ds-improved-ajax') && !this._hasCustomizedAjax()) {
return this._super(...arguments);
} else {
var data = {};
var serializer = store.serializerFor(type.modelName);
const data = {};
const serializer = store.serializerFor(type.modelName);

serializer.serializeIntoHash(data, type, snapshot, { includeId: true });

var id = snapshot.id;
var url = this.buildURL(type.modelName, id, snapshot, 'updateRecord');
const url = this.buildURL(type.modelName, snapshot.id, snapshot, 'updateRecord');

return this.ajax(url, 'PATCH', { data: data });
}
Expand Down
24 changes: 12 additions & 12 deletions addon/adapters/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,40 +888,40 @@ var RESTAdapter = Adapter.extend(BuildURLMixin, {
loaded separately by `findMany`.
*/
groupRecordsForFindMany(store, snapshots) {
var groups = MapWithDefault.create({ defaultValue() { return []; } });
var adapter = this;
var maxURLLength = this.maxURLLength;
const groups = MapWithDefault.create({ defaultValue() { return []; } });
const adapter = this;
const maxURLLength = this.maxURLLength;

snapshots.forEach((snapshot) => {
var baseUrl = adapter._stripIDFromURL(store, snapshot);
const baseUrl = adapter._stripIDFromURL(store, snapshot);
groups.get(baseUrl).push(snapshot);
});

function splitGroupToFitInUrl(group, maxURLLength, paramNameLength) {
var baseUrl = adapter._stripIDFromURL(store, group[0]);
var idsSize = 0;
var splitGroups = [[]];
let idsSize = 0;
const baseUrl = adapter._stripIDFromURL(store, group[0]);
const splitGroups = [[]];

group.forEach((snapshot) => {
var additionalLength = encodeURIComponent(snapshot.id).length + paramNameLength;
const additionalLength = encodeURIComponent(snapshot.id).length + paramNameLength;
if (baseUrl.length + idsSize + additionalLength >= maxURLLength) {
idsSize = 0;
splitGroups.push([]);
}

idsSize += additionalLength;

var lastGroupIndex = splitGroups.length - 1;
const lastGroupIndex = splitGroups.length - 1;
splitGroups[lastGroupIndex].push(snapshot);
});

return splitGroups;
}

var groupsArray = [];
let groupsArray = [];
groups.forEach((group, key) => {
var paramNameLength = '&ids%5B%5D='.length;
var splitGroups = splitGroupToFitInUrl(group, maxURLLength, paramNameLength);
const paramNameLength = '&ids%5B%5D='.length;
const splitGroups = splitGroupToFitInUrl(group, maxURLLength, paramNameLength);

splitGroups.forEach((splitGroup) => groupsArray.push(splitGroup));
});
Expand Down
12 changes: 6 additions & 6 deletions addon/attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function getValue(record, key) {
@namespace
@method attr
@for DS
@param {String} type the attribute type
@param {String|Object} type the attribute type
@param {Object} options a hash of options
@return {Attribute}
*/
Expand All @@ -122,25 +122,25 @@ export default function attr(type, options) {
options = options || {};
}

var meta = {
const meta = {
type: type,
isAttribute: true,
options: options
};

return Ember.computed({
get(key) {
var internalModel = this._internalModel;
const internalModel = this._internalModel;
if (hasValue(internalModel, key)) {
return getValue(internalModel, key);
} else {
return getDefaultValue(this, options, key);
}
},
set(key, value) {
var internalModel = this._internalModel;
var oldValue = getValue(internalModel, key);
var originalValue;
const internalModel = this._internalModel;
const oldValue = getValue(internalModel, key);
let originalValue;

if (value !== oldValue) {
// Add the new value to the changed attributes hash; it will get deleted by
Expand Down
62 changes: 31 additions & 31 deletions addon/serializers/embedded-records-mixin.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Ember from 'ember';
import { warn } from "ember-data/-private/debug";

var get = Ember.get;
var set = Ember.set;
var camelize = Ember.String.camelize;
const get = Ember.get;
const set = Ember.set;
const camelize = Ember.String.camelize;

/**
## Using Embedded Records
Expand Down Expand Up @@ -125,7 +125,7 @@ export default Ember.Mixin.create({
@return {Object} the normalized hash
**/
normalize(typeClass, hash, prop) {
var normalizedHash = this._super(typeClass, hash, prop);
const normalizedHash = this._super(typeClass, hash, prop);
return this._extractEmbeddedRecords(this, this.store, typeClass, normalizedHash);
},

Expand Down Expand Up @@ -190,16 +190,16 @@ export default Ember.Mixin.create({
@param {Object} relationship
*/
serializeBelongsTo(snapshot, json, relationship) {
var attr = relationship.key;
const attr = relationship.key;
if (this.noSerializeOptionSpecified(attr)) {
this._super(snapshot, json, relationship);
return;
}
var includeIds = this.hasSerializeIdsOption(attr);
var includeRecords = this.hasSerializeRecordsOption(attr);
var embeddedSnapshot = snapshot.belongsTo(attr);
const includeIds = this.hasSerializeIdsOption(attr);
const includeRecords = this.hasSerializeRecordsOption(attr);
const embeddedSnapshot = snapshot.belongsTo(attr);
if (includeIds) {
var serializedKey = this._getMappedKey(relationship.key, snapshot.type);
let serializedKey = this._getMappedKey(relationship.key, snapshot.type);
if (serializedKey === relationship.key && this.keyForRelationship) {
serializedKey = this.keyForRelationship(relationship.key, relationship.kind, "serialize");
}
Expand All @@ -220,7 +220,7 @@ export default Ember.Mixin.create({

_serializeEmbeddedBelongsTo(snapshot, json, relationship) {
let embeddedSnapshot = snapshot.belongsTo(relationship.key);
var serializedKey = this._getMappedKey(relationship.key, snapshot.type);
let serializedKey = this._getMappedKey(relationship.key, snapshot.type);
if (serializedKey === relationship.key && this.keyForRelationship) {
serializedKey = this.keyForRelationship(relationship.key, relationship.kind, "serialize");
}
Expand Down Expand Up @@ -373,7 +373,7 @@ export default Ember.Mixin.create({
@param {Object} relationship
*/
serializeHasMany(snapshot, json, relationship) {
var attr = relationship.key;
const attr = relationship.key;
if (this.noSerializeOptionSpecified(attr)) {
this._super(snapshot, json, relationship);
return;
Expand Down Expand Up @@ -404,8 +404,8 @@ export default Ember.Mixin.create({
TODO: Make the default in Ember-data 3.0??
*/
_serializeHasManyAsIdsAndTypes(snapshot, json, relationship) {
var serializedKey = this.keyForAttribute(relationship.key, 'serialize');
var hasMany = snapshot.hasMany(relationship.key);
const serializedKey = this.keyForAttribute(relationship.key, 'serialize');
const hasMany = snapshot.hasMany(relationship.key);

json[serializedKey] = Ember.A(hasMany).map(function (recordSnapshot) {
//
Expand All @@ -417,7 +417,7 @@ export default Ember.Mixin.create({
},

_serializeEmbeddedHasMany(snapshot, json, relationship) {
var serializedKey = this._getMappedKey(relationship.key, snapshot.type);
let serializedKey = this._getMappedKey(relationship.key, snapshot.type);
if (serializedKey === relationship.key && this.keyForRelationship) {
serializedKey = this.keyForRelationship(relationship.key, relationship.kind, "serialize");
}
Expand Down Expand Up @@ -467,63 +467,63 @@ export default Ember.Mixin.create({
@param {Object} json
*/
removeEmbeddedForeignKey(snapshot, embeddedSnapshot, relationship, json) {
if (relationship.kind === 'hasMany') {
return;
} else if (relationship.kind === 'belongsTo') {
var parentRecord = snapshot.type.inverseFor(relationship.key, this.store);
if (relationship.kind === 'belongsTo') {
const parentRecord = snapshot.type.inverseFor(relationship.key, this.store);
if (parentRecord) {
var name = parentRecord.name;
var embeddedSerializer = this.store.serializerFor(embeddedSnapshot.modelName);
var parentKey = embeddedSerializer.keyForRelationship(name, parentRecord.kind, 'deserialize');
const name = parentRecord.name;
const embeddedSerializer = this.store.serializerFor(embeddedSnapshot.modelName);
const parentKey = embeddedSerializer.keyForRelationship(name, parentRecord.kind, 'deserialize');
if (parentKey) {
delete json[parentKey];
}
}
}
} /*else if (relationship.kind === 'hasMany') {
return;
}*/
},

// checks config for attrs option to embedded (always) - serialize and deserialize
hasEmbeddedAlwaysOption(attr) {
var option = this.attrsOption(attr);
const option = this.attrsOption(attr);
return option && option.embedded === 'always';
},

// checks config for attrs option to serialize ids
hasSerializeRecordsOption(attr) {
var alwaysEmbed = this.hasEmbeddedAlwaysOption(attr);
var option = this.attrsOption(attr);
const alwaysEmbed = this.hasEmbeddedAlwaysOption(attr);
const option = this.attrsOption(attr);
return alwaysEmbed || (option && (option.serialize === 'records'));
},

// checks config for attrs option to serialize records
hasSerializeIdsOption(attr) {
var option = this.attrsOption(attr);
const option = this.attrsOption(attr);
return option && (option.serialize === 'ids' || option.serialize === 'id');
},

// checks config for attrs option to serialize records as objects containing id and types
hasSerializeIdsAndTypesOption(attr) {
var option = this.attrsOption(attr);
const option = this.attrsOption(attr);
return option && (option.serialize === 'ids-and-types' || option.serialize === 'id-and-type');
},

// checks config for attrs option to serialize records
noSerializeOptionSpecified(attr) {
var option = this.attrsOption(attr);
const option = this.attrsOption(attr);
return !(option && (option.serialize || option.embedded));
},

// checks config for attrs option to deserialize records
// a defined option object for a resource is treated the same as
// `deserialize: 'records'`
hasDeserializeRecordsOption(attr) {
var alwaysEmbed = this.hasEmbeddedAlwaysOption(attr);
var option = this.attrsOption(attr);
const alwaysEmbed = this.hasEmbeddedAlwaysOption(attr);
const option = this.attrsOption(attr);
return alwaysEmbed || (option && option.deserialize === 'records');
},

attrsOption(attr) {
var attrs = this.get('attrs');
const attrs = this.get('attrs');
return attrs && (attrs[camelize(attr)] || attrs[attr]);
},

Expand Down
23 changes: 11 additions & 12 deletions addon/serializers/json-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import normalizeModelName from 'ember-data/-private/system/normalize-model-name'
import { pluralize, singularize } from 'ember-inflector';
import isEnabled from 'ember-data/-private/features';

var dasherize = Ember.String.dasherize;
const dasherize = Ember.String.dasherize;

/**
Ember Data 2.0 Serializer:
Expand Down Expand Up @@ -190,8 +190,7 @@ const JSONAPISerializer = JSONSerializer.extend({

relationshipDataHash.type = modelName;
} else {
let type = this.modelNameFromPayloadKey(relationshipDataHash.type);
relationshipDataHash.type = type;
relationshipDataHash.type = this.modelNameFromPayloadKey(relationshipDataHash.type);
}

return relationshipDataHash;
Expand Down Expand Up @@ -284,7 +283,7 @@ const JSONAPISerializer = JSONSerializer.extend({
},

extractAttributes(modelClass, resourceHash) {
var attributes = {};
const attributes = {};

if (resourceHash.attributes) {
modelClass.eachAttribute((key) => {
Expand Down Expand Up @@ -532,15 +531,15 @@ const JSONAPISerializer = JSONSerializer.extend({
},

serializeBelongsTo(snapshot, json, relationship) {
var key = relationship.key;
const key = relationship.key;

if (this._canSerialize(key)) {
var belongsTo = snapshot.belongsTo(key);
const belongsTo = snapshot.belongsTo(key);
if (belongsTo !== undefined) {

json.relationships = json.relationships || {};

var payloadKey = this._getMappedKey(key, snapshot.type);
let payloadKey = this._getMappedKey(key, snapshot.type);
if (payloadKey === key) {
payloadKey = this.keyForRelationship(key, 'belongsTo', 'serialize');
}
Expand Down Expand Up @@ -577,19 +576,19 @@ const JSONAPISerializer = JSONSerializer.extend({
},

serializeHasMany(snapshot, json, relationship) {
var key = relationship.key;
var shouldSerializeHasMany = '_shouldSerializeHasMany';
const key = relationship.key;
let shouldSerializeHasMany = '_shouldSerializeHasMany';
if (isEnabled("ds-check-should-serialize-relationships")) {
shouldSerializeHasMany = 'shouldSerializeHasMany';
}

if (this[shouldSerializeHasMany](snapshot, key, relationship)) {
var hasMany = snapshot.hasMany(key);
const hasMany = snapshot.hasMany(key);
if (hasMany !== undefined) {

json.relationships = json.relationships || {};

var payloadKey = this._getMappedKey(key, snapshot.type);
let payloadKey = this._getMappedKey(key, snapshot.type);
if (payloadKey === key && this.keyForRelationship) {
payloadKey = this.keyForRelationship(key, 'hasMany', 'serialize');
}
Expand Down Expand Up @@ -743,7 +742,7 @@ if (isEnabled("ds-payload-type-hooks")) {
runInDebug(function() {
JSONAPISerializer.reopen({
willMergeMixin(props) {
var constructor = this.constructor;
const constructor = this.constructor;
warn(`You've defined 'extractMeta' in ${constructor.toString()} which is not used for serializers extending JSONAPISerializer. Read more at http://emberjs.com/api/data/classes/DS.JSONAPISerializer.html#toc_customizing-meta on how to customize meta when using JSON API.`, Ember.isNone(props.extractMeta) || props.extractMeta === JSONSerializer.prototype.extractMeta, {
id: 'ds.serializer.json-api.extractMeta'
});
Expand Down
Loading

0 comments on commit d40afd7

Please sign in to comment.