2018-06-13 22:39:39 +03:00
|
|
|
'use strict';
|
|
|
|
|
2018-06-18 12:42:41 +03:00
|
|
|
export function defineReadOnly(object: any, name: string, value: any): void {
|
2018-06-13 22:39:39 +03:00
|
|
|
Object.defineProperty(object, name, {
|
|
|
|
enumerable: true,
|
|
|
|
value: value,
|
|
|
|
writable: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-18 12:42:41 +03:00
|
|
|
export function defineFrozen(object: any, name: string, value: any): void {
|
2018-06-13 22:39:39 +03:00
|
|
|
var frozen = JSON.stringify(value);
|
|
|
|
Object.defineProperty(object, name, {
|
|
|
|
enumerable: true,
|
|
|
|
get: function() { return JSON.parse(frozen); }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-18 12:42:41 +03:00
|
|
|
export function resolveProperties(object: any): Promise<any> {
|
2018-06-13 22:39:39 +03:00
|
|
|
let result: any = {};
|
|
|
|
|
2018-06-23 08:33:51 +03:00
|
|
|
let promises: Array<Promise<void>> = [];
|
2018-06-13 22:39:39 +03:00
|
|
|
Object.keys(object).forEach((key) => {
|
|
|
|
let value = object[key];
|
|
|
|
if (value instanceof Promise) {
|
|
|
|
promises.push(
|
2018-06-23 08:33:51 +03:00
|
|
|
value.then((value) => {
|
|
|
|
result[key] = value;
|
|
|
|
})
|
2018-06-13 22:39:39 +03:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
result[key] = value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return Promise.all(promises).then(() => {
|
2018-06-22 03:41:09 +03:00
|
|
|
return result;
|
2018-06-13 22:39:39 +03:00
|
|
|
});
|
|
|
|
}
|
2018-06-15 11:18:17 +03:00
|
|
|
|
|
|
|
export function shallowCopy(object: any): any {
|
2018-06-23 03:30:50 +03:00
|
|
|
let result: any = {};
|
2018-06-15 11:18:17 +03:00
|
|
|
for (var key in object) { result[key] = object[key]; }
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function jsonCopy(object: any): any {
|
|
|
|
return JSON.parse(JSON.stringify(object));
|
|
|
|
}
|