Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 21b47ae

Browse files
committed
fix: fork should deep clone objects
1 parent 818b1b4 commit 21b47ae

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

test/zone.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ describe('Zone', function () {
128128
expect(zone.mark).toBe('root');
129129
});
130130

131+
describe('fork', function () {
132+
it('should fork deep copy', function () {
133+
var protoZone = { too: { deep: true } },
134+
a = zone.fork(protoZone),
135+
b = zone.fork(protoZone);
136+
137+
expect(a.too).not.toBe(b.too);
138+
expect(a.too).toEqual(b.too);
139+
});
140+
});
141+
131142
});
132143

133144
function throwError () {

zone.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ function Zone(parentZone, data) {
3939

4040
// set the new zone's hook (replacing the parent zone's)
4141
} else {
42-
zone[property] = data[property];
42+
zone[property] = (typeof data[property] === 'object') ?
43+
JSON.parse(JSON.stringify(data[property])) :
44+
data[property];
4345
}
4446
});
4547

0 commit comments

Comments
 (0)