Skip to content

Commit 09217a6

Browse files
committed
Constructor functions for adding custom behavior are now named functions.
1 parent 4e85954 commit 09217a6

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

dist/angular-data.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,6 +2846,7 @@ function changes(resourceName, id) {
28462846
module.exports = changes;
28472847

28482848
},{}],44:[function(require,module,exports){
2849+
/*jshint evil:true*/
28492850
var errorPrefix = 'DS.defineResource(definition): ';
28502851

28512852
function Resource(utils, options) {
@@ -2955,9 +2956,10 @@ function defineResource(definition) {
29552956
});
29562957

29572958
if (def.methods) {
2958-
def.factory = function () {
2959-
};
2960-
this.utils.deepMixIn(def.factory.prototype, def.methods);
2959+
def.class = definition.name[0].toUpperCase() + definition.name.substring(1);
2960+
eval('function ' + def.class + '() {}');
2961+
def[def.class] = eval(def.class);
2962+
this.utils.deepMixIn(def[def.class].prototype, def.methods);
29612963
}
29622964

29632965
this.store[def.name] = {
@@ -3672,7 +3674,7 @@ function _inject(definition, resource, attrs) {
36723674
item = this.get(definition.name, id);
36733675

36743676
if (!item) {
3675-
item = definition.factory ? new definition.factory() : {};
3677+
item = definition.class ? new definition[definition.class]() : {};
36763678
resource.previousAttributes[id] = {};
36773679

36783680
_this.utils.deepMixIn(item, attrs);

dist/angular-data.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/datastore/sync_methods/defineResource.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/*jshint evil:true*/
12
var errorPrefix = 'DS.defineResource(definition): ';
23

34
function Resource(utils, options) {
@@ -107,9 +108,10 @@ function defineResource(definition) {
107108
});
108109

109110
if (def.methods) {
110-
def.factory = function () {
111-
};
112-
this.utils.deepMixIn(def.factory.prototype, def.methods);
111+
def.class = definition.name[0].toUpperCase() + definition.name.substring(1);
112+
eval('function ' + def.class + '() {}');
113+
def[def.class] = eval(def.class);
114+
this.utils.deepMixIn(def[def.class].prototype, def.methods);
113115
}
114116

115117
this.store[def.name] = {

src/datastore/sync_methods/inject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function _inject(definition, resource, attrs) {
3434
item = this.get(definition.name, id);
3535

3636
if (!item) {
37-
item = definition.factory ? new definition.factory() : {};
37+
item = definition.class ? new definition[definition.class]() : {};
3838
resource.previousAttributes[id] = {};
3939

4040
_this.utils.deepMixIn(item, attrs);

test/integration/datastore/sync_methods/defineResource.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ describe('DS.defineResource(definition)', function () {
107107
id: 1
108108
}));
109109
assert.equal(user.fullName(), 'John Anderson');
110-
assert.isTrue(user instanceof DS.definitions.user.factory);
110+
assert.isTrue(user instanceof DS.definitions.user[DS.definitions.user.class]);
111+
assert.equal(DS.definitions.user.class, 'User');
112+
assert.equal(DS.definitions.user[DS.definitions.user.class].name, 'User');
111113
assert.equal(lifecycle.beforeInject.callCount, 1, 'beforeInject should have been called');
112114
assert.equal(lifecycle.afterInject.callCount, 1, 'afterInject should have been called');
113115
});

0 commit comments

Comments
 (0)