Skip to content

Commit 147c4f6

Browse files
committed
Initial relations experiments.
1 parent 8441406 commit 147c4f6

File tree

6 files changed

+392
-147
lines changed

6 files changed

+392
-147
lines changed

Gruntfile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ module.exports = function (grunt) {
9393
browsers: ['Chrome'],
9494
autoWatch: true,
9595
singleRun: false,
96+
reporters: ['spec'],
97+
preprocessors: {},
9698
exclude: [
9799
'test/integration/datastore/cacheFactory.test.js'
98100
]

dist/angular-data.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4545,8 +4545,8 @@ var observe = require('../../../lib/observe-js/observe-js'),
45454545
errorPrefix = 'DS.inject(resourceName, attrs[, options]): ';
45464546

45474547
function _inject(definition, resource, attrs) {
4548-
var _this = this,
4549-
$log = _this.$log;
4548+
var _this = this;
4549+
var $log = _this.$log;
45504550

45514551
function _react(added, removed, changed, getOldValueFn) {
45524552
try {
@@ -4624,6 +4624,21 @@ function _inject(definition, resource, attrs) {
46244624
return injected;
46254625
}
46264626

4627+
function _injectRelations(definition, injected) {
4628+
var _this = this;
4629+
_this.utils.forOwn(definition.relations, function (relation, type) {
4630+
_this.utils.forOwn(relation, function (def, relationName) {
4631+
if (_this.definitions[relationName] && injected[def.localField]) {
4632+
try {
4633+
injected[def.localField] = _this.inject(relationName, injected[def.localField]);
4634+
} catch (err) {
4635+
_this.$log.error(errorPrefix + 'Failed to inject ' + type + ' relation: "' + relationName + '"!', err);
4636+
}
4637+
}
4638+
});
4639+
});
4640+
}
4641+
46274642
/**
46284643
* @doc method
46294644
* @id DS.sync_methods:inject
@@ -4680,19 +4695,23 @@ function inject(resourceName, attrs, options) {
46804695
throw new this.errors.IllegalArgumentError(errorPrefix + 'options: Must be an object!', { options: { actual: typeof options, expected: 'object' } });
46814696
}
46824697

4683-
var definition = this.definitions[resourceName],
4684-
resource = this.store[resourceName],
4685-
_this = this;
4698+
var definition = this.definitions[resourceName];
4699+
var resource = this.store[resourceName];
4700+
var _this = this;
46864701

46874702
try {
46884703
var injected;
46894704
if (!this.$rootScope.$$phase) {
46904705
this.$rootScope.$apply(function () {
4691-
injected = _inject.apply(_this, [definition, resource, attrs]);
4706+
injected = _inject.call(_this, definition, resource, attrs);
46924707
});
46934708
} else {
4694-
injected = _inject.apply(_this, [definition, resource, attrs]);
4709+
injected = _inject.call(_this, definition, resource, attrs);
4710+
}
4711+
if (definition.relations) {
4712+
_injectRelations.call(_this, definition, injected);
46954713
}
4714+
46964715
return injected;
46974716
} catch (err) {
46984717
if (!(err instanceof this.errors.RuntimeError)) {

dist/angular-data.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)