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 8, 2017
1 parent 0d0fbf9 commit 2bcdef4
Show file tree
Hide file tree
Showing 164 changed files with 2,191 additions and 1,134 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);
}
});
12 changes: 6 additions & 6 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 @@ -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
28 changes: 16 additions & 12 deletions addon/-private/system/model/errors.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import Ember from 'ember';
import { mapBy, not } from '@ember/object/computed';
import Evented from '@ember/object/evented';
import ArrayProxy from '@ember/array/proxy';
import { set, get, computed } from '@ember/object';
import { isEmpty } from '@ember/utils';
import { makeArray, A } from '@ember/array';
import MapWithDefault from '@ember/map/with-default';
import { deprecate, warn } from '@ember/debug';

const { get, set, isEmpty, makeArray, MapWithDefault } = Ember;

/**
@module ember-data
*/
Expand Down Expand Up @@ -82,7 +86,7 @@ const { get, set, isEmpty, makeArray, MapWithDefault } = Ember;
@uses Ember.Enumerable
@uses Ember.Evented
*/
export default Ember.ArrayProxy.extend(Ember.Evented, {
export default ArrayProxy.extend(Evented, {
/**
Register with target handler
Expand Down Expand Up @@ -120,10 +124,10 @@ export default Ember.ArrayProxy.extend(Ember.Evented, {
@type {Ember.MapWithDefault}
@private
*/
errorsByAttributeName: Ember.computed(function() {
errorsByAttributeName: computed(function() {
return MapWithDefault.create({
defaultValue() {
return Ember.A();
return A();
}
});
}),
Expand Down Expand Up @@ -165,15 +169,15 @@ export default Ember.ArrayProxy.extend(Ember.Evented, {
@property messages
@type {Array}
*/
messages: Ember.computed.mapBy('content', 'message'),
messages: mapBy('content', 'message'),

/**
@property content
@type {Array}
@private
*/
content: Ember.computed(function() {
return Ember.A();
content: computed(function() {
return A();
}),

/**
Expand All @@ -199,7 +203,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, {
@type {Boolean}
@readOnly
*/
isEmpty: Ember.computed.not('length').readOnly(),
isEmpty: not('length').readOnly(),

/**
Adds error messages to a given attribute and sends
Expand Down Expand Up @@ -382,7 +386,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, {
if (get(this, 'isEmpty')) { return; }

let errorsByAttributeName = get(this, 'errorsByAttributeName');
let attributes = Ember.A();
let attributes = A();

errorsByAttributeName.forEach(function(_, attribute) {
attributes.push(attribute);
Expand All @@ -393,7 +397,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, {
this.notifyPropertyChange(attribute);
}, this);

Ember.ArrayProxy.prototype.clear.call(this);
ArrayProxy.prototype.clear.call(this);
},


Expand Down
44 changes: 19 additions & 25 deletions addon/-private/system/model/internal-model.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { assign, merge } from '@ember/polyfills';
import { set, get } from '@ember/object';
import { copy } from '@ember/object/internals';
import EmberError from '@ember/error';
import { isEqual, isEmpty } from '@ember/utils';
import { setOwner } from '@ember/application';
import { run } from '@ember/runloop';
import RSVP, { Promise } from 'rsvp';
import Ember from 'ember';
import { DEBUG } from '@glimmer/env';
import { assert } from '@ember/debug';
import { assert, inspect } from '@ember/debug';
import RootState from "./states";
import Relationships from "../relationships/state/create";
import Snapshot from "../snapshot";
Expand All @@ -15,21 +23,7 @@ import {
HasManyReference
} from "../references";

const {
get,
set,
copy,
Error: EmberError,
inspect,
isEmpty,
isEqual,
setOwner,
run,
RSVP,
RSVP: { Promise }
} = Ember;

const assign = Ember.assign || Ember.merge;
const emberAssign = assign || merge;

/*
The TransitionChainMap caches the `state.enters`, `state.setups`, and final state reached
Expand Down Expand Up @@ -345,7 +339,7 @@ export default class InternalModel {
};

if (typeof properties === 'object' && properties !== null) {
assign(createOptions, properties);
emberAssign(createOptions, properties);
}

if (setOwner) {
Expand Down Expand Up @@ -497,10 +491,10 @@ export default class InternalModel {

if (this._scheduledDestroy === null) {
// TODO: use run.schedule once we drop 1.13
if (!Ember.run.currentRunLoop) {
if (!run.currentRunLoop) {
assert('You have turned on testing mode, which disabled the run-loop\'s autorun.\n You will need to wrap any code with asynchronous side-effects in a run', Ember.testing);
}
this._scheduledDestroy = Ember.run.backburner.schedule('destroy', this, '_checkForOrphanedInternalModels')
this._scheduledDestroy = run.backburner.schedule('destroy', this, '_checkForOrphanedInternalModels')
}
}

Expand Down Expand Up @@ -591,7 +585,7 @@ export default class InternalModel {
changedKeys = this._changedKeys(data.attributes);
}

assign(this._data, data.attributes);
emberAssign(this._data, data.attributes);
this.pushedData();

if (this.hasRecord) {
Expand Down Expand Up @@ -700,7 +694,7 @@ export default class InternalModel {
let oldData = this._data;
let currentData = this._attributes;
let inFlightData = this._inFlightAttributes;
let newData = assign(copy(inFlightData), currentData);
let newData = emberAssign(copy(inFlightData), currentData);
let diffData = Object.create(null);
let newDataKeys = Object.keys(newData);

Expand Down Expand Up @@ -1073,9 +1067,9 @@ export default class InternalModel {
this.didCleanError();
let changedKeys = this._changedKeys(data);

assign(this._data, this._inFlightAttributes);
emberAssign(this._data, this._inFlightAttributes);
if (data) {
assign(this._data, data);
emberAssign(this._data, data);
}

this._inFlightAttributes = null;
Expand Down Expand Up @@ -1203,8 +1197,8 @@ export default class InternalModel {
attrs= this._attributes;
}

original = assign(Object.create(null), this._data);
original = assign(original, this._inFlightAttributes);
original = emberAssign(Object.create(null), this._data);
original = emberAssign(original, this._inFlightAttributes);

for (i = 0; i < length; i++) {
key = keys[i];
Expand Down
Loading

0 comments on commit 2bcdef4

Please sign in to comment.