Skip to content

Commit d722f80

Browse files
committed
Fixes #223.
1 parent 2439185 commit d722f80

File tree

6 files changed

+43
-9
lines changed

6 files changed

+43
-9
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
##### 1.1.1 - xx October 2014
2+
3+
###### Backwards compatible bug fixes
4+
- #223 - need to update lastModified when an item is re-injected
5+
16
##### 1.1.0 - 30 October 2014
27

38
###### Backwards compatible API changes

dist/angular-data.js

+4
Original file line numberDiff line numberDiff line change
@@ -6445,6 +6445,7 @@ function _inject(definition, resource, attrs, options) {
64456445
definition.beforeInject(definition.name, attrs);
64466446
var id = attrs[idA];
64476447
var item = DS.get(definition.name, id);
6448+
var initialLastModified = item ? resource.modified[id] : 0;
64486449

64496450
if (!item) {
64506451
if (options.useClass) {
@@ -6493,6 +6494,7 @@ function _inject(definition, resource, attrs, options) {
64936494
resource.observers[id].deliver();
64946495
}
64956496
resource.saved[id] = DS.utils.updateTimestamp(resource.saved[id]);
6497+
resource.modified[id] = initialLastModified && resource.modified[id] === initialLastModified ? DS.utils.updateTimestamp(resource.modified[id]) : resource.modified[id];
64966498
definition.afterInject(definition.name, item);
64976499
injected = item;
64986500
} catch (err) {
@@ -6598,9 +6600,11 @@ function inject(resourceName, attrs, options) {
65986600
if (!DS.$rootScope.$$phase) {
65996601
DS.$rootScope.$apply(function () {
66006602
injected = _inject.call(DS, definition, resource, attrs, options);
6603+
resource.collectionModified = DS.utils.updateTimestamp(resource.collectionModified);
66016604
});
66026605
} else {
66036606
injected = _inject.call(DS, definition, resource, attrs, options);
6607+
resource.collectionModified = DS.utils.updateTimestamp(resource.collectionModified);
66046608
}
66056609

66066610
if (options.linkInverse) {

dist/angular-data.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/datastore/sync_methods/inject.js

+4
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ function _inject(definition, resource, attrs, options) {
116116
definition.beforeInject(definition.name, attrs);
117117
var id = attrs[idA];
118118
var item = DS.get(definition.name, id);
119+
var initialLastModified = item ? resource.modified[id] : 0;
119120

120121
if (!item) {
121122
if (options.useClass) {
@@ -164,6 +165,7 @@ function _inject(definition, resource, attrs, options) {
164165
resource.observers[id].deliver();
165166
}
166167
resource.saved[id] = DS.utils.updateTimestamp(resource.saved[id]);
168+
resource.modified[id] = initialLastModified && resource.modified[id] === initialLastModified ? DS.utils.updateTimestamp(resource.modified[id]) : resource.modified[id];
167169
definition.afterInject(definition.name, item);
168170
injected = item;
169171
} catch (err) {
@@ -269,9 +271,11 @@ function inject(resourceName, attrs, options) {
269271
if (!DS.$rootScope.$$phase) {
270272
DS.$rootScope.$apply(function () {
271273
injected = _inject.call(DS, definition, resource, attrs, options);
274+
resource.collectionModified = DS.utils.updateTimestamp(resource.collectionModified);
272275
});
273276
} else {
274277
injected = _inject.call(DS, definition, resource, attrs, options);
278+
resource.collectionModified = DS.utils.updateTimestamp(resource.collectionModified);
275279
}
276280

277281
if (options.linkInverse) {

test/integration/datastore/sync_methods/changeHistory.test.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ describe('DS.changeHistory(resourceName, id)', function () {
2222
assert.isUndefined(DS.changeHistory('post', 5));
2323
});
2424
it('should return the changeHistory in an object', function (done) {
25-
DS.inject('post', p1);
25+
Post.inject(p1);
2626

27-
var initialModified = DS.store['post'].modified[5];
27+
var initialModified = Post.lastModified(5);
2828
assert.deepEqual(DS.changeHistory('post', 5), [
29-
{resourceName: 'post', added: {}, changed: {}, removed: {}, timestamp: initialModified, target: DS.get('post', 5)}
29+
{resourceName: 'post', added: {}, changed: {}, removed: {}, timestamp: Post.lastModified(5), target: DS.get('post', 5)}
3030
]);
3131

3232
var post = DS.get('post', 5);
@@ -42,11 +42,11 @@ describe('DS.changeHistory(resourceName, id)', function () {
4242
{resourceName: 'post', added: {}, changed: { author: 'Jake' }, removed: {}, timestamp: DS.store['post'].modified[5], target: DS.get('post', 5)}
4343
]);
4444

45-
DS.inject('post', p1);
4645

47-
initialModified = DS.store['post'].modified[5];
46+
DS.inject('post', p1);
47+
initialModified = Post.lastModified(5);
4848
assert.deepEqual(DS.changeHistory('post', 5), [
49-
{resourceName: 'post', added: {}, changed: { author: 'John' }, removed: {}, timestamp: initialModified, target: DS.get('post', 5)}
49+
{resourceName: 'post', added: {}, changed: { author: 'John' }, removed: {}, timestamp: Post.lastModified(5), target: DS.get('post', 5)}
5050
]);
5151
var post = DS.get('post', 5);
5252
post.author = 'Johnny';
@@ -58,7 +58,7 @@ describe('DS.changeHistory(resourceName, id)', function () {
5858
DS.digest();
5959
assert.deepEqual(DS.changeHistory('post', 5), [
6060
{resourceName: 'post', added: {}, changed: { author: 'John' }, removed: {}, timestamp: initialModified, target: DS.get('post', 5)},
61-
{resourceName: 'post', added: {}, changed: { author: 'Johnny' }, removed: {}, timestamp: DS.store['post'].modified[5], target: DS.get('post', 5)}
61+
{resourceName: 'post', added: {}, changed: { author: 'Johnny' }, removed: {}, timestamp: Post.lastModified(5), target: DS.get('post', 5)}
6262
]);
6363
done();
6464
} catch (err) {

test/integration/datastore/sync_methods/lastModified.test.js

+21
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,27 @@ describe('DS.lastModified(resourceName[, id])', function () {
8787
}
8888
}, 100);
8989
});
90+
it('should update the lastModified timestamp of an item when the item is re-injected', function (done) {
91+
92+
var Thing = DS.defineResource('thing');
93+
94+
var thing = Thing.inject({ id: 1, foo: 'bar', bing: { boom: 'bam' } });
95+
var time = Thing.lastModified(1);
96+
97+
Thing.inject(thing);
98+
if (typeof Object.observe !== 'function') {
99+
Thing.digest();
100+
}
101+
setTimeout(function () {
102+
try {
103+
assert.notEqual(time, Thing.lastModified(1));
104+
done();
105+
} catch (e) {
106+
console.log(e.stack);
107+
done(e);
108+
}
109+
}, 100);
110+
});
90111
// it('should lastModified an item into the store', function (done) {
91112
//
92113
// assert.equal(DS.lastModified('post', 5), 0);

0 commit comments

Comments
 (0)