File tree 1 file changed +17
-4
lines changed
1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change 18
18
*/
19
19
20
20
class Context {
21
- constructor ( values ) {
22
- for ( const k in values ) this [ k ] = values [ k ] ;
21
+ constructor ( values = { } ) {
22
+ const descs = Object . getOwnPropertyDescriptors ( values ) ;
23
+ for ( const k in descs ) {
24
+ Object . defineProperty ( this , k , descs [ k ] ) ;
25
+ }
26
+ }
27
+ follow ( source , keys ) {
28
+ const values = { } ;
29
+ for ( const k of keys ) {
30
+ Object . defineProperty ( values , k , {
31
+ get : ( ) => source [ k ]
32
+ } ) ;
33
+ }
34
+ return this . sub ( values ) ;
23
35
}
24
36
sub ( newValues ) {
25
37
if ( newValues === undefined ) newValues = { } ;
@@ -36,9 +48,10 @@ class Context {
36
48
}
37
49
}
38
50
39
- for ( const k in newValues ) {
51
+ const descs = Object . getOwnPropertyDescriptors ( newValues ) ;
52
+ for ( const k in descs ) {
40
53
if ( alreadyApplied [ k ] ) continue ;
41
- sub [ k ] = newValues [ k ] ;
54
+ Object . defineProperty ( sub , k , descs [ k ] ) ;
42
55
}
43
56
44
57
return sub ;
You can’t perform that action at this time.
0 commit comments