Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

WIP ES6 lol

  • Loading branch information...
commit b1d7448be0c2aff866de6449749441fb7e1d4f98 1 parent 72dc74d
@fivetanley fivetanley authored fivetanley committed
Showing with 3,316 additions and 259 deletions.
  1. +66 −0 Gruntfile.js
  2. +7 −0 bower.json
  3. +7 −1 package.json
  4. +9 −2 packages/activemodel-adapter/lib/main.js
  5. +5 −1 packages/activemodel-adapter/lib/system.js
  6. +10 −6 packages/activemodel-adapter/lib/system/active_model_adapter.js
  7. +7 −5 packages/activemodel-adapter/lib/system/active_model_serializer.js
  8. +7 −3 packages/activemodel-adapter/lib/system/embedded_records_mixin.js
  9. +4 −2 packages/ember-data/lib/adapters.js
  10. +5 −4 packages/ember-data/lib/adapters/fixture_adapter.js
  11. +4 −6 packages/ember-data/lib/adapters/rest_adapter.js
  12. +2 −0  packages/ember-data/lib/core.js
  13. +0 −1  packages/ember-data/lib/ext.js
  14. +2 −3 packages/ember-data/lib/initializers.js
  15. +93 −12 packages/ember-data/lib/main.js
  16. +3 −1 packages/ember-data/lib/serializers/json_serializer.js
  17. +4 −3 packages/ember-data/lib/serializers/rest_serializer.js
  18. +6 −3 packages/ember-data/lib/system/adapter.js
  19. +22 −2 packages/ember-data/lib/system/changes.js
  20. +3 −1 packages/ember-data/lib/system/changes/attribute_change.js
  21. +58 −54 packages/ember-data/lib/system/changes/relationship_change.js
  22. +5 −2 packages/ember-data/lib/system/debug.js
  23. +6 −3 packages/ember-data/lib/system/debug/debug_adapter.js
  24. +4 −2 packages/ember-data/lib/system/debug/debug_info.js
  25. +5 −3 packages/ember-data/lib/system/model.js
  26. +5 −4 packages/ember-data/lib/system/model/attributes.js
  27. +7 −6 packages/ember-data/lib/system/model/model.js
  28. +1 −1  packages/ember-data/lib/system/model/states.js
  29. +5 −2 packages/ember-data/lib/system/record_array_manager.js
  30. +11 −4 packages/ember-data/lib/system/record_arrays.js
  31. +4 −3 packages/ember-data/lib/system/record_arrays/adapter_populated_record_array.js
  32. +4 −2 packages/ember-data/lib/system/record_arrays/filtered_record_array.js
  33. +7 −4 packages/ember-data/lib/system/record_arrays/many_array.js
  34. +5 −2 packages/ember-data/lib/system/record_arrays/record_array.js
  35. +6 −3 packages/ember-data/lib/system/relationships.js
  36. +6 −2 packages/ember-data/lib/system/relationships/belongs_to.js
  37. +6 −5 packages/ember-data/lib/system/relationships/ext.js
  38. +3 −3 packages/ember-data/lib/system/relationships/has_many.js
  39. +8 −7 packages/ember-data/lib/system/store.js
  40. +7 −0 packages/ember-data/lib/transforms.js
  41. +3 −1 packages/ember-data/lib/transforms/base.js
  42. +3 −1 packages/ember-data/lib/transforms/boolean.js
  43. +4 −1 packages/ember-data/lib/transforms/date.js
  44. +0 −5 packages/ember-data/lib/transforms/index.js
  45. +4 −1 packages/ember-data/lib/transforms/number.js
  46. +4 −1 packages/ember-data/lib/transforms/string.js
  47. +1 −1  packages/ember-data/tests/integration/application_test.js
  48. +3 −3 packages/ember-inflector/lib/ext/string.js
  49. +13 −1 packages/ember-inflector/lib/main.js
  50. +11 −5 packages/ember-inflector/lib/system.js
  51. +3 −1 packages/ember-inflector/lib/system/inflections.js
  52. +1 −1  packages/ember-inflector/lib/system/inflector.js
  53. +7 −4 packages/ember-inflector/lib/system/string.js
  54. +14 −0 tasks/browser.js
  55. +60 −0 tests/ember-data-setup.js
  56. +9 −65 tests/ember_configuration.js
  57. +21 −0 tests/index.html
  58. +217 −0 tests/qunit_configuration.js
  59. +244 −0 tests/vendor/qunit.css
  60. +2,212 −0 tests/vendor/qunit.js
  61. +53 −0 vendor/loader.js
View
66 Gruntfile.js
@@ -0,0 +1,66 @@
+var matchdep = require('matchdep');
+
+function nameFor(path) {
+ var result, match;
+ if (match = path.match(/^(?:lib|test|test\/tests)\/(.*?)(?:\.js)?$/)) {
+ result = match[1];
+ } else {
+ result = path;
+ }
+
+ return path;
+}
+module.exports = function(grunt){
+
+ matchdep.filterDev('grunt-*').forEach(grunt.loadNpmTasks);
+ grunt.loadTasks('tasks');
+
+ grunt.initConfig({
+ pkg: require('./package.json'),
+ clean: {
+ main: [ 'tmp/**/*' ]
+ },
+ transpile: {
+ amd: {
+ type: 'amd',
+ moduleName: nameFor,
+ files: [{
+ expand: true,
+ cwd: 'packages/',
+ src: [ '**/lib/**/*.js', ],
+ dest: 'tmp',
+ ext: '.amd.js'
+ }]
+ }
+ },
+ concat: {
+ amd: {
+ src: [ 'tmp/**/*.amd.js' ],
+ dest: 'tmp/ember-data.amd.js'
+ },
+ globals: {
+ src: [ 'vendor/loader.js', 'tmp/**/*.amd.js' ],
+ dest: 'tmp/ember-data.browser1.js'
+ },
+ tests: {
+ src: [ 'packages/**/tests/**/*.js' ],
+ dest: 'tmp/tests.js',
+ options: {
+ separator: ';\n',
+ process: function(src, filepath){
+ return "(function(){\n" + src + "\n})()";
+ }
+ }
+ }
+ },
+
+ browser: {
+ dist: {
+ src: 'tmp/ember-data.browser1.js',
+ dest: 'dist/ember-data.js'
+ }
+ }
+ });
+
+ grunt.registerTask('default', [ 'clean', 'transpile:amd', 'concat:globals', 'browser:dist', 'concat:tests' ]);
+};
View
7 bower.json
@@ -0,0 +1,7 @@
+{
+ "name": "ember-data",
+ "private": true,
+ "dependencies": {
+ "ember": "~1.2.0"
+ }
+}
View
8 package.json
@@ -1,6 +1,12 @@
{
+ "name": "ember-data",
+ "namespace": "DS",
"devDependencies": {
"defeatureify": "~0.1.4",
- "yuidocjs": "~0.3.46"
+ "yuidocjs": "~0.3.46",
+ "grunt-es6-module-transpiler": "~0.6.0",
+ "grunt": "~0.4.2",
+ "grunt-contrib-clean": "~0.5.0",
+ "grunt-contrib-concat": "~0.3.0"
}
}
View
11 packages/activemodel-adapter/lib/main.js
@@ -1,2 +1,9 @@
-require('activemodel-adapter/system');
-require('activemodel-adapter/initializers');
+import {ActiveModelAdapter, ActiveModelSerializer, EmbeddedRecordsMixin} from "./system";
+
+import "./initializers";
+
+export {
+ ActiveModelAdapter,
+ ActiveModelSerializer,
+ EmbeddedRecordsMixin
+};
View
6 packages/activemodel-adapter/lib/system.js
@@ -1 +1,5 @@
-require('activemodel-adapter/system/active_model_adapter');
+import EmbeddedRecordsMixin from "./system/embedded_records_mixin";
+import ActiveModelAdapter from "./system/active_model_adapter";
+import ActiveModelSerializer from "./system/active_model_serializer";
+
+export {EmbeddedRecordsMixin, ActiveModelAdapter, ActiveModelSerializer};
View
16 packages/activemodel-adapter/lib/system/active_model_adapter.js
@@ -1,6 +1,8 @@
-require('ember-data/adapters/rest_adapter');
-require('activemodel-adapter/system/active_model_serializer');
-require('activemodel-adapter/system/embedded_records_mixin');
+import {RESTAdapter} from "../../../ember-data/lib/adapters";
+import {InvalidError} from "../../../ember-data/lib/system/adapter";
+import {pluralize} from "../../../ember-inflector/lib/main";
+import ActiveModelSerializer from "./active_model_serializer";
+import EmbeddedRecordsMixin from "./embedded_records_mixin";
/**
@module ember-data
@@ -57,7 +59,7 @@ var forEach = Ember.EnumerableUtils.forEach;
@extends DS.Adapter
**/
-DS.ActiveModelAdapter = DS.RESTAdapter.extend({
+var ActiveModelAdapter = RESTAdapter.extend({
defaultSerializer: '_ams',
/**
The ActiveModelAdapter overrides the `pathForType` method to build
@@ -74,7 +76,7 @@ DS.ActiveModelAdapter = DS.RESTAdapter.extend({
*/
pathForType: function(type) {
var decamelized = Ember.String.decamelize(type);
- return Ember.String.pluralize(decamelized);
+ return pluralize(decamelized);
},
/**
@@ -104,9 +106,11 @@ DS.ActiveModelAdapter = DS.RESTAdapter.extend({
errors[Ember.String.camelize(key)] = jsonErrors[key];
});
- return new DS.InvalidError(errors);
+ return new InvalidError(errors);
} else {
return error;
}
}
});
+
+export default ActiveModelAdapter;
View
12 packages/activemodel-adapter/lib/system/active_model_serializer.js
@@ -1,5 +1,5 @@
-require('ember-data/serializers/rest_serializer');
-
+import {singularize} from "../../../ember-inflector/lib/system";
+import RESTSerializer from "../../../ember-data/lib/serializers/rest_serializer";
/**
@module ember-data
*/
@@ -7,7 +7,7 @@ require('ember-data/serializers/rest_serializer');
var get = Ember.get;
var forEach = Ember.EnumerableUtils.forEach;
-DS.ActiveModelSerializer = DS.RESTSerializer.extend({
+var ActiveModelSerializer = RESTSerializer.extend({
// SERIALIZE
/**
@@ -35,7 +35,7 @@ DS.ActiveModelSerializer = DS.RESTSerializer.extend({
if (kind === "belongsTo") {
return key + "_id";
} else if (kind === "hasMany") {
- return Ember.String.singularize(key) + "_ids";
+ return singularize(key) + "_ids";
} else {
return key;
}
@@ -86,7 +86,7 @@ DS.ActiveModelSerializer = DS.RESTSerializer.extend({
*/
typeForRoot: function(root) {
var camelized = Ember.String.camelize(root);
- return Ember.String.singularize(camelized);
+ return singularize(camelized);
},
/**
@@ -203,3 +203,5 @@ DS.ActiveModelSerializer = DS.RESTSerializer.extend({
}
}
});
+
+export default ActiveModelSerializer;
View
10 packages/activemodel-adapter/lib/system/embedded_records_mixin.js
@@ -1,6 +1,8 @@
var get = Ember.get;
var forEach = Ember.EnumerableUtils.forEach;
+import {pluralize} from "../../../ember-inflector/lib/main";
+
/**
The EmbeddedRecordsMixin allows you to add embedded record support to your
serializers.
@@ -20,7 +22,7 @@ var forEach = Ember.EnumerableUtils.forEach;
@class EmbeddedRecordsMixin
@namespace DS
*/
-DS.EmbeddedRecordsMixin = Ember.Mixin.create({
+var EmbeddedRecordsMixin = Ember.Mixin.create({
/**
Serialize has-may relationship when it is configured as embedded objects.
@@ -67,7 +69,7 @@ DS.EmbeddedRecordsMixin = Ember.Mixin.create({
*/
extractArray: function(store, type, payload) {
var root = this.keyForAttribute(type.typeKey),
- partials = payload[Ember.String.pluralize(root)];
+ partials = payload[pluralize(root)];
forEach(partials, function(partial) {
updatePayloadWithEmbedded(store, this, type, partial, payload);
@@ -119,4 +121,6 @@ function updatePayloadWithEmbedded(store, serializer, type, partial, payload) {
delete partial[attribute];
}
}, serializer);
-}
+}
+
+export default EmbeddedRecordsMixin;
View
6 packages/ember-data/lib/adapters.js
@@ -2,5 +2,7 @@
@module ember-data
*/
-require("ember-data/adapters/fixture_adapter");
-require("ember-data/adapters/rest_adapter");
+import FixtureAdapter from "./adapters/fixture_adapter";
+import RESTAdapter from "./adapters/rest_adapter";
+
+export {RESTAdapter, FixtureAdapter};
View
9 packages/ember-data/lib/adapters/fixture_adapter.js
@@ -1,6 +1,3 @@
-require("ember-data/core");
-require("ember-data/system/adapter");
-
/**
@module ember-data
*/
@@ -10,6 +7,8 @@ var get = Ember.get, fmt = Ember.String.fmt,
var counter = 0;
+import Adapter from "../system/adapter";
+
/**
`DS.FixtureAdapter` is an adapter that loads records from memory.
Its primarily used for development and testing. You can also use
@@ -27,7 +26,7 @@ var counter = 0;
@namespace DS
@extends DS.Adapter
*/
-DS.FixtureAdapter = DS.Adapter.extend({
+var FixtureAdapter = Adapter.extend({
// by default, fixtures are already in normalized form
serializer: null,
@@ -339,3 +338,5 @@ DS.FixtureAdapter = DS.Adapter.extend({
}, "DS: FixtureAdapter#simulateRemoteCall");
}
});
+
+export default FixtureAdapter;
View
10 packages/ember-data/lib/adapters/rest_adapter.js
@@ -1,12 +1,8 @@
-require("ember-data/core");
-require('ember-data/system/adapter');
-
-require('ember-data/serializers/rest_serializer');
-
/**
@module ember-data
*/
+import Adapter from "../system/adapter";
var get = Ember.get, set = Ember.set;
var forEach = Ember.ArrayPolyfills.forEach;
@@ -108,7 +104,7 @@ var forEach = Ember.ArrayPolyfills.forEach;
@namespace DS
@extends DS.Adapter
*/
-DS.RESTAdapter = DS.Adapter.extend({
+var RESTAdapter = Adapter.extend({
defaultSerializer: '_rest',
/**
@@ -549,3 +545,5 @@ DS.RESTAdapter = DS.Adapter.extend({
}
});
+
+export default RESTAdapter;
View
2  packages/ember-data/lib/core.js
@@ -28,3 +28,5 @@ if ('undefined' === typeof DS) {
Ember.libraries.registerCoreLibrary('Ember Data', DS.VERSION);
}
}
+
+export default DS;
View
1  packages/ember-data/lib/ext.js
@@ -1 +0,0 @@
-require('ember-data/ext/date');
View
5 packages/ember-data/lib/initializers.js
@@ -1,6 +1,5 @@
-require("ember-data/serializers/json_serializer");
-require("ember-data/system/debug/debug_adapter");
-require("ember-data/transforms/index");
+import JSONSerializer from "./serializers/json_serializer";
+import DebugAdapter from "./system/debug/debug_adapter";
/**
@module ember-data
View
105 packages/ember-data/lib/main.js
@@ -5,15 +5,96 @@
@main ember-data
*/
-require("ember-data/core");
-require("ember-data/initializers");
-require("ember-data/ext");
-require("ember-data/system/store");
-require("ember-data/system/model");
-require("ember-data/system/changes");
-require("ember-data/system/relationships");
-require("ember-data/system/record_arrays");
-require("ember-data/system/record_array_manager");
-require("ember-data/system/adapter");
-require("ember-data/adapters");
-require("ember-data/system/debug");
+import DS from "./core";
+import "./ext/date";
+
+import {Store, PromiseArray, PromiseObject} from "./system/store";
+import {Model, RootState, attr} from "./system/model";
+import {
+ AttributeChange,
+ RelationshipChange,
+ RelationshipChangeAdd,
+ RelationshipChangeRemove,
+ OneToManyChange,
+ ManyToNoneChange,
+ OneToOneChange,
+ ManyToManyChange
+} from "./system/changes";
+import {InvalidError, Adapter} from "./system/adapter";
+import DebugAdapter from "./system/debug";
+import {
+ RecordArray,
+ FilteredRecordArray,
+ AdapterPopulatedRecordArray,
+ ManyArray
+} from "./system/record_arrays";
+import RecordArrayManager from "./system/record_array_manager";
+import {RESTAdapter, FixtureAdapter} from "./adapters";
+import JSONSerializer from "./serializers/json_serializer";
+import RESTSerializer from "./serializers/rest_serializer";
+import "../../ember-inflector/lib/main";
+import {
+ ActiveModelAdapter,
+ ActiveModelSerializer,
+ EmbeddedRecordsMixin
+} from "../../activemodel-adapter/lib/main";
+
+import {
+ Transform,
+ DateTransform,
+ NumberTransform,
+ StringTransform,
+ BooleanTransform
+} from "./transforms";
+
+import {hasMany, belongsTo} from "./system/relationships";
+import "./initializers";
+
+DS.Store = Store;
+DS.PromiseArray = PromiseArray;
+DS.PromiseObject = PromiseObject;
+
+DS.Model = Model;
+DS.RootState = RootState;
+DS.attr = attr;
+
+DS.AttributeChange = AttributeChange;
+DS.RelationshipChange = RelationshipChange;
+DS.RelationshipChangeAdd = RelationshipChangeAdd;
+DS.OneToManyChange = OneToManyChange;
+DS.ManyToNoneChange = OneToManyChange;
+DS.OneToOneChange = OneToOneChange;
+DS.ManyToManyChange = ManyToManyChange;
+
+DS.Adapter = Adapter;
+DS.InvalidError = InvalidError;
+
+DS.DebugAdapter = DebugAdapter;
+
+DS.RecordArray = RecordArray;
+DS.FilteredRecordArray = FilteredRecordArray;
+DS.AdapterPopulatedRecordArray = AdapterPopulatedRecordArray;
+DS.ManyArray = ManyArray;
+
+DS.RecordArrayManager = RecordArrayManager;
+
+DS.RESTAdapter = RESTAdapter;
+DS.FixtureAdapter = FixtureAdapter;
+
+DS.RESTSerializer = RESTSerializer;
+DS.JSONSerializer = JSONSerializer;
+
+DS.Transform = Transform;
+DS.DateTransform = DateTransform;
+DS.StringTransform = StringTransform;
+DS.NumberTransform = NumberTransform;
+DS.BooleanTransform = BooleanTransform;
+
+DS.ActiveModelAdapter = ActiveModelAdapter;
+DS.ActiveModelSerializer = ActiveModelSerializer;
+DS.EmbeddedRecordsMixin = EmbeddedRecordsMixin;
+
+DS.belongsTo = belongsTo;
+DS.hasMany = hasMany;
+
+export default DS;
View
4 packages/ember-data/lib/serializers/json_serializer.js
@@ -23,7 +23,7 @@ function aliasMethod(methodName) {
@class JSONSerializer
@namespace DS
*/
-DS.JSONSerializer = Ember.Object.extend({
+var JSONSerializer = Ember.Object.extend({
/**
The primaryKey is used when serializing and deserializing
data. Ember Data always uses the `id` propery to store the id of
@@ -724,3 +724,5 @@ DS.JSONSerializer = Ember.Object.extend({
return transform;
}
});
+
+export default JSONSerializer;
View
7 packages/ember-data/lib/serializers/rest_serializer.js
@@ -1,9 +1,8 @@
-require('ember-data/serializers/json_serializer');
-
/**
@module ember-data
*/
+import JSONSerializer from "./json_serializer";
var get = Ember.get, set = Ember.set;
var forEach = Ember.ArrayPolyfills.forEach;
var map = Ember.ArrayPolyfills.map;
@@ -52,7 +51,7 @@ function coerceId(id) {
@namespace DS
@extends DS.JSONSerializer
*/
-DS.RESTSerializer = DS.JSONSerializer.extend({
+var RESTSerializer = JSONSerializer.extend({
/**
If you want to do normalizations specific to some part of the payload, you
can specify those under `normalizeHash`.
@@ -794,3 +793,5 @@ DS.RESTSerializer = DS.JSONSerializer.extend({
json[key + "Type"] = belongsTo.constructor.typeKey;
}
});
+
+export default RESTSerializer;
View
9 packages/ember-data/lib/system/adapter.js
@@ -36,7 +36,7 @@ var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'n
@class InvalidError
@namespace DS
*/
-DS.InvalidError = function(errors) {
+var InvalidError = function(errors) {
var tmp = Error.prototype.constructor.call(this, "The backend rejected the commit because it was invalid: " + Ember.inspect(errors));
this.errors = errors;
@@ -44,7 +44,7 @@ DS.InvalidError = function(errors) {
this[errorProps[i]] = tmp[errorProps[i]];
}
};
-DS.InvalidError.prototype = Ember.create(Error.prototype);
+InvalidError.prototype = Ember.create(Error.prototype);
/**
An adapter is an object that receives requests from a store and
@@ -97,7 +97,7 @@ DS.InvalidError.prototype = Ember.create(Error.prototype);
@extends Ember.Object
*/
-DS.Adapter = Ember.Object.extend({
+var Adapter = Ember.Object.extend({
/**
The `find()` method is invoked when the store is asked for a record that
@@ -421,3 +421,6 @@ DS.Adapter = Ember.Object.extend({
return Ember.RSVP.all(promises);
}
});
+
+export {InvalidError, Adapter};
+export default Adapter;
View
24 packages/ember-data/lib/system/changes.js
@@ -2,5 +2,25 @@
@module ember-data
*/
-require("ember-data/system/changes/attribute_change");
-require("ember-data/system/changes/relationship_change");
+import AttributeChange from "./changes/attribute_change";
+
+import {
+ RelationshipChange,
+ RelationshipChangeAdd,
+ RelationshipChangeRemove,
+ OneToManyChange,
+ ManyToNoneChange,
+ OneToOneChange,
+ ManyToManyChange
+} from "./changes/relationship_change";
+
+export {
+ AttributeChange,
+ RelationshipChange,
+ RelationshipChangeAdd,
+ RelationshipChangeRemove,
+ OneToManyChange,
+ ManyToNoneChange,
+ OneToOneChange,
+ ManyToManyChange
+};
View
4 packages/ember-data/lib/system/changes/attribute_change.js
@@ -12,7 +12,7 @@
@private
@constructor
*/
-var AttributeChange = DS.AttributeChange = function(options) {
+var AttributeChange = function(options) {
this.record = options.record;
this.store = options.store;
this.name = options.name;
@@ -46,3 +46,5 @@ AttributeChange.prototype = {
delete this.record._changesToSync[this.name];
}
};
+
+export default AttributeChange;
View
112 packages/ember-data/lib/system/changes/relationship_change.js
@@ -2,6 +2,8 @@
@module ember-data
*/
+import {Model} from "../model";
+
var get = Ember.get, set = Ember.set;
var forEach = Ember.EnumerableUtils.forEach;
@@ -11,7 +13,7 @@ var forEach = Ember.EnumerableUtils.forEach;
@private
@construtor
*/
-DS.RelationshipChange = function(options) {
+var RelationshipChange = function(options) {
this.parentRecord = options.parentRecord;
this.childRecord = options.childRecord;
this.firstRecord = options.firstRecord;
@@ -32,8 +34,8 @@ DS.RelationshipChange = function(options) {
@private
@construtor
*/
-DS.RelationshipChangeAdd = function(options){
- DS.RelationshipChange.call(this, options);
+var RelationshipChangeAdd = function(options){
+ RelationshipChange.call(this, options);
};
/**
@@ -42,39 +44,39 @@ DS.RelationshipChangeAdd = function(options){
@private
@construtor
*/
-DS.RelationshipChangeRemove = function(options){
- DS.RelationshipChange.call(this, options);
+var RelationshipChangeRemove = function(options){
+ RelationshipChange.call(this, options);
};
-DS.RelationshipChange.create = function(options) {
- return new DS.RelationshipChange(options);
+RelationshipChange.create = function(options) {
+ return new RelationshipChange(options);
};
-DS.RelationshipChangeAdd.create = function(options) {
- return new DS.RelationshipChangeAdd(options);
+RelationshipChangeAdd.create = function(options) {
+ return new RelationshipChangeAdd(options);
};
-DS.RelationshipChangeRemove.create = function(options) {
- return new DS.RelationshipChangeRemove(options);
+RelationshipChangeRemove.create = function(options) {
+ return new RelationshipChangeRemove(options);
};
-DS.OneToManyChange = {};
-DS.OneToNoneChange = {};
-DS.ManyToNoneChange = {};
-DS.OneToOneChange = {};
-DS.ManyToManyChange = {};
+var OneToManyChange = {};
+var OneToNoneChange = {};
+var ManyToNoneChange = {};
+var OneToOneChange = {};
+var ManyToManyChange = {};
-DS.RelationshipChange._createChange = function(options){
+RelationshipChange._createChange = function(options){
if(options.changeType === "add"){
- return DS.RelationshipChangeAdd.create(options);
+ return RelationshipChangeAdd.create(options);
}
if(options.changeType === "remove"){
- return DS.RelationshipChangeRemove.create(options);
+ return RelationshipChangeRemove.create(options);
}
};
-DS.RelationshipChange.determineRelationshipType = function(recordType, knownSide){
+RelationshipChange.determineRelationshipType = function(recordType, knownSide){
var knownKey = knownSide.key, key, otherKind;
var knownKind = knownSide.kind;
@@ -99,33 +101,33 @@ DS.RelationshipChange.determineRelationshipType = function(recordType, knownSide
};
-DS.RelationshipChange.createChange = function(firstRecord, secondRecord, store, options){
+RelationshipChange.createChange = function(firstRecord, secondRecord, store, options){
// Get the type of the child based on the child's client ID
var firstRecordType = firstRecord.constructor, changeType;
- changeType = DS.RelationshipChange.determineRelationshipType(firstRecordType, options);
+ changeType = RelationshipChange.determineRelationshipType(firstRecordType, options);
if (changeType === "oneToMany"){
- return DS.OneToManyChange.createChange(firstRecord, secondRecord, store, options);
+ return OneToManyChange.createChange(firstRecord, secondRecord, store, options);
}
else if (changeType === "manyToOne"){
- return DS.OneToManyChange.createChange(secondRecord, firstRecord, store, options);
+ return OneToManyChange.createChange(secondRecord, firstRecord, store, options);
}
else if (changeType === "oneToNone"){
- return DS.OneToNoneChange.createChange(firstRecord, secondRecord, store, options);
+ return OneToNoneChange.createChange(firstRecord, secondRecord, store, options);
}
else if (changeType === "manyToNone"){
- return DS.ManyToNoneChange.createChange(firstRecord, secondRecord, store, options);
+ return ManyToNoneChange.createChange(firstRecord, secondRecord, store, options);
}
else if (changeType === "oneToOne"){
- return DS.OneToOneChange.createChange(firstRecord, secondRecord, store, options);
+ return OneToOneChange.createChange(firstRecord, secondRecord, store, options);
}
else if (changeType === "manyToMany"){
- return DS.ManyToManyChange.createChange(firstRecord, secondRecord, store, options);
+ return ManyToManyChange.createChange(firstRecord, secondRecord, store, options);
}
};
-DS.OneToNoneChange.createChange = function(childRecord, parentRecord, store, options) {
+OneToNoneChange.createChange = function(childRecord, parentRecord, store, options) {
var key = options.key;
- var change = DS.RelationshipChange._createChange({
+ var change = RelationshipChange._createChange({
parentRecord: parentRecord,
childRecord: childRecord,
firstRecord: childRecord,
@@ -140,9 +142,9 @@ DS.OneToNoneChange.createChange = function(childRecord, parentRecord, store, opt
return change;
};
-DS.ManyToNoneChange.createChange = function(childRecord, parentRecord, store, options) {
+ManyToNoneChange.createChange = function(childRecord, parentRecord, store, options) {
var key = options.key;
- var change = DS.RelationshipChange._createChange({
+ var change = RelationshipChange._createChange({
parentRecord: childRecord,
childRecord: parentRecord,
secondRecord: childRecord,
@@ -157,14 +159,14 @@ DS.ManyToNoneChange.createChange = function(childRecord, parentRecord, store, op
};
-DS.ManyToManyChange.createChange = function(childRecord, parentRecord, store, options) {
+ManyToManyChange.createChange = function(childRecord, parentRecord, store, options) {
// If the name of the belongsTo side of the relationship is specified,
// use that
// If the type of the parent is specified, look it up on the child's type
// definition.
var key = options.key;
- var change = DS.RelationshipChange._createChange({
+ var change = RelationshipChange._createChange({
parentRecord: parentRecord,
childRecord: childRecord,
firstRecord: childRecord,
@@ -182,7 +184,7 @@ DS.ManyToManyChange.createChange = function(childRecord, parentRecord, store, op
return change;
};
-DS.OneToOneChange.createChange = function(childRecord, parentRecord, store, options) {
+OneToOneChange.createChange = function(childRecord, parentRecord, store, options) {
var key;
// If the name of the belongsTo side of the relationship is specified,
@@ -197,7 +199,7 @@ DS.OneToOneChange.createChange = function(childRecord, parentRecord, store, opti
Ember.assert("You must pass either a parentType or belongsToName option to OneToManyChange.forChildAndParent", false);
}
- var change = DS.RelationshipChange._createChange({
+ var change = RelationshipChange._createChange({
parentRecord: parentRecord,
childRecord: childRecord,
firstRecord: childRecord,
@@ -215,11 +217,11 @@ DS.OneToOneChange.createChange = function(childRecord, parentRecord, store, opti
return change;
};
-DS.OneToOneChange.maintainInvariant = function(options, store, childRecord, key){
+OneToOneChange.maintainInvariant = function(options, store, childRecord, key){
if (options.changeType === "add" && store.recordIsMaterialized(childRecord)) {
var oldParent = get(childRecord, key);
if (oldParent){
- var correspondingChange = DS.OneToOneChange.createChange(childRecord, oldParent, store, {
+ var correspondingChange = OneToOneChange.createChange(childRecord, oldParent, store, {
parentType: options.parentType,
hasManyName: options.hasManyName,
changeType: "remove",
@@ -231,7 +233,7 @@ DS.OneToOneChange.maintainInvariant = function(options, store, childRecord, key)
}
};
-DS.OneToManyChange.createChange = function(childRecord, parentRecord, store, options) {
+OneToManyChange.createChange = function(childRecord, parentRecord, store, options) {
var key;
// If the name of the belongsTo side of the relationship is specified,
@@ -240,14 +242,14 @@ DS.OneToManyChange.createChange = function(childRecord, parentRecord, store, opt
// definition.
if (options.parentType) {
key = options.parentType.inverseFor(options.key).name;
- DS.OneToManyChange.maintainInvariant( options, store, childRecord, key );
+ OneToManyChange.maintainInvariant( options, store, childRecord, key );
} else if (options.key) {
key = options.key;
} else {
Ember.assert("You must pass either a parentType or belongsToName option to OneToManyChange.forChildAndParent", false);
}
- var change = DS.RelationshipChange._createChange({
+ var change = RelationshipChange._createChange({
parentRecord: parentRecord,
childRecord: childRecord,
firstRecord: childRecord,
@@ -266,11 +268,11 @@ DS.OneToManyChange.createChange = function(childRecord, parentRecord, store, opt
};
-DS.OneToManyChange.maintainInvariant = function(options, store, childRecord, key){
+OneToManyChange.maintainInvariant = function(options, store, childRecord, key){
if (options.changeType === "add" && childRecord) {
var oldParent = get(childRecord, key);
if (oldParent){
- var correspondingChange = DS.OneToManyChange.createChange(childRecord, oldParent, store, {
+ var correspondingChange = OneToManyChange.createChange(childRecord, oldParent, store, {
parentType: options.parentType,
hasManyName: options.hasManyName,
changeType: "remove",
@@ -286,7 +288,7 @@ DS.OneToManyChange.maintainInvariant = function(options, store, childRecord, key
@class RelationshipChange
@namespace DS
*/
-DS.RelationshipChange.prototype = {
+RelationshipChange.prototype = {
getSecondRecordName: function() {
var name = this.secondRecordName, parent;
@@ -352,16 +354,16 @@ DS.RelationshipChange.prototype = {
}
};
-DS.RelationshipChangeAdd.prototype = Ember.create(DS.RelationshipChange.create({}));
-DS.RelationshipChangeRemove.prototype = Ember.create(DS.RelationshipChange.create({}));
+RelationshipChangeAdd.prototype = Ember.create(RelationshipChange.create({}));
+RelationshipChangeRemove.prototype = Ember.create(RelationshipChange.create({}));
// the object is a value, and not a promise
function isValue(object) {
return typeof object === 'object' && (!object.then || typeof object.then !== 'function');
}
-DS.RelationshipChangeAdd.prototype.changeType = "add";
-DS.RelationshipChangeAdd.prototype.sync = function() {
+RelationshipChangeAdd.prototype.changeType = "add";
+RelationshipChangeAdd.prototype.sync = function() {
var secondRecordName = this.getSecondRecordName(),
firstRecordName = this.getFirstRecordName(),
firstRecord = this.getFirstRecord(),
@@ -370,7 +372,7 @@ DS.RelationshipChangeAdd.prototype.sync = function() {
//Ember.assert("You specified a hasMany (" + hasManyName + ") on " + (!belongsToName && (newParent || oldParent || this.lastParent).constructor) + " but did not specify an inverse belongsTo on " + child.constructor, belongsToName);
//Ember.assert("You specified a belongsTo (" + belongsToName + ") on " + child.constructor + " but did not specify an inverse hasMany on " + (!hasManyName && (newParent || oldParent || this.lastParentRecord).constructor), hasManyName);
- if (secondRecord instanceof DS.Model && firstRecord instanceof DS.Model) {
+ if (secondRecord instanceof Model && firstRecord instanceof Model) {
if(this.secondRecordKind === "belongsTo"){
secondRecord.suspendRelationshipObservers(function(){
set(secondRecord, secondRecordName, firstRecord);
@@ -385,7 +387,7 @@ DS.RelationshipChangeAdd.prototype.sync = function() {
}
}
- if (firstRecord instanceof DS.Model && secondRecord instanceof DS.Model && get(firstRecord, firstRecordName) !== secondRecord) {
+ if (firstRecord instanceof Model && secondRecord instanceof Model && get(firstRecord, firstRecordName) !== secondRecord) {
if(this.firstRecordKind === "belongsTo"){
firstRecord.suspendRelationshipObservers(function(){
set(firstRecord, firstRecordName, secondRecord);
@@ -402,8 +404,8 @@ DS.RelationshipChangeAdd.prototype.sync = function() {
this.coalesce();
};
-DS.RelationshipChangeRemove.prototype.changeType = "remove";
-DS.RelationshipChangeRemove.prototype.sync = function() {
+RelationshipChangeRemove.prototype.changeType = "remove";
+RelationshipChangeRemove.prototype.sync = function() {
var secondRecordName = this.getSecondRecordName(),
firstRecordName = this.getFirstRecordName(),
firstRecord = this.getFirstRecord(),
@@ -412,7 +414,7 @@ DS.RelationshipChangeRemove.prototype.sync = function() {
//Ember.assert("You specified a hasMany (" + hasManyName + ") on " + (!belongsToName && (newParent || oldParent || this.lastParent).constructor) + " but did not specify an inverse belongsTo on " + child.constructor, belongsToName);
//Ember.assert("You specified a belongsTo (" + belongsToName + ") on " + child.constructor + " but did not specify an inverse hasMany on " + (!hasManyName && (newParent || oldParent || this.lastParentRecord).constructor), hasManyName);
- if (secondRecord instanceof DS.Model && firstRecord instanceof DS.Model) {
+ if (secondRecord instanceof Model && firstRecord instanceof Model) {
if(this.secondRecordKind === "belongsTo"){
secondRecord.suspendRelationshipObservers(function(){
set(secondRecord, secondRecordName, null);
@@ -426,7 +428,7 @@ DS.RelationshipChangeRemove.prototype.sync = function() {
}
}
- if (firstRecord instanceof DS.Model && get(firstRecord, firstRecordName)) {
+ if (firstRecord instanceof Model && get(firstRecord, firstRecordName)) {
if(this.firstRecordKind === "belongsTo"){
firstRecord.suspendRelationshipObservers(function(){
set(firstRecord, firstRecordName, null);
@@ -442,3 +444,5 @@ DS.RelationshipChangeRemove.prototype.sync = function() {
this.coalesce();
};
+
+export {RelationshipChange, RelationshipChangeAdd, RelationshipChangeRemove, OneToManyChange, ManyToNoneChange, OneToOneChange, ManyToManyChange};
View
7 packages/ember-data/lib/system/debug.js
@@ -1,5 +1,8 @@
/**
@module ember-data
*/
-require("ember-data/system/debug/debug_info");
-require("ember-data/system/debug/debug_adapter");
+
+import "./debug/debug_info";
+import DebugAdapter from "./debug/debug_adapter";
+
+export default DebugAdapter;
View
9 packages/ember-data/lib/system/debug/debug_adapter.js
@@ -1,7 +1,8 @@
/**
@module ember-data
*/
-var get = Ember.get, capitalize = Ember.String.capitalize, underscore = Ember.String.underscore, DS = window.DS ;
+import {Model} from "../model";
+var get = Ember.get, capitalize = Ember.String.capitalize, underscore = Ember.String.underscore;
/**
Extend `Ember.DataAdapter` with ED specific code.
@@ -11,7 +12,7 @@ var get = Ember.get, capitalize = Ember.String.capitalize, underscore = Ember.St
@extends Ember.DataAdapter
@private
*/
-DS.DebugAdapter = Ember.DataAdapter.extend({
+var DebugAdapter = Ember.DataAdapter.extend({
getFilters: function() {
return [
{ name: 'isNew', desc: 'New' },
@@ -21,7 +22,7 @@ DS.DebugAdapter = Ember.DataAdapter.extend({
},
detect: function(klass) {
- return klass !== DS.Model && DS.Model.detect(klass);
+ return klass !== Model && Model.detect(klass);
},
columnsForType: function(type) {
@@ -107,3 +108,5 @@ DS.DebugAdapter = Ember.DataAdapter.extend({
}
});
+
+export default DebugAdapter;
View
6 packages/ember-data/lib/system/debug/debug_info.js
@@ -1,6 +1,6 @@
-require("ember-data/system/model/model");
+import {Model} from "../model";
-DS.Model.reopen({
+Model.reopen({
/**
Provides info about the model for debugging purposes
@@ -66,3 +66,5 @@ DS.Model.reopen({
}
});
+
+export default Model;
View
8 packages/ember-data/lib/system/model.js
@@ -2,6 +2,8 @@
@module ember-data
*/
-require("ember-data/system/model/model");
-require("ember-data/system/model/states");
-require("ember-data/system/model/attributes");
+import Model from "./model/model";
+import attr from "./model/attributes";
+import RootState from "./model/states";
+
+export {Model, RootState, attr};
View
9 packages/ember-data/lib/system/model/attributes.js
@@ -1,4 +1,4 @@
-require("ember-data/system/model/model");
+import Model from "./model";
/**
@module ember-data
@@ -10,7 +10,7 @@ var get = Ember.get;
@class Model
@namespace DS
*/
-DS.Model.reopenClass({
+Model.reopenClass({
/**
A map whose keys are the attributes of the model (properties
described by DS.attr) and whose values are the meta object for the
@@ -198,7 +198,7 @@ DS.Model.reopenClass({
});
-DS.Model.reopen({
+Model.reopen({
eachAttribute: function(callback, binding) {
this.constructor.eachAttribute(callback, binding);
}
@@ -262,7 +262,7 @@ function getValue(record, key) {
@return {Attribute}
*/
-DS.attr = function(type, options) {
+var attr = function(type, options) {
options = options || {};
var meta = {
@@ -297,3 +297,4 @@ DS.attr = function(type, options) {
}).property('data').meta(meta);
};
+export default attr;
View
13 packages/ember-data/lib/system/model/model.js
@@ -1,5 +1,4 @@
-require("ember-data/system/model/states");
-
+import RootState from "./states";
/**
@module ember-data
*/
@@ -20,7 +19,7 @@ var retrieveFromCurrentState = Ember.computed('currentState', function(key, valu
@extends Ember.Object
@uses Ember.Evented
*/
-DS.Model = Ember.Object.extend(Ember.Evented, {
+var Model = Ember.Object.extend(Ember.Evented, {
/**
If this property is `true` the record is in the `empty`
state. Empty is the first state all records enter after they have
@@ -381,7 +380,7 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
_data: null,
init: function() {
- set(this, 'currentState', DS.RootState.empty);
+ set(this, 'currentState', RootState.empty);
this._super();
this._setup();
},
@@ -977,7 +976,7 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
}
});
-DS.Model.reopenClass({
+Model.reopenClass({
/**
Alias DS.Model's `create` method to `_create`. This allows us to create DS.Model
@@ -988,7 +987,7 @@ DS.Model.reopenClass({
@private
@static
*/
- _create: DS.Model.create,
+ _create: Model.create,
/**
Override the class' `create()` method to raise an error. This
@@ -1005,3 +1004,5 @@ DS.Model.reopenClass({
throw new Ember.Error("You should not call `create` on a model. Instead, call `store.createRecord` with the attributes you would like to set.");
}
});
+
+export default Model;
View
2  packages/ember-data/lib/system/model/states.js
@@ -703,4 +703,4 @@ function wireState(object, parent, name) {
RootState = wireState(RootState, null, "root");
-DS.RootState = RootState;
+export default RootState;
View
7 packages/ember-data/lib/system/record_array_manager.js
@@ -2,6 +2,7 @@
@module ember-data
*/
+import {ManyArray} from "./record_arrays";
var get = Ember.get, set = Ember.set;
var once = Ember.run.once;
var forEach = Ember.EnumerableUtils.forEach;
@@ -12,7 +13,7 @@ var forEach = Ember.EnumerableUtils.forEach;
@private
@extends Ember.Object
*/
-DS.RecordArrayManager = Ember.Object.extend({
+var RecordArrayManager = Ember.Object.extend({
init: function() {
this.filteredRecordArrays = Ember.MapWithDefault.create({
defaultValue: function() { return []; }
@@ -153,7 +154,7 @@ DS.RecordArrayManager = Ember.Object.extend({
@return {DS.ManyArray}
*/
createManyArray: function(type, records) {
- var manyArray = DS.ManyArray.create({
+ var manyArray = ManyArray.create({
type: type,
content: records,
store: this.store
@@ -196,3 +197,5 @@ DS.RecordArrayManager = Ember.Object.extend({
record._loadingRecordArrays = loadingRecordArrays;
}
});
+
+export default RecordArrayManager;
View
15 packages/ember-data/lib/system/record_arrays.js
@@ -2,7 +2,14 @@
@module ember-data
*/
-require('ember-data/system/record_arrays/record_array');
-require('ember-data/system/record_arrays/filtered_record_array');
-require('ember-data/system/record_arrays/adapter_populated_record_array');
-require('ember-data/system/record_arrays/many_array');
+import RecordArray from "./record_arrays/record_array";
+import FilteredRecordArray from "./record_arrays/filtered_record_array";
+import AdapterPopulatedRecordArray from "./record_arrays/adapter_populated_record_array";
+import ManyArray from "./record_arrays/many_array";
+
+export {
+ RecordArray,
+ FilteredRecordArray,
+ AdapterPopulatedRecordArray,
+ ManyArray
+};
View
7 packages/ember-data/lib/system/record_arrays/adapter_populated_record_array.js
@@ -1,5 +1,4 @@
-require("ember-data/system/record_arrays/record_array");
-
+import RecordArray from "./record_array";
/**
@module ember-data
*/
@@ -16,7 +15,7 @@ var get = Ember.get, set = Ember.set;
@namespace DS
@extends DS.RecordArray
*/
-DS.AdapterPopulatedRecordArray = DS.RecordArray.extend({
+var AdapterPopulatedRecordArray = RecordArray.extend({
query: null,
replace: function() {
@@ -45,3 +44,5 @@ DS.AdapterPopulatedRecordArray = DS.RecordArray.extend({
Ember.run.once(this, 'trigger', 'didLoad');
}
});
+
+export default AdapterPopulatedRecordArray;
View
6 packages/ember-data/lib/system/record_arrays/filtered_record_array.js
@@ -1,4 +1,4 @@
-require("ember-data/system/record_arrays/record_array");
+import RecordArray from "./record_array";
/**
@module ember-data
@@ -16,7 +16,7 @@ var get = Ember.get;
@namespace DS
@extends DS.RecordArray
*/
-DS.FilteredRecordArray = DS.RecordArray.extend({
+var FilteredRecordArray = RecordArray.extend({
/**
The filterFunction is a function used to test records from the store to
determine if they should be part of the record array.
@@ -60,3 +60,5 @@ DS.FilteredRecordArray = DS.RecordArray.extend({
manager.updateFilter(this, get(this, 'type'), get(this, 'filterFunction'));
}, 'filterFunction')
});
+
+export default FilteredRecordArray;
View
11 packages/ember-data/lib/system/record_arrays/many_array.js
@@ -1,4 +1,5 @@
-require("ember-data/system/record_arrays/record_array");
+import RecordArray from "./record_array";
+import {RelationshipChange} from "../changes";
/**
@module ember-data
@@ -43,7 +44,7 @@ var map = Ember.EnumerableUtils.map;
@namespace DS
@extends DS.RecordArray
*/
-DS.ManyArray = DS.RecordArray.extend({
+var ManyArray = RecordArray.extend({
init: function() {
this._super.apply(this, arguments);
this._changesToSync = Ember.OrderedSet.create();
@@ -153,7 +154,7 @@ DS.ManyArray = DS.RecordArray.extend({
for (var i=index; i<index+removed; i++) {
var record = get(this, 'content').objectAt(i);
- var change = DS.RelationshipChange.createChange(owner, record, get(this, 'store'), {
+ var change = RelationshipChange.createChange(owner, record, get(this, 'store'), {
parentType: owner.constructor,
changeType: "remove",
kind: "hasMany",
@@ -182,7 +183,7 @@ DS.ManyArray = DS.RecordArray.extend({
for (var i=index; i<index+added; i++) {
var record = get(this, 'content').objectAt(i);
- var change = DS.RelationshipChange.createChange(owner, record, store, {
+ var change = RelationshipChange.createChange(owner, record, store, {
parentType: owner.constructor,
changeType: "add",
kind:"hasMany",
@@ -229,3 +230,5 @@ DS.ManyArray = DS.RecordArray.extend({
}
});
+
+export default ManyArray;
View
7 packages/ember-data/lib/system/record_arrays/record_array.js
@@ -2,6 +2,7 @@
@module ember-data
*/
+import {PromiseArray} from "../store";
var get = Ember.get, set = Ember.set;
/**
@@ -17,7 +18,7 @@ var get = Ember.get, set = Ember.set;
@uses Ember.Evented
*/
-DS.RecordArray = Ember.ArrayProxy.extend(Ember.Evented, {
+var RecordArray = Ember.ArrayProxy.extend(Ember.Evented, {
/**
The model type contained by this record array.
@@ -160,6 +161,8 @@ DS.RecordArray = Ember.ArrayProxy.extend(Ember.Evented, {
return Ember.A(array);
}, null, "DS: RecordArray#save apply Ember.NativeArray");
- return DS.PromiseArray.create({ promise: promise });
+ return PromiseArray.create({ promise: promise });
}
});
+
+export default RecordArray;
View
9 packages/ember-data/lib/system/relationships.js
@@ -2,6 +2,9 @@
@module ember-data
*/
-require("ember-data/system/relationships/belongs_to");
-require("ember-data/system/relationships/has_many");
-require("ember-data/system/relationships/ext");
+import belongsTo from "./relationships/belongs_to";
+import hasMany from "./relationships/has_many";
+
+import "../system/relationships/ext";
+
+export {belongsTo, hasMany};
View
8 packages/ember-data/lib/system/relationships/belongs_to.js
@@ -1,6 +1,8 @@
var get = Ember.get, set = Ember.set,
isNone = Ember.isNone;
+import {Model} from "../model";
+
/**
@module ember-data
*/
@@ -79,7 +81,7 @@ function asyncBelongsTo(type, options, meta) {
@param {Object} options a hash of options
@return {Ember.computed} relationship
*/
-DS.belongsTo = function(type, options) {
+var belongsTo = function(type, options) {
if (typeof type === 'object') {
options = type;
type = undefined;
@@ -127,7 +129,7 @@ DS.belongsTo = function(type, options) {
@class Model
@namespace DS
*/
-DS.Model.reopen({
+Model.reopen({
/**
@method belongsToWillChange
@@ -172,3 +174,5 @@ DS.Model.reopen({
delete this._changesToSync[key];
})
});
+
+export default belongsTo;
View
11 packages/ember-data/lib/system/relationships/ext.js
@@ -1,4 +1,5 @@
-require("ember-inflector/system");
+import {singularize} from "../../../../ember-inflector/lib/system";
+import {Model} from "../model";
var get = Ember.get, set = Ember.set;
@@ -15,7 +16,7 @@ var get = Ember.get, set = Ember.set;
@class Model
@namespace DS
*/
-DS.Model.reopen({
+Model.reopen({
/**
This Ember.js hook allows an object to be notified when a property
@@ -79,7 +80,7 @@ DS.Model.reopen({
extensively.
*/
-DS.Model.reopenClass({
+Model.reopenClass({
/**
For a given relationship name, returns the model type of the relationship.
@@ -346,7 +347,7 @@ DS.Model.reopenClass({
type = meta.type;
if (!type && meta.kind === 'hasMany') {
- type = Ember.String.singularize(name);
+ type = singularize(name);
} else if (!type) {
type = name;
}
@@ -445,7 +446,7 @@ DS.Model.reopenClass({
}
});
-DS.Model.reopen({
+Model.reopen({
/**
Given a callback, iterates over each of the relationships in the model,
invoking the callback with the name of each relationship and its relationship
View
6 packages/ember-data/lib/system/relationships/has_many.js
@@ -1,5 +1,3 @@
-require("ember-data/system/model/model");
-
/**
@module ember-data
*/
@@ -148,10 +146,12 @@ function hasRelationship(type, options) {
@param {Object} options a hash of options
@return {Ember.computed} relationship
*/
-DS.hasMany = function(type, options) {
+var hasMany = function(type, options) {
if (typeof type === 'object') {
options = type;
type = undefined;
}
return hasRelationship(type, options);
};
+
+export default hasMany;
View
15 packages/ember-data/lib/system/store.js
@@ -1,8 +1,6 @@
/*globals Ember*/
/*jshint eqnull:true*/
-require("ember-data/system/record_arrays");
-
/**
@module ember-data
*/
@@ -15,6 +13,7 @@ var indexOf = Ember.EnumerableUtils.indexOf;
var map = Ember.EnumerableUtils.map;
var resolve = Ember.RSVP.resolve;
var copy = Ember.copy;
+var Store, PromiseObject, PromiseArray;
// Implementors Note:
//
@@ -87,7 +86,7 @@ var coerceId = function(id) {
@namespace DS
@extends Ember.Object
*/
-DS.Store = Ember.Object.extend({
+Store = Ember.Object.extend({
/**
@method init
@@ -1525,7 +1524,7 @@ function addUnsavedRecords(record, key, data) {
@extends Ember.ArrayProxy
@uses Ember.PromiseProxyMixin
*/
-DS.PromiseArray = Ember.ArrayProxy.extend(Ember.PromiseProxyMixin);
+PromiseArray = Ember.ArrayProxy.extend(Ember.PromiseProxyMixin);
/**
A `PromiseObject` is an object that acts like both an `Ember.Object`
and a promise. When the promise is resolved the the resulting value
@@ -1555,14 +1554,14 @@ DS.PromiseArray = Ember.ArrayProxy.extend(Ember.PromiseProxyMixin);
@extends Ember.ObjectProxy
@uses Ember.PromiseProxyMixin
*/
-DS.PromiseObject = Ember.ObjectProxy.extend(Ember.PromiseProxyMixin);
+PromiseObject = Ember.ObjectProxy.extend(Ember.PromiseProxyMixin);
function promiseObject(promise) {
- return DS.PromiseObject.create({ promise: promise });
+ return PromiseObject.create({ promise: promise });
}
function promiseArray(promise) {
- return DS.PromiseArray.create({ promise: promise });
+ return PromiseArray.create({ promise: promise });
}
function isThenable(object) {
@@ -1705,3 +1704,5 @@ function _commit(adapter, store, operation, record) {
throw reason;
}, "DS: Extract and notify about " + operation + " completion of " + record);
}
+
+export {Store, PromiseArray, PromiseObject};
View
7 packages/ember-data/lib/transforms.js
@@ -0,0 +1,7 @@
+import Transform from "./transforms/base";
+import NumberTransform from "./transforms/number";
+import DateTransform from "./transforms/date";
+import StringTransform from "./transforms/string";
+import BooleanTransform from "./transforms/boolean";
+
+export { Transform, NumberTransform, DateTransform, StringTransform, BooleanTransform };
View
4 packages/ember-data/lib/transforms/base.js
@@ -31,7 +31,7 @@
@class Transform
@namespace DS
*/
-DS.Transform = Ember.Object.extend({
+var Transform = Ember.Object.extend({
/**
When given a deserialized value from a record attribute this
method must return the serialized value.
@@ -69,3 +69,5 @@ DS.Transform = Ember.Object.extend({
deserialize: Ember.required()
});
+
+export default Transform;
View
4 packages/ember-data/lib/transforms/boolean.js
@@ -20,7 +20,8 @@
@extends DS.Transform
@namespace DS
*/
-DS.BooleanTransform = DS.Transform.extend({
+import Transform from "./base";
+var BooleanTransform = Transform.extend({
deserialize: function(serialized) {
var type = typeof serialized;
@@ -39,3 +40,4 @@ DS.BooleanTransform = DS.Transform.extend({
return Boolean(deserialized);
}
});
+export default BooleanTransform;
View
5 packages/ember-data/lib/transforms/date.js
@@ -17,7 +17,8 @@
@extends DS.Transform
@namespace DS
*/
-DS.DateTransform = DS.Transform.extend({
+import Transform from "./base";
+var DateTransform = Transform.extend({
deserialize: function(serialized) {
var type = typeof serialized;
@@ -65,3 +66,5 @@ DS.DateTransform = DS.Transform.extend({
}
});
+
+export default DateTransform;
View
5 packages/ember-data/lib/transforms/index.js
@@ -1,5 +0,0 @@
-require('ember-data/transforms/base');
-require('ember-data/transforms/boolean');
-require('ember-data/transforms/date');
-require('ember-data/transforms/number');
-require('ember-data/transforms/string');
View
5 packages/ember-data/lib/transforms/number.js
@@ -20,7 +20,8 @@ var empty = Ember.isEmpty;
@extends DS.Transform
@namespace DS
*/
-DS.NumberTransform = DS.Transform.extend({
+import Transform from "./base";
+var NumberTransform = Transform.extend({
deserialize: function(serialized) {
return empty(serialized) ? null : Number(serialized);
@@ -30,3 +31,5 @@ DS.NumberTransform = DS.Transform.extend({
return empty(deserialized) ? null : Number(deserialized);
}
});
+
+export default NumberTransform;
View
5 packages/ember-data/lib/transforms/string.js
@@ -21,7 +21,8 @@ var none = Ember.isNone;
@extends DS.Transform
@namespace DS
*/
-DS.StringTransform = DS.Transform.extend({
+import Transform from "./base";
+var StringTransform = Transform.extend({
deserialize: function(serialized) {
return none(serialized) ? null : String(serialized);
@@ -32,3 +33,5 @@ DS.StringTransform = DS.Transform.extend({
}
});
+
+export default StringTransform;
View
2  packages/ember-data/tests/integration/application_test.js
@@ -66,4 +66,4 @@ 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");
-});
+});
View
6 packages/ember-inflector/lib/ext/string.js
@@ -1,4 +1,4 @@
-require('ember-inflector/system/string');
+import {pluralize, singularize} from "../system/string";
if (Ember.EXTEND_PROTOTYPES === true || Ember.EXTEND_PROTOTYPES.String) {
/**
@@ -8,7 +8,7 @@ if (Ember.EXTEND_PROTOTYPES === true || Ember.EXTEND_PROTOTYPES.String) {
@for String
*/
String.prototype.pluralize = function() {
- return Ember.String.pluralize(this);
+ return pluralize(this);
};
/**
@@ -18,6 +18,6 @@ if (Ember.EXTEND_PROTOTYPES === true || Ember.EXTEND_PROTOTYPES.String) {
@for String
*/
String.prototype.singularize = function() {
- return Ember.String.singularize(this);
+ return singularize(this);
};
}
View
14 packages/ember-inflector/lib/main.js
@@ -1 +1,13 @@
-require('ember-inflector/system');
+import {Inflector, inflections, pluralize, singularize} from "./system";
+
+Inflector.defaultRules = inflections;
+Ember.Inflector = Inflector;
+
+Ember.String.pluralize = pluralize;
+Ember.String.singularize = singularize;
+
+import "./ext/string";
+
+export default Inflector;
+
+export {pluralize, singularize};
View
16 packages/ember-inflector/lib/system.js
@@ -1,6 +1,12 @@
-require('ember-inflector/system/string');
-require('ember-inflector/system/inflector');
-require('ember-inflector/system/inflections');
-require('ember-inflector/ext/string');
+import Inflector from "./system/inflector";
+import {pluralize, singularize} from "./system/string";
+import defaultRules from "./system/inflections";
-Ember.Inflector.inflector = new Ember.Inflector(Ember.Inflector.defaultRules);
+Inflector.inflector = new Inflector(defaultRules);
+
+export {
+ Inflector,
+ singularize,
+ pluralize,
+ defaultRules
+};
View
4 packages/ember-inflector/lib/system/inflections.js
@@ -1,4 +1,4 @@
-Ember.Inflector.defaultRules = {
+var defaultRules = {
plurals: [
[/$/, 's'],
[/s$/i, 's'],
@@ -76,3 +76,5 @@ Ember.Inflector.defaultRules = {
'police'
]
};
+
+export default defaultRules;
View
2  packages/ember-inflector/lib/system/inflector.js
@@ -196,4 +196,4 @@ Inflector.prototype = {
}
};
-Ember.Inflector = Inflector;
+export default Inflector;
View
11 packages/ember-inflector/lib/system/string.js
@@ -1,7 +1,10 @@
-Ember.String.pluralize = function(word) {
- return Ember.Inflector.inflector.pluralize(word);
+import Inflector from "./inflector";
+var pluralize = function(word) {
+ return Inflector.inflector.pluralize(word);
};
-Ember.String.singularize = function(word) {
- return Ember.Inflector.inflector.singularize(word);
+var singularize = function(word) {
+ return Inflector.inflector.singularize(word);
};
+
+export {pluralize, singularize};
View
14 tasks/browser.js
@@ -0,0 +1,14 @@
+module.exports = function(grunt) {
+ grunt.registerMultiTask('browser', 'Export the object in <%= pkg.name %> to the window', function() {
+ this.files.forEach(function(f) {
+ var output = ['(function(global) {'];
+
+ output.push.apply(output, f.src.map(grunt.file.read));
+
+ output.push("global.<%= pkg.namespace %> = requireModule('<%= pkg.name %>/lib/main')['default'];");
+ output.push('}(window));');
+
+ grunt.file.write(f.dest, grunt.template.process(output.join('\n')));
+ });
+ });
+};
View
60 tests/ember-data-setup.js
@@ -0,0 +1,60 @@
+;(function(){
+
+ Ember.RSVP.configure('onerror', function(reason) {
+ // only print error messages if they're exceptions;
+ // otherwise, let a future turn of the event loop
+ // handle the error.
+ if (reason && reason instanceof Error) {
+ Ember.Logger.log(reason, reason.stack)
+ throw reason;
+ }
+ });
+
+ Ember.RSVP.resolve = syncForTest(Ember.RSVP.resolve);
+
+ Ember.View.reopen({
+ _insertElementLater: syncForTest()
+ });
+
+ DS.Store.reopen({
+ save: syncForTest(),
+ createRecord: syncForTest(),
+ deleteRecord: syncForTest(),
+ push: syncForTest(),
+ pushMany: syncForTest(),
+ filter: syncForTest(),
+ find: syncForTest(),
+ findMany: syncForTest(),
+ findByIds: syncForTest(),
+ didSaveRecord: syncForTest(),
+ didSaveRecords: syncForTest(),
+ didUpdateAttribute: syncForTest(),
+ didUpdateAttributes: syncForTest(),
+ didUpdateRelationship: syncForTest(),
+ didUpdateRelationships: syncForTest()
+ });
+
+ DS.Model.reopen({
+ save: syncForTest(),
+ reload: syncForTest(),
+ deleteRecord: syncForTest(),
+ dataDidChange: Ember.observer(syncForTest(), 'data'),
+ updateRecordArraysLater: syncForTest()
+ });
+
+ var transforms = {
+ 'boolean': DS.BooleanTransform.create(),
+ 'date': DS.DateTransform.create(),
+ 'number': DS.NumberTransform.create(),
+ 'string': DS.StringTransform.create()
+ };
+
+ // Prevent all tests involving serialization to require a container
+ DS.JSONSerializer.reopen({
+ transformFor: function(attributeType) {
+ return this._super(attributeType, true) || transforms[attributeType];
+ }
+ });
+
+ Ember.RSVP.Promise.prototype.then = syncForTest(Ember.RSVP.Promise.prototype.then);
+})();
View
74 tests/ember_configuration.js
@@ -1,6 +1,7 @@
/*globals EmberDev ENV QUnit */
-(function() {
+(function RESET() {
+ console.log('RESETTING');
window.Ember = window.Ember || {};
Ember.config = {};
@@ -11,7 +12,7 @@
var extendPrototypes = QUnit.urlParams.extendprototypes;
ENV['EXTEND_PROTOTYPES'] = !!extendPrototypes;
- if (EmberDev.jsHint) {
+ if (typeof EmberDev !== 'undefined' && EmberDev.jsHint) {
// jsHint makes its own Object.create stub, we don't want to use this
ENV['STUB_OBJECT_CREATE'] = !Object.create;
}
@@ -84,7 +85,7 @@
return setupStore(options).store;
};
- var syncForTest = function(fn) {
+ var syncForTest = window.syncForTest = function(fn) {
var callSuper;
if (typeof fn !== "function") { callSuper = true; }
@@ -130,70 +131,13 @@
});
};
- minispade.register('ember-data/~test-setup', function() {
- Ember.RSVP.configure('onerror', function(reason) {
- // only print error messages if they're exceptions;
- // otherwise, let a future turn of the event loop
- // handle the error.
- if (reason && reason instanceof Error) {
- Ember.Logger.log(reason, reason.stack)
- throw reason;
- }
- });
-
- Ember.RSVP.resolve = syncForTest(Ember.RSVP.resolve);
-
- Ember.View.reopen({
- _insertElementLater: syncForTest()
- });
-
- DS.Store.reopen({
- save: syncForTest(),
- createRecord: syncForTest(),
- deleteRecord: syncForTest(),
- push: syncForTest(),
- pushMany: syncForTest(),
- filter: syncForTest(),
- find: syncForTest(),
- findMany: syncForTest(),
- findByIds: syncForTest(),
- didSaveRecord: syncForTest(),
- didSaveRecords: syncForTest(),
- didUpdateAttribute: syncForTest(),
- didUpdateAttributes: syncForTest(),
- didUpdateRelationship: syncForTest(),
- didUpdateRelationships: syncForTest()
- });
-
- DS.Model.reopen({
- save: syncForTest(),
- reload: syncForTest(),
- deleteRecord: syncForTest(),
- dataDidChange: Ember.observer(syncForTest(), 'data'),
- updateRecordArraysLater: syncForTest()
- });
- var transforms = {
- 'boolean': DS.BooleanTransform.create(),
- 'date': DS.DateTransform.create(),
- 'number': DS.NumberTransform.create(),
- 'string': DS.StringTransform.create()
+ if (typeof EmberDev !== 'undefined') {
+ EmberDev.distros = {
+ spade: 'ember-data-spade.js',
+ build: 'ember-data.js'
};
-
- // Prevent all tests involving serialization to require a container
- DS.JSONSerializer.reopen({
- transformFor: function(attributeType) {
- return this._super(attributeType, true) || transforms[attributeType];
- }
- });
-
- Ember.RSVP.Promise.prototype.then = syncForTest(Ember.RSVP.Promise.prototype.then);
- });
-
- EmberDev.distros = {
- spade: 'ember-data-spade.js',
- build: 'ember-data.js'
- };
+ }
// Generate the jQuery expando on window ahead of time
// to make the QUnit global check run clean
View
21 tests/index.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>QUnit Example</title>
+ <link rel="stylesheet" href="/tests/vendor/qunit.css">
+ </head>
+<body>
+ <div id="qunit"></div>
+ <div id="qunit-fixture"></div>
+ <script src="/bower_components/jquery/jquery.js"></script>
+ <script src="/bower_components/handlebars/handlebars.js"></script>
+ <script src="/tests/vendor/qunit.js"></script>
+ <script src="/tests/ember_configuration.js"></script>
+ <script src="http://builds.emberjs.com/canary/ember.js"></script>
+ <script src="/dist/ember-data.js"></script>
+ <script src="/tests/ember-data-setup.js"></script>
+ <script src="/tests/qunit_configuration.js"></script>
+ <script src="/tmp/tests.js"></script>
+</body>
+</html>
View
217 tests/qunit_configuration.js
@@ -0,0 +1,217 @@
+(function() {
+ window.EmberDev = window.EmberDev || {};
+
+ EmberDev.afterEach = function() {
+ if (Ember && Ember.View) {
+ var viewIds = [], id;
+ for (id in Ember.View.views) {
+ if (Ember.View.views[id] != null) {
+ viewIds.push(id);
+ }
+ }
+
+ if (viewIds.length > 0) {
+ deepEqual(viewIds, [], "Ember.View.views should be empty");
+ Ember.View.views = [];
+ }
+ }
+
+ if (Ember && Ember.TEMPLATES) {
+ var templateNames = [], name;
+ for (name in Ember.TEMPLATES) {
+ if (Ember.TEMPLATES[name] != null) {
+ templateNames.push(name);
+ }
+ }
+
+ if (templateNames.length > 0) {
+ deepEqual(templateNames, [], "Ember.TEMPLATES should be empty");
+ Ember.TEMPLATES = {};
+ }
+ }
+ };
+
+ window.globalFailedTests = [];
+ window.globalTestResults = null;
+ window.lastAssertionTime = new Date().getTime();
+
+ var currentTest, assertCount;
+
+ QUnit.testStart(function(data) {
+ // Reset the assertion count
+ assertCount = 0;
+
+ currentTest = {
+ name: data.name,
+ failedAssertions: [],
+ total: 0,
+ passed: 0,
+ failed: 0,
+ start: new Date(),
+ time: 0
+ };
+
+ })
+
+ QUnit.log(function(data) {
+ assertCount++;
+ lastAssertionTime = new Date().getTime();
+
+ // Ignore passing assertions
+ if (!data.result) {
+ currentTest.failedAssertions.push(data);
+ }
+ });
+
+ QUnit.testDone(function(data) {
+ currentTest.time = (new Date()).getTime() - currentTest.start.getTime(); // ms
+ currentTest.total = data.total;
+ currentTest.passed = data.passed;
+ currentTest.failed = data.failed;
+
+ if (currentTest.failed > 0)
+ window.globalFailedTests.push(currentTest)
+
+ currentTest = null;
+ });
+
+ QUnit.done(function( details ) {
+ details.failedTests = globalFailedTests;
+
+ window.globalTestResults = details;
+ });
+
+ // hack qunit to not suck for Ember objects
+ var originalTypeof = QUnit.jsDump.typeOf;
+
+ QUnit.jsDump.typeOf = function(obj) {
+ if (Ember && Ember.Object && Ember.Object.detectInstance(obj)) {
+ return "emberObject";
+ }
+
+ return originalTypeof.call(this, obj);
+ };
+
+ QUnit.jsDump.parsers.emberObject = function(obj) {
+ return obj.toString();
+ };
+
+ var originalModule = module;
+ module = function(name, origOpts) {
+ var opts = {};
+ if (origOpts && origOpts.setup) { opts.setup = origOpts.setup; }
+ opts.teardown = function() {
+ if (origOpts && origOpts.teardown) { origOpts.teardown(); }
+
+ if (Ember && Ember.run) {
+ if (Ember.run.currentRunLoop) {
+ ok(false, "Should not be in a run loop at end of test");
+ while (Ember.run.currentRunLoop) {
+ Ember.run.end();
+ }
+ }
+ if (Ember.run.hasScheduledTimers()) {
+ // Use `ok` so we get full description.
+ // Gate inside of `if` so that we don't mess up `expects` counts
+ ok(false, "Ember run should not have scheduled timers at end of test");
+ Ember.run.cancelTimers();
+ }
+ }
+
+ if (EmberDev.afterEach) {
+ EmberDev.afterEach();
+ }
+ };
+ return originalModule(name, opts);
+ };
+
+ // Tests should time out after 5 seconds
+ QUnit.config.testTimeout = 5000;
+
+ // Handle JSHint
+ QUnit.config.urlConfig.push('nojshint');
+
+ EmberDev.jsHint = !QUnit.urlParams.nojshint;
+
+ EmberDev.jsHintReporter = function (file, errors) {
+ if (!errors) { return ''; }
+
+ var len = errors.length,
+ str = '',
+ error, idx;
+
+ if (len === 0) { return ''; }
+
+ for (idx=0; idx<len; idx++) {
+ error = errors[idx];
+ str += file + ': line ' + error.line + ', col ' +
+ error.character + ', ' + error.reason + '\n';
+ }
+
+ return str + "\n" + len + ' error' + ((len === 1) ? '' : 's');
+ };
+
+ // Add `expectAssertion` which replaces
+ // `raises` to detect uncatchable assertions
+ function expectAssertion(fn, expectedMessage) {
+ var originalAssert = Ember.assert,
+ actualMessage, actualTest,
+ arity, sawAssertion;
+