Permalink
Browse files

Merge branch 'master' of https://github.com/emberjs/data into es6

Conflicts:
	packages/activemodel-adapter/lib/system/active_model_adapter.js
	packages/ember-data/lib/adapters/rest_adapter.js
	packages/ember-data/lib/initializers.js
	packages/ember-data/tests/integration/application_test.js
  • Loading branch information...
2 parents d977f34 + 58451d1 commit 63cd313d289fbfcd52f25d396a2f5ccbe8b4dfdb @fivetanley fivetanley committed Jan 23, 2014
View
@@ -30,7 +30,9 @@
"async",
"invokeAsync",
"jQuery",
- "expectAssertion"
+ "expectAssertion",
+ "expectDeprecation"
+
],
"node" : false,
View
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/emberjs/ember-dev.git
- revision: 87bc39887fdd1fb7332bebad0c91b57fedef059f
+ revision: 48ce37b50c2f59658ba70824a8b692bf9d690b9e
branch: master
specs:
ember-dev (0.1)
@@ -33,7 +33,7 @@ PATH
GEM
remote: https://rubygems.org/
specs:
- aws-sdk (1.31.3)
+ aws-sdk (1.32.0)
json (~> 1.4)
nokogiri (>= 1.4.4)
uuidtools (~> 2.1)
@@ -1,10 +1,18 @@
+require("ember-data/system/container_proxy");
+
Ember.onLoad('Ember.Application', function(Application) {
Application.initializer({
name: "activeModelAdapter",
initialize: function(container, application) {
- application.register('serializer:_ams', DS.ActiveModelSerializer);
- application.register('adapter:_ams', DS.ActiveModelAdapter);
+ var proxy = new DS.ContainerProxy(container);
+ proxy.registerDeprecations([
+ {deprecated: 'serializer:_ams', valid: 'serializer:-active-model'},
+ {deprecated: 'adapter:_ams', valid: 'adapter:-active-model'}
+ ]);
+
+ application.register('serializer:-active-model', DS.ActiveModelSerializer);
+ application.register('adapter:-active-model', DS.ActiveModelAdapter);
}
});
});
@@ -62,7 +62,7 @@ var decamelize = Ember.String.decamelize,
**/
var ActiveModelAdapter = RESTAdapter.extend({
- defaultSerializer: '_ams',
+ defaultSerializer: '-active-model',
/**
The ActiveModelAdapter overrides the `pathForType` method to build
underscored URLs by decamelizing and pluralizing the object type name.
@@ -105,9 +105,7 @@ var forEach = Ember.ArrayPolyfills.forEach;
@extends DS.Adapter
*/
var RESTAdapter = Adapter.extend({
- defaultSerializer: '_rest',
-
-
+ defaultSerializer: '-rest',
/**
Endpoint paths can be prefixed with a `namespace` by setting the namespace
property on the adapter:
@@ -1,5 +1,13 @@
-import JSONSerializer from "./serializers/json_serializer";
+import {JSONSerializer, RESTSerializer} from "./serializers";
+import {RESTAdapter} from "./adapters";
import DebugAdapter from "./system/debug/debug_adapter";
+import ContainerFactory from "./system/container_proxy";
+import {
+ BooleanTransform,
+ DateTransform,
+ StringTransform,
+ NumberTransform
+} from "./transforms";
/**
@module ember-data
@@ -43,9 +51,20 @@ Ember.onLoad('Ember.Application', function(Application) {
initialize: function(container, application) {
application.register('store:main', application.Store || DS.Store);
- application.register('serializer:_default', DS.JSONSerializer);
- application.register('serializer:_rest', DS.RESTSerializer);
- application.register('adapter:_rest', DS.RESTAdapter);
+
+ // allow older names to be looked up
+
+ var proxy = new ContainerProxy(container);
+ proxy.registerDeprecations([
+ {deprecated: 'serializer:_default', valid: 'serializer:-default'},
+ {deprecated: 'serializer:_rest', valid: 'serializer:-rest'},
+ {deprecated: 'adapter:_rest', valid: 'adapter:-rest'}
+ ]);
+
+ // new go forward paths
+ application.register('serializer:-default', JSONSerializer);
+ application.register('serializer:-rest', RESTSerializer);
+ application.register('adapter:-rest', RESTAdapter);
// Eagerly generate the store so defaultStore is populated.
// TODO: Do this in a finisher hook
@@ -70,7 +89,7 @@ Ember.onLoad('Ember.Application', function(Application) {
before: "store",
initialize: function(container, application) {
- application.register('data-adapter:main', DS.DebugAdapter);
+ application.register('data-adapter:main', DebugAdapter);
}
});
@@ -0,0 +1,48 @@
+/**
+ This is used internally to enable deprecation of container paths and provide
+ a decent message to the user indicating how to fix the issue.
+
+ @class ContainerProxy
+ @namespace DS
+ @private
+*/
+var ContainerProxy = function (container){
+ this.container = container;
+};
+
+ContainerProxy.prototype.aliasedFactory = function(path, preLookup) {
+ var _this = this;
+
+ return {create: function(){
+ if (preLookup) { preLookup(); }
+
+ return _this.container.lookup(path);
+ }};
+};
+
+ContainerProxy.prototype.registerAlias = function(source, dest, preLookup) {
+ var factory = this.aliasedFactory(dest, preLookup);
+
+ return this.container.register(source, factory);
+};
+
+ContainerProxy.prototype.registerDeprecation = function(deprecated, valid) {
+ var preLookupCallback = function(){
+ Ember.deprecate("You tried to look up '" + deprecated + "', " +
+ "but this has been deprecated in favor of '" + valid + "'.", false);
+ };
+
+ return this.registerAlias(deprecated, valid, preLookupCallback);
+};
+
+ContainerProxy.prototype.registerDeprecations = function(proxyPairs) {
+ for (var i = proxyPairs.length; i > 0; i--) {
+ var proxyPair = proxyPairs[i - 1],
+ deprecated = proxyPair['deprecated'],
+ valid = proxyPair['valid'];
+
+ this.registerDeprecation(deprecated, valid);
+ }
+};
+
+export default ContainerProxy;
@@ -777,7 +777,7 @@ var Model = Ember.Object.extend(Ember.Evented, {
},
/**
- If the model `isDirty` this function will which discard any unsaved
+ If the model `isDirty` this function will discard any unsaved
changes
Example
@@ -117,7 +117,7 @@ Store = Ember.Object.extend({
@default DS.RESTAdapter
@type {DS.Adapter|String}
*/
- adapter: '_rest',
+ adapter: '-rest',
/**
Returns a JSON representation of the record using a custom
@@ -158,7 +158,7 @@ Store = Ember.Object.extend({
Ember.assert('You tried to set `adapter` property to an instance of `DS.Adapter`, where it should be a name or a factory', !(adapter instanceof DS.Adapter));
if (typeof adapter === 'string') {
- adapter = this.container.lookup('adapter:' + adapter) || this.container.lookup('adapter:application') || this.container.lookup('adapter:_rest');
+ adapter = this.container.lookup('adapter:' + adapter) || this.container.lookup('adapter:application') || this.container.lookup('adapter:-rest');
}
if (DS.Adapter.detect(adapter)) {
@@ -788,7 +788,7 @@ Store = Ember.Object.extend({
}).then(function(unreadPosts) {
unreadPosts.get('length'); // 5
var unreadPost = unreadPosts.objectAt(0);
- unreadPosts.set('unread', false);
+ unreadPost.set('unread', false);
unreadPosts.get('length'); // 4
});
```
@@ -1547,12 +1547,12 @@ function serializerFor(container, type, defaultSerializer) {
return container.lookup('serializer:'+type) ||
container.lookup('serializer:application') ||
container.lookup('serializer:' + defaultSerializer) ||
- container.lookup('serializer:_default');
+ container.lookup('serializer:-default');
}
function defaultSerializer(container) {
return container.lookup('serializer:application') ||
- container.lookup('serializer:_default');
+ container.lookup('serializer:-default');
}
function serializerForAdapter(adapter, type) {
@@ -67,3 +67,31 @@ test("If a store is instantiated, it should be made available to each controller
test("the DS namespace should be accessible", function() {
ok(Ember.Namespace.byName('DS') instanceof Ember.Namespace, "the DS namespace is accessible");
});
+
+test("the deprecated serializer:_default is resolved as serializer:default", function(){
+ var deprecated = container.lookup('serializer:_default'),
+ valid = container.lookup('serializer:-default');
+
+ ok(deprecated === valid, "they should resolve to the same thing");
+});
+
+test("the deprecated serializer:_rest is resolved as serializer:rest", function(){
+ var deprecated = container.lookup('serializer:_rest'),
+ valid = container.lookup('serializer:-rest');
+
+ ok(deprecated === valid, "they should resolve to the same thing");
+});
+
+test("the deprecated adapter:_rest is resolved as adapter:rest", function(){
+ var deprecated = container.lookup('adapter:_rest'),
+ valid = container.lookup('adapter:-rest');
+
+ ok(deprecated === valid, "they should resolve to the same thing");
+});
+
+test("a deprecation is made when looking up adapter:_rest", function(){
+ expectDeprecation(function(){
+ container.lookup('serializer:_default');
+ },"You tried to look up 'serializer:_default', but this has been deprecated in favor of 'serializer:-default'.");
+});
+>>>>>>> 58451d1ca50d9ef88c4e397afccc6a0a79622645
@@ -18,7 +18,7 @@ test("Adapter can be set as a factory", function() {
});
test('Adapter can be set as a name', function() {
- store = createStore({adapter: '_rest'});
+ store = createStore({adapter: '-rest'});
ok(store.get('defaultAdapter') instanceof DS.RESTAdapter);
});
@@ -62,14 +62,14 @@
adapter: adapter
}));
- container.register('serializer:_default', DS.JSONSerializer);
- container.register('serializer:_rest', DS.RESTSerializer);
- container.register('adapter:_rest', DS.RESTAdapter);
+ container.register('serializer:-default', DS.JSONSerializer);
+ container.register('serializer:-rest', DS.RESTSerializer);
+ container.register('adapter:-rest', DS.RESTAdapter);
container.injection('serializer', 'store', 'store:main');
- env.serializer = container.lookup('serializer:_default');
- env.restSerializer = container.lookup('serializer:_rest');
+ env.serializer = container.lookup('serializer:-default');
+ env.restSerializer = container.lookup('serializer:-rest');
env.store = container.lookup('store:main');
env.adapter = env.store.get('defaultAdapter');

0 comments on commit 63cd313

Please sign in to comment.