dochub-sdk 0.1.266 → 0.1.267
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/helpers/proxy.ts +19 -0
- package/index.ts +3 -2
- package/package.json +1 -1
package/helpers/proxy.ts
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
export type DynamicProxyHandler = () => any;
|
2
|
+
/**
|
3
|
+
* Проксирует обращения к динамическому объекту в режиме "только для чтения"
|
4
|
+
* @param handler - Функция, которая должна возвращать реальный объект источник
|
5
|
+
* @returns
|
6
|
+
*/
|
7
|
+
export function dynamicProxy(handler: DynamicProxyHandler) {
|
8
|
+
const resolver = {
|
9
|
+
get(target, prop, receiver) {
|
10
|
+
const subject = handler();
|
11
|
+
if (!subject) throw new Error('Proxy subject is empty');
|
12
|
+
return handler()[prop];
|
13
|
+
},
|
14
|
+
set() {
|
15
|
+
throw new Error('Changing the proxy object is prohibited!');
|
16
|
+
}
|
17
|
+
};
|
18
|
+
return new Proxy({}, resolver);
|
19
|
+
}
|
package/index.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { IDocHubCore } from './interfaces/core';
|
2
|
+
import { dynamicProxy } from './helpers/proxy';
|
2
3
|
|
3
4
|
export * from './interfaces/core';
|
4
5
|
export * from './interfaces/contexts';
|
@@ -24,8 +25,8 @@ export * from './interfaces/datasets';
|
|
24
25
|
export * from './schemas/basetypes';
|
25
26
|
export * from './schemas/dochub-yaml';
|
26
27
|
|
27
|
-
export const DocHub: IDocHubCore = window['DocHub'];
|
28
|
+
export const DocHub: IDocHubCore = dynamicProxy(() => window['DocHub']);
|
28
29
|
export const Vue2 = () => window['Vue'];
|
29
30
|
export const Vuetify2 = () => window['Vuetify'];
|
30
31
|
|
31
|
-
|
32
|
+
|