
import { appLogger } from './logger';
import { isFunction, isUndefined } from 'lodash';

const _cacheFns = Symbol('cacheFns');

export default function createProxyObject(source, debugName) {
	return new Proxy({}, {
		get(_, name) {
			const proxy = new Proxy({}, {
				get(_, key) {
					const dist = source[name];
					if (isUndefined(dist)) {
						appLogger.error(`${debugName} "${name}" is undefined`);
						return {}; // avoid throw `undefined.sth()` like error
					}
					const result = dist[key];
					if (isFunction(result)) {
						if (!dist[_cacheFns]) {
							dist[_cacheFns] = {};
						}

						if (!dist[_cacheFns][key]) {
							dist[_cacheFns][key] = result.bind(dist);
						}

						return dist[_cacheFns][key];
					}
					else {
						return result;
					}
				},
			});
			return proxy;
		}
	});
}

@@ -44,20 +44,8 @@
 rt %7B
- isFunction,
  isU
@@ -75,47 +75,8 @@
 ';%0A%0A
-const _cacheFns = Symbol('cacheFns');%0A%0A
 expo
@@ -427,307 +427,25 @@
 %09%09%09%09
-const result = dist%5Bkey%5D;%0A%09%09%09%09%09if (isFunction(result)) %7B%0A%09%09%09%09%09%09if (!dist%5B_cacheFns%5D) %7B%0A%09%09%09%09%09%09%09dist%5B_cacheFns%5D = %7B%7D;%0A%09%09%09%09%09%09%7D%0A%0A%09%09%09%09%09%09if (!dist%5B_cacheFns%5D%5Bkey%5D) %7B%0A%09%09%09%09%09%09%09dist%5B_cacheFns%5D%5Bkey%5D = result.bind(dist);%0A%09%09%09%09%09%09%7D%0A%0A%09%09%09%09%09%09return dist%5B_cacheFns%5D%5Bkey%5D;%0A%09%09%09%09%09%7D%0A%09%09%09%09%09else %7B%0A%09%09%09%09%09%09return result;%0A%09%09%09%09%09%7D
+return dist%5Bkey%5D;
 %0A%09%09%09

fix models bug