File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed
Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change 11'use strict' ;
22
33const start = ( data ) => {
4- console . log ( 'start transaction' ) ;
4+ console . log ( '\nstart transaction' ) ;
55 let delta = { } ;
6+ const commit = ( ) => {
7+ console . log ( '\ncommit transaction' ) ;
8+ Object . assign ( data , delta ) ;
9+ delta = { } ;
10+ } ;
611 return new Proxy ( data , {
712 get ( target , key ) {
8- if ( key === 'commit' ) {
9- return ( ) => {
10- console . log ( 'commit transaction' ) ;
11- Object . assign ( data , delta ) ;
12- delta = { } ;
13- } ;
14- }
13+ if ( key === 'commit' ) return commit ;
1514 if ( delta . hasOwnProperty ( key ) ) return delta [ key ] ;
1615 return target [ key ] ;
1716 } ,
@@ -26,7 +25,7 @@ const start = (data) => {
2625
2726// Usage
2827
29- const data = { name : 'Marcus Aurelius' , city : 'Rome' , born : 121 } ;
28+ const data = { name : 'Marcus Aurelius' , born : 121 } ;
3029
3130console . log ( 'data.name' , data . name ) ;
3231console . log ( 'data.born' , data . born ) ;
You can’t perform that action at this time.
0 commit comments