Skip to content

Commit

Permalink
Updates codebase to new Ember modules API based on RFC 176
Browse files Browse the repository at this point in the history
  • Loading branch information
locks committed Oct 2, 2017
1 parent 9846a95 commit 5b4b8cc
Show file tree
Hide file tree
Showing 164 changed files with 3,662 additions and 2,559 deletions.
1,022 changes: 1,022 additions & 0 deletions MODULE_REPORT.md

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions addon/-private/adapters/build-url-mixin.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Ember from 'ember';
import { camelize } from '@ember/string';
import Mixin from '@ember/object/mixin';
import { get } from '@ember/object';
import { pluralize } from 'ember-inflector';

const get = Ember.get;

/**
WARNING: This interface is likely to change in order to accomodate https://github.com/emberjs/rfcs/pull/4
Expand Down Expand Up @@ -30,7 +30,7 @@ const get = Ember.get;
@class BuildURLMixin
@namespace DS
*/
export default Ember.Mixin.create({
export default Mixin.create({
/**
Builds a URL for a given type and optional ID.
Expand Down Expand Up @@ -421,11 +421,12 @@ export default Ember.Mixin.create({
```app/adapters/application.js
import DS from 'ember-data';
import { decamelize } from '@ember/string';
import { pluralize } from 'ember-inflector';
export default DS.RESTAdapter.extend({
pathForType: function(modelName) {
var decamelized = Ember.String.decamelize(modelName);
var decamelized = decamelize(modelName);
return pluralize(decamelized);
}
});
Expand All @@ -436,7 +437,7 @@ export default Ember.Mixin.create({
@return {String} path
**/
pathForType(modelName) {
let camelized = Ember.String.camelize(modelName);
let camelized = camelize(modelName);
return pluralize(camelized);
}
});
80 changes: 53 additions & 27 deletions addon/-private/adapters/errors.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Ember from 'ember';
import { assert } from '@ember/debug';

const EmberError = Ember.Error;
import { makeArray } from "@ember/array";
import { isPresent } from "@ember/utils";
import EmberError from "@ember/error";
import { assert } from "@ember/debug";

const SOURCE_POINTER_REGEXP = /^\/?data\/(attributes|relationships)\/(.*)/;
const SOURCE_POINTER_PRIMARY_REGEXP = /^\/?data/;
const PRIMARY_ATTRIBUTE_KEY = 'base';
const PRIMARY_ATTRIBUTE_KEY = "base";

/**
A `DS.AdapterError` is used by an adapter to signal that an error occurred
Expand Down Expand Up @@ -74,13 +74,13 @@ const PRIMARY_ATTRIBUTE_KEY = 'base';
@class AdapterError
@namespace DS
*/
export function AdapterError(errors, message = 'Adapter operation failed') {
export function AdapterError(errors, message = "Adapter operation failed") {
this.isAdapterError = true;
EmberError.call(this, message);

this.errors = errors || [
{
title: 'Adapter Error',
title: "Adapter Error",
detail: message
}
];
Expand All @@ -94,7 +94,10 @@ function extendFn(ErrorClass) {

function extend(ParentErrorClass, defaultMessage) {
let ErrorClass = function(errors, message) {
assert('`AdapterError` expects json-api formatted errors array.', Array.isArray(errors || []));
assert(
"`AdapterError` expects json-api formatted errors array.",
Array.isArray(errors || [])
);
ParentErrorClass.call(this, errors, message || defaultMessage);
};
ErrorClass.prototype = Object.create(ParentErrorClass.prototype);
Expand Down Expand Up @@ -165,8 +168,10 @@ AdapterError.extend = extendFn(AdapterError);
@class InvalidError
@namespace DS
*/
export const InvalidError = extend(AdapterError,
'The adapter rejected the commit because it was invalid');
export const InvalidError = extend(
AdapterError,
"The adapter rejected the commit because it was invalid"
);

/**
A `DS.TimeoutError` is used by an adapter to signal that a request
Expand Down Expand Up @@ -200,8 +205,10 @@ export const InvalidError = extend(AdapterError,
@class TimeoutError
@namespace DS
*/
export const TimeoutError = extend(AdapterError,
'The adapter operation timed out');
export const TimeoutError = extend(
AdapterError,
"The adapter operation timed out"
);

/**
A `DS.AbortError` is used by an adapter to signal that a request to
Expand All @@ -212,8 +219,10 @@ export const TimeoutError = extend(AdapterError,
@class AbortError
@namespace DS
*/
export const AbortError = extend(AdapterError,
'The adapter operation was aborted');
export const AbortError = extend(
AdapterError,
"The adapter operation was aborted"
);

/**
A `DS.UnauthorizedError` equates to a HTTP `401 Unauthorized` response
Expand Down Expand Up @@ -248,7 +257,10 @@ export const AbortError = extend(AdapterError,
@class UnauthorizedError
@namespace DS
*/
export const UnauthorizedError = extend(AdapterError, 'The adapter operation is unauthorized');
export const UnauthorizedError = extend(
AdapterError,
"The adapter operation is unauthorized"
);

/**
A `DS.ForbiddenError` equates to a HTTP `403 Forbidden` response status.
Expand All @@ -260,7 +272,10 @@ export const UnauthorizedError = extend(AdapterError, 'The adapter operation is
@class ForbiddenError
@namespace DS
*/
export const ForbiddenError = extend(AdapterError, 'The adapter operation is forbidden');
export const ForbiddenError = extend(
AdapterError,
"The adapter operation is forbidden"
);

/**
A `DS.NotFoundError` equates to a HTTP `404 Not Found` response status.
Expand Down Expand Up @@ -298,7 +313,10 @@ export const ForbiddenError = extend(AdapterError, 'The adapter operation is for
@class NotFoundError
@namespace DS
*/
export const NotFoundError = extend(AdapterError, 'The adapter could not find the resource');
export const NotFoundError = extend(
AdapterError,
"The adapter could not find the resource"
);

/**
A `DS.ConflictError` equates to a HTTP `409 Conflict` response status.
Expand All @@ -310,7 +328,10 @@ export const NotFoundError = extend(AdapterError, 'The adapter could not find th
@class ConflictError
@namespace DS
*/
export const ConflictError = extend(AdapterError, 'The adapter operation failed due to a conflict');
export const ConflictError = extend(
AdapterError,
"The adapter operation failed due to a conflict"
);

/**
A `DS.ServerError` equates to a HTTP `500 Internal Server Error` response
Expand All @@ -320,7 +341,10 @@ export const ConflictError = extend(AdapterError, 'The adapter operation failed
@class ServerError
@namespace DS
*/
export const ServerError = extend(AdapterError, 'The adapter operation failed due to a server error');
export const ServerError = extend(
AdapterError,
"The adapter operation failed due to a server error"
);

/**
Convert an hash of errors into an array with errors in JSON-API format.
Expand Down Expand Up @@ -371,14 +395,14 @@ export const ServerError = extend(AdapterError, 'The adapter operation failed du
export function errorsHashToArray(errors) {
let out = [];

if (Ember.isPresent(errors)) {
Object.keys(errors).forEach((key) => {
let messages = Ember.makeArray(errors[key]);
if (isPresent(errors)) {
Object.keys(errors).forEach(key => {
let messages = makeArray(errors[key]);
for (let i = 0; i < messages.length; i++) {
let title = 'Invalid Attribute';
let title = "Invalid Attribute";
let pointer = `/data/attributes/${key}`;
if (key === PRIMARY_ATTRIBUTE_KEY) {
title = 'Invalid Document';
title = "Invalid Document";
pointer = `/data`;
}
out.push({
Expand Down Expand Up @@ -438,14 +462,16 @@ export function errorsHashToArray(errors) {
export function errorsArrayToHash(errors) {
let out = {};

if (Ember.isPresent(errors)) {
errors.forEach((error) => {
if (isPresent(errors)) {
errors.forEach(error => {
if (error.source && error.source.pointer) {
let key = error.source.pointer.match(SOURCE_POINTER_REGEXP);

if (key) {
key = key[2];
} else if (error.source.pointer.search(SOURCE_POINTER_PRIMARY_REGEXP) !== -1) {
} else if (
error.source.pointer.search(SOURCE_POINTER_PRIMARY_REGEXP) !== -1
) {
key = PRIMARY_ATTRIBUTE_KEY;
}

Expand Down
23 changes: 13 additions & 10 deletions addon/-private/system/debug/debug-adapter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/**
@module ember-data
*/
import Ember from 'ember';
import { addObserver, removeObserver } from '@ember/object/observers';

import { A } from '@ember/array';
import DataAdapter from '@ember/debug/data-adapter';
import { capitalize, underscore } from '@ember/string';
import { assert } from '@ember/debug';
import { get } from '@ember/object';
import Model from '../model/model';
const capitalize = Ember.String.capitalize;
const underscore = Ember.String.underscore;
const { assert, get } = Ember;

/*
Extend `Ember.DataAdapter` with ED specific code.
Expand All @@ -15,7 +18,7 @@ const { assert, get } = Ember;
@extends Ember.DataAdapter
@private
*/
export default Ember.DataAdapter.extend({
export default DataAdapter.extend({
getFilters() {
return [
{ name: 'isNew', desc: 'New' },
Expand Down Expand Up @@ -73,7 +76,7 @@ export default Ember.DataAdapter.extend({

getRecordKeywords(record) {
let keywords = [];
let keys = Ember.A(['id']);
let keys = A(['id']);
record.eachAttribute((key) => keys.push(key));
keys.forEach((key) => keywords.push(get(record, key)));
return keywords;
Expand All @@ -98,8 +101,8 @@ export default Ember.DataAdapter.extend({
},

observeRecord(record, recordUpdated) {
let releaseMethods = Ember.A();
let keysToObserve = Ember.A(['id', 'isNew', 'hasDirtyAttributes']);
let releaseMethods = A();
let keysToObserve = A(['id', 'isNew', 'hasDirtyAttributes']);

record.eachAttribute((key) => keysToObserve.push(key));
let adapter = this;
Expand All @@ -108,9 +111,9 @@ export default Ember.DataAdapter.extend({
let handler = function() {
recordUpdated(adapter.wrapRecord(record));
};
Ember.addObserver(record, key, handler);
addObserver(record, key, handler);
releaseMethods.push(function() {
Ember.removeObserver(record, key, handler);
removeObserver(record, key, handler);
});
});

Expand Down
7 changes: 4 additions & 3 deletions addon/-private/system/is-array-like.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Ember from 'ember';
import { typeOf } from '@ember/utils';
import EmberArray from '@ember/array';

/*
We're using this to detect arrays and "array-like" objects.
Expand All @@ -13,9 +14,9 @@ import Ember from 'ember';
export default function isArrayLike(obj) {
if (!obj || obj.setInterval) { return false; }
if (Array.isArray(obj)) { return true; }
if (Ember.Array.detect(obj)) { return true; }
if (EmberArray.detect(obj)) { return true; }

let type = Ember.typeOf(obj);
let type = typeOf(obj);
if ('array' === type) { return true; }
if ((obj.length !== undefined) && 'object' === type) { return true; }
return false;
Expand Down
12 changes: 7 additions & 5 deletions addon/-private/system/many-array.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
/**
@module ember-data
*/
import Ember from 'ember';
import { all } from 'rsvp';

import Evented from '@ember/object/evented';
import MutableArray from '@ember/array/mutable';
import EmberObject, { get } from '@ember/object';
import { assert } from '@ember/debug';
import { PromiseArray } from "./promise-proxies";
import { _objectIsAlive } from "./store/common";
import diffArray from './diff-array';

const { get } = Ember;

/**
A `ManyArray` is a `MutableArray` that represents the contents of a has-many
relationship.
Expand Down Expand Up @@ -52,7 +54,7 @@ const { get } = Ember;
@extends Ember.Object
@uses Ember.MutableArray, Ember.Evented
*/
export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, {
export default EmberObject.extend(MutableArray, Evented, {
init() {
this._super(...arguments);

Expand Down Expand Up @@ -260,7 +262,7 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, {
save() {
let manyArray = this;
let promiseLabel = 'DS: ManyArray#save ' + get(this, 'type');
let promise = Ember.RSVP.all(this.invoke("save"), promiseLabel).
let promise = all(this.invoke("save"), promiseLabel).
then(() => manyArray, null, 'DS: ManyArray#save return ManyArray');

return PromiseArray.create({ promise });
Expand Down
Loading

0 comments on commit 5b4b8cc

Please sign in to comment.