mirror of
https://github.com/HeyPuter/puter
synced 2024-11-15 06:15:47 +00:00
dev: clone property descriptors in Context
This commit is contained in:
parent
c2a475f3c0
commit
6e5d5c2021
@ -18,8 +18,20 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class Context {
|
class Context {
|
||||||
constructor (values) {
|
constructor (values = {}) {
|
||||||
for ( const k in values ) this[k] = values[k];
|
const descs = Object.getOwnPropertyDescriptors(values);
|
||||||
|
for ( const k in descs ) {
|
||||||
|
Object.defineProperty(this, k, descs[k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
follow (source, keys) {
|
||||||
|
const values = {};
|
||||||
|
for ( const k of keys ) {
|
||||||
|
Object.defineProperty(values, k, {
|
||||||
|
get: () => source[k]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return this.sub(values);
|
||||||
}
|
}
|
||||||
sub (newValues) {
|
sub (newValues) {
|
||||||
if ( newValues === undefined ) newValues = {};
|
if ( newValues === undefined ) newValues = {};
|
||||||
@ -36,9 +48,10 @@ class Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( const k in newValues ) {
|
const descs = Object.getOwnPropertyDescriptors(newValues);
|
||||||
|
for ( const k in descs ){
|
||||||
if ( alreadyApplied[k] ) continue;
|
if ( alreadyApplied[k] ) continue;
|
||||||
sub[k] = newValues[k];
|
Object.defineProperty(sub, k, descs[k]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sub;
|
return sub;
|
||||||
|
Loading…
Reference in New Issue
Block a user