deleight
Version:
A library with 9 modules for writing more expressive web applications with traditional HTML, CSS and JavaScript.
32 lines (31 loc) • 979 B
JavaScript
;
/**
* Exports a {@link scope} function which creates a proxy object from
* multiple objects so that they behave like they have been joined together
* with `Object.assign`. Hover the object created here does not allocate
* new memory to hold all the properties and it 'contains' both
* enumerable and the non-enumerable properties.
*
* @module
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.scope = void 0;
function scope(objects) {
return new Proxy({ objects }, handler);
}
exports.scope = scope;
const handler = {
get(target, p) {
for (let object of target.objects) {
if (Reflect.has(object, p))
return object[p];
}
},
ownKeys(target) {
const result = new Set();
for (let obj of target.objects)
for (let key of Reflect.ownKeys(obj))
result.add(typeof key === 'number' ? `${key}` : key);
return [...result];
}
};