2020-08-06 23:39:05 +03:00
|
|
|
function mark(data, type, transformMethod) {
|
|
|
|
return {
|
|
|
|
data: transformMethod ? data[transformMethod]() : data,
|
2020-08-08 23:26:39 +03:00
|
|
|
__serializedType__: type,
|
2020-08-06 23:39:05 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function extract(data, type) {
|
|
|
|
return {
|
|
|
|
data: Object.assign({}, data),
|
2020-08-08 23:26:39 +03:00
|
|
|
__serializedType__: type,
|
2020-08-06 23:39:05 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function refer(data, type, isArray, refs) {
|
|
|
|
var r = mark(data, type, isArray);
|
|
|
|
if (!refs) return r;
|
|
|
|
for (var i = 0; i < refs.length; i++) {
|
|
|
|
var ref = refs[i];
|
|
|
|
if (typeof ref === 'function' && data instanceof ref) {
|
|
|
|
r.__serializedRef__ = i;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
mark: mark,
|
|
|
|
extract: extract,
|
2020-08-08 23:26:39 +03:00
|
|
|
refer: refer,
|
2020-08-06 23:39:05 +03:00
|
|
|
};
|