Skip to content

Commit

Permalink
Updates addon to adhere to RFC 176 (emberjs#5108)
Browse files Browse the repository at this point in the history
* Updates codebase to new Ember modules API based on RFC 176

* bumps ember-cli-babel to latest 6.8
  • Loading branch information
locks authored and Danail Nachev committed Oct 9, 2017
1 parent 8dd4b35 commit 6dcece6
Show file tree
Hide file tree
Showing 165 changed files with 2,600 additions and 1,352 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);
}
});
32 changes: 16 additions & 16 deletions addon/-private/adapters/errors.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Ember from 'ember';
import { makeArray } from '@ember/array';
import { isPresent } from '@ember/utils';
import EmberError from '@ember/error';
import { assert } from '@ember/debug';

const EmberError = Ember.Error;

const SOURCE_POINTER_REGEXP = /^\/?data\/(attributes|relationships)\/(.*)/;
const SOURCE_POINTER_PRIMARY_REGEXP = /^\/?data/;
const PRIMARY_ATTRIBUTE_KEY = 'base';
Expand Down Expand Up @@ -54,10 +54,10 @@ const PRIMARY_ATTRIBUTE_KEY = 'base';
`under-maintenance` route:
```app/routes/application.js
import Ember from 'ember';
import Route from '@ember/routing/route';
import MaintenanceError from '../adapters/maintenance-error';
export default Ember.Route.extend({
export default Route.extend({
actions: {
error(error, transition) {
if (error instanceof MaintenanceError) {
Expand Down Expand Up @@ -136,13 +136,13 @@ AdapterError.extend = extendFn(AdapterError);
rejects with a `DS.InvalidError` object that looks like this:
```app/adapters/post.js
import Ember from 'ember';
import RSVP from 'RSVP';
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
updateRecord() {
// Fictional adapter that always rejects
return Ember.RSVP.reject(new DS.InvalidError([
return RSVP.reject(new DS.InvalidError([
{
detail: 'Must be unique',
source: { pointer: '/data/attributes/title' }
Expand Down Expand Up @@ -177,12 +177,12 @@ export const InvalidError = extend(AdapterError,
connection if an adapter operation has timed out:
```app/routes/application.js
import Ember from 'ember';
import Route from '@ember/routing/route';
import DS from 'ember-data';
const { TimeoutError } = DS;
export default Ember.Route.extend({
export default Route.extend({
actions: {
error(error, transition) {
if (error instanceof TimeoutError) {
Expand Down Expand Up @@ -225,12 +225,12 @@ export const AbortError = extend(AdapterError,
request is unauthorized:
```app/routes/application.js
import Ember from 'ember';
import Route from '@ember/routing/route';
import DS from 'ember-data';
const { UnauthorizedError } = DS;
export default Ember.Route.extend({
export default Route.extend({
actions: {
error(error, transition) {
if (error instanceof UnauthorizedError) {
Expand Down Expand Up @@ -271,12 +271,12 @@ export const ForbiddenError = extend(AdapterError, 'The adapter operation is for
for a specific model that does not exist. For example:
```app/routes/post.js
import Ember from 'ember';
import Route from '@ember/routing/route';
import DS from 'ember-data';
const { NotFoundError } = DS;
export default Ember.Route.extend({
export default Route.extend({
model(params) {
return this.get('store').findRecord('post', params.post_id);
},
Expand Down Expand Up @@ -371,9 +371,9 @@ export const ServerError = extend(AdapterError, 'The adapter operation failed du
export function errorsHashToArray(errors) {
let out = [];

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

if (Ember.isPresent(errors)) {
if (isPresent(errors)) {
errors.forEach((error) => {
if (error.source && error.source.pointer) {
let key = error.source.pointer.match(SOURCE_POINTER_REGEXP);
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 6dcece6

Please sign in to comment.