@@ -4,8 +4,9 @@ import IPOSMessaging, {iposMessagingMessage, iposMessagingType} from './messagin
44import intercept from './intercept.js'
55
66export default class IPOS {
7- private readonly fields : Map < string , object >
8- private fieldsReverseMap : Map < object , string >
7+ private readonly fields : Map < string , ProxyHandler < any > >
8+ private readonly fieldsRaw : Map < string , any >
9+ private fieldsReverseMap : Map < ProxyHandler < any > , string >
910 private processMessagingMap : Map < ChildProcess , IPOSMessaging >
1011 private readonly proxy
1112 protected messaging ?: IPOSMessaging
@@ -24,6 +25,7 @@ export default class IPOS {
2425
2526 constructor ( ) {
2627 this . fields = new Map ( )
28+ this . fieldsRaw = new Map ( )
2729 this . fieldsReverseMap = new Map ( )
2830 this . processMessagingMap = new Map ( )
2931
@@ -72,16 +74,21 @@ export default class IPOS {
7274 return this . fields . get ( key )
7375 }
7476
77+ private getRaw ( key : string ) : any {
78+ return this . fields . get ( key )
79+ }
80+
7581 /******************** CREATE ********************/
7682 public create ( key : string , value : any ) : void {
7783 this . createStealthy ( key , value )
7884 this . sendToAll ( 'set' , { key, value} )
7985 }
8086
8187 protected createStealthy ( key : string , value : object ) : void {
88+ this . fieldsRaw . set ( key , value )
8289 if ( typeof value === 'object' )
83- value = intercept ( value , ( object , method , ...args ) =>
84- this . sendMethodCall ( object , method , ...args )
90+ value = intercept ( value , key , ( key , method , ...args ) =>
91+ this . sendMethodCall ( key , method , ...args )
8592 )
8693
8794 this . fields . set ( key , value )
@@ -96,13 +103,18 @@ export default class IPOS {
96103 /******************** UPDATE ********************/
97104 protected performUpdate ( message : iposMessagingMessage ) {
98105 if ( ! message . do || ! message . on ) return
99- this . get ( message . on ) [ message . do ] ( ...( message . with ?? [ ] ) )
106+ if ( message . do === '$$iposDefine' ) {
107+ if ( ! message . with ) return
108+ this . fieldsRaw . get ( message . on ) [ message . with [ 0 ] ] = message . with [ 1 ]
109+ } else {
110+ this . fieldsRaw . get ( message . on ) [ message . do ] ( ...( message . with ?? [ ] ) )
111+ }
100112 }
101113
102- private sendMethodCall ( object : object , method : string , ...args : any ) {
114+ private sendMethodCall ( key : string , method : string , ...args : any ) {
103115 this . sendToAll ( 'update' , {
104116 do : method ,
105- on : this . fieldsReverseMap . get ( object ) ,
117+ on : key ,
106118 with : Array . from ( args )
107119 } )
108120 }
0 commit comments