@@ -12,27 +12,22 @@ export default function createNodeFactory({ encode, decode }) {
1212 } = { } ) {
1313 const requests = { }
1414 let request_id_index = 0
15- const local_functions_id = { }
16- const local_functions = new Map ( )
15+ const local_rpcs_id = { }
16+ const local_rpcs = new Map ( )
1717 let local_function_index = 1 // 0 is reserved for the entry function used in open()
1818
1919 const encode_params = {
20- local_functions ,
21- registerLocalFunctionFromEncode ,
20+ local_rpcs ,
21+ registerLocalRpcFromEncode ,
2222 }
2323
24- function registerLocalFunction ( function_id , fn ) {
25- local_functions_id [ function_id ] = fn
26- local_functions . set ( fn , function_id )
24+ function registerLocalRpc ( function_id , fn ) {
25+ local_rpcs_id [ function_id ] = fn
26+ local_rpcs . set ( fn , function_id )
2727 return function_id
2828 }
2929
30- function createRemoteFunction ( {
31- function_id,
32- function_creator,
33- caller,
34- path,
35- } ) {
30+ function createRpc ( function_id ) {
3631 const makeCall = ( request_id , args ) => {
3732 const data = [ request_id , function_id ]
3833 if ( args . length > 0 ) data . push ( args )
@@ -62,8 +57,17 @@ export default function createNodeFactory({ encode, decode }) {
6257 makeCall ( 0 , args )
6358 }
6459
60+ return rpc
61+ }
62+
63+ function createRemoteFunction ( {
64+ function_id,
65+ function_creator,
66+ caller,
67+ path,
68+ } ) {
6569 return rpcFilter ( {
66- rpc,
70+ rpc : createRpc ( function_id ) ,
6771 node,
6872 function_id,
6973 function_creator,
@@ -73,15 +77,15 @@ export default function createNodeFactory({ encode, decode }) {
7377 }
7478
7579 function getNextLocalFunctionId ( ) {
76- while ( local_functions_id . hasOwnProperty ( local_function_index ) ) {
80+ while ( local_rpcs_id . hasOwnProperty ( local_function_index ) ) {
7781 local_function_index += 1
7882 }
7983 return local_function_index
8084 }
8185
8286 function open ( send , fn ) {
8387 const function_id = 0
84- if ( isFunction ( fn ) ) registerLocalFunction ( function_id , fn )
88+ if ( isFunction ( fn ) ) registerLocalRpc ( function_id , fn )
8589 node . send = ( msg ) => send ( serialize ( msg ) )
8690 return createRemoteFunction ( {
8791 function_id,
@@ -97,7 +101,7 @@ export default function createNodeFactory({ encode, decode }) {
97101
98102 const [ id , function_id ] = msg
99103 const is_request = id > - 1
100- const fn = is_request ? local_functions_id [ function_id ] : undefined
104+ const fn = is_request ? local_rpcs_id [ function_id ] : undefined
101105
102106 msg = decode ( msg , {
103107 createRemoteFunction,
@@ -152,8 +156,8 @@ export default function createNodeFactory({ encode, decode }) {
152156 return false
153157 }
154158
155- function registerLocalFunctionFromEncode ( fn ) {
156- return registerLocalFunction ( getNextLocalFunctionId ( ) , fn )
159+ function registerLocalRpcFromEncode ( fn ) {
160+ return registerLocalRpc ( getNextLocalFunctionId ( ) , fn )
157161 }
158162
159163 const node = {
0 commit comments