Skip to content

Commit 4450015

Browse files
author
Vlad Balin
committed
assignFrom should sync changeToken in the scope of transaction
1 parent b2747c5 commit 4450015

File tree

8 files changed

+31
-22
lines changed

8 files changed

+31
-22
lines changed

dist/index.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.

dist/index.js.map

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

lib/transactions.js

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

lib/transactions.js.map

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "type-r",
3-
"version": "2.0.5",
3+
"version": "2.0.6",
44
"description": "Reactive serializable data layer for modern JS applications",
55
"main": "./dist/index.js",
66
"jsnext:main": "./lib/index.js",

src/transactions.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,17 @@ export abstract class Transactional implements Messenger, IONode, Validatable, T
180180

181181
// Assign transactional object "by value", copying aggregated items.
182182
assignFrom( source : Transactional | Object ) : this {
183-
this.set( ( <any>source ).__inner_state__ || source, { merge : true } );
183+
// Need to delay change events until change token willl by synced.
184+
this.transaction( () =>{
185+
this.set( ( <any>source ).__inner_state__ || source, { merge : true } );
184186

185-
// Synchronize change tokens
186-
const { _changeToken } = source as any;
187-
188-
if( _changeToken ){
189-
this._changeToken = _changeToken;
190-
}
187+
// Synchronize change tokens
188+
const { _changeToken } = source as any;
189+
190+
if( _changeToken ){
191+
this._changeToken = _changeToken;
192+
}
193+
});
191194

192195
return this;
193196
}

tests/typescript/dist/index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,11 +1033,14 @@ var Transactional = (function () {
10331033
return this;
10341034
};
10351035
Transactional.prototype.assignFrom = function (source) {
1036-
this.set(source.__inner_state__ || source, { merge: true });
1037-
var _changeToken = source._changeToken;
1038-
if (_changeToken) {
1039-
this._changeToken = _changeToken;
1040-
}
1036+
var _this = this;
1037+
this.transaction(function () {
1038+
_this.set(source.__inner_state__ || source, { merge: true });
1039+
var _changeToken = source._changeToken;
1040+
if (_changeToken) {
1041+
_this._changeToken = _changeToken;
1042+
}
1043+
});
10411044
return this;
10421045
};
10431046
Transactional.prototype.parse = function (data, options) { return data; };

tests/typescript/dist/index.js.map

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)