Skip to content

Commit 04e8606

Browse files
committed
fix: snapshot failing on constructor prop
1 parent 278e5d7 commit 04e8606

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/utils/helpers.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,17 @@ export const isSafari = Object.prototype.toString.call(window.HTMLElement).index
118118
|| (function (p) { return p.toString() === '[object SafariRemoteNotification]'; })(!window['safari']
119119
|| safari.pushNotification);
120120

121+
// works only for plain objects (JSON)
121122
export function snapshot(obj) {
122123
if(obj == undefined || typeof(obj) !== 'object') {
123124
return obj;
124125
}
125126

126-
var temp = new obj.constructor();
127+
if(obj instanceof Date) {
128+
return new Date(obj.getTime());
129+
}
130+
131+
var temp = Array.isArray(obj) ? [] : {};
127132

128133
for(var key in obj) {
129134
if (obj.hasOwnProperty(key)) {

0 commit comments

Comments
 (0)