@@ -9,6 +9,7 @@ const componentDef = {
99 data : function ( ) {
1010 return {
1111 asyncTemplate : null ,
12+ asyncTemplateDOMelement : null ,
1213 showing : true ,
1314 loading : false ,
1415 hideAfterTimeout : null ,
@@ -47,6 +48,29 @@ const componentDef = {
4748 self . rerender ( )
4849 } , parseInt ( this . componentConfig [ "defer" ] ) ) ;
4950 } ,
51+ update : function ( payload ) {
52+ let position = "beforeend"
53+
54+ if ( this . componentConfig [ "position" ] === "begin" ) {
55+ position = "afterbegin"
56+ }
57+ if ( this . componentConfig [ "position" ] === "end" ) {
58+ position = "beforeend"
59+ }
60+
61+ if ( payload . new_element != undefined ) {
62+ this . asyncTemplateDOMelement . insertAdjacentHTML (
63+ position ,
64+ payload . new_element
65+ )
66+ }
67+
68+ if ( payload . remove_element_by_id != undefined ) {
69+ this . asyncTemplateDOMelement . querySelector ( '#' + payload . remove_element_by_id ) . remove ( )
70+ }
71+
72+ this . asyncTemplate = this . asyncTemplateDOMelement . outerHTML
73+ } ,
5074 rerender : function ( ) {
5175 var self = this ;
5276 self . loading = true ;
@@ -69,12 +93,15 @@ const componentDef = {
6993 self . asyncTemplate = template ;
7094 } )
7195 . catch ( function ( error ) {
72- console . log ( error )
7396 matestackEventHub . $emit ( 'async_rerender_error' , { id : self . componentConfig [ "component_key" ] } )
7497 } )
7598 }
7699 } ,
77100 created : function ( ) {
101+
102+ this . asyncTemplateDOMelement = document . querySelector ( "#" + this . componentConfig [ "id" ] )
103+ this . asyncTemplate = this . asyncTemplateDOMelement . outerHTML ;
104+
78105 const self = this
79106 if ( this . componentConfig [ "show_on" ] != undefined ) {
80107 this . showing = false
@@ -89,6 +116,10 @@ const componentDef = {
89116 var rerender_events = this . componentConfig [ "rerender_on" ] . split ( "," )
90117 rerender_events . forEach ( rerender_event => matestackEventHub . $on ( rerender_event . trim ( ) , self . rerender ) ) ;
91118 }
119+ if ( this . componentConfig [ "update_on" ] != undefined ) {
120+ var update_events = this . componentConfig [ "update_on" ] . split ( "," )
121+ update_events . forEach ( update_event => matestackEventHub . $on ( update_event . trim ( ) , self . update ) ) ;
122+ }
92123 if ( this . componentConfig [ "show_on" ] != undefined ) {
93124 this . showing = false
94125 }
0 commit comments