@@ -29,10 +29,6 @@ const CoCreateApi = {
2929 if ( typeof this . modules [ name ] === 'undefined' ) {
3030 this . modules [ name ] = { name, endPoints, options } ;
3131
32- Socket . listen ( name , ( data ) => {
33- self . response ( name , data ) ;
34- } ) ;
35-
3632 Actions . init ( {
3733 name,
3834 callback : ( action ) => {
@@ -91,12 +87,13 @@ const CoCreateApi = {
9187 this . modules [ object . name ] [ object . method ] . request ( object )
9288 else if ( ! object . event && object . type === 'action' || object . event && object . event . includes ( object . type ) ) {
9389 let data = await CoCreateApi . getData ( object ) ;
94- CoCreateApi . send ( object . name , object . method , data ) ;
90+ CoCreateApi . send ( object , data ) ;
9591 }
9692 } ,
9793
98- response : function ( name , data ) {
99- const method = data . method . substring ( name . length + 1 ) ;
94+ response : function ( object , data ) {
95+ const name = object . name
96+ const method = object . method ;
10097 if ( this . modules [ name ] [ method ] && this . modules [ name ] [ method ] . response )
10198 this . modules [ name ] [ method ] . response ( data [ name ] )
10299 else if ( data . error ) {
@@ -110,7 +107,7 @@ const CoCreateApi = {
110107 } ]
111108 } ) ;
112109 } else {
113- CoCreateApi . setData ( { name , method , data } )
110+ CoCreateApi . setData ( object , data )
114111
115112 document . dispatchEvent ( new CustomEvent ( name , {
116113 detail : {
@@ -120,8 +117,9 @@ const CoCreateApi = {
120117 }
121118 } ,
122119
123- send : function ( name , method , data ) {
124- Socket . send ( { method : name + '.' + method , [ name ] : data , broadcast : false , broadcastBrowser : false , status : 'await' } ) ;
120+ send : async function ( object , data ) {
121+ data = await Socket . send ( { method : object . name + '.' + object . method , [ object . name ] : data , broadcast : false , broadcastBrowser : false , status : 'await' } ) ;
122+ this . response ( object , data ) ;
125123 } ,
126124
127125 getData : async function ( { name, method, element, form } ) {
@@ -171,11 +169,13 @@ const CoCreateApi = {
171169 return data
172170 } ,
173171
174- setData : function ( { name, method, data, form } ) {
172+ setData : function ( object , data ) {
173+ const name = object . name
174+ let form = object . form
175175 if ( ! form )
176176 form = document ;
177177
178- let elements = form . querySelectorAll ( `[${ name } ="${ method } "]` ) ;
178+ let elements = form . querySelectorAll ( `[${ name } ="${ object . method } "]` ) ;
179179 if ( ! elements || elements . length == 0 )
180180 return
181181
0 commit comments