@@ -9,7 +9,6 @@ const componentDef = {
99 data : function ( ) {
1010 return {
1111 asyncTemplate : null ,
12- asyncTemplateDOMelement : null ,
1312 showing : true ,
1413 loading : false ,
1514 hideAfterTimeout : null ,
@@ -48,29 +47,6 @@ const componentDef = {
4847 self . rerender ( )
4948 } , parseInt ( this . componentConfig [ "defer" ] ) ) ;
5049 } ,
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- } ,
7450 rerender : function ( ) {
7551 var self = this ;
7652 self . loading = true ;
@@ -93,33 +69,16 @@ const componentDef = {
9369 self . asyncTemplate = template ;
9470 } )
9571 . catch ( function ( error ) {
72+ console . log ( error )
9673 matestackEventHub . $emit ( 'async_rerender_error' , { id : self . componentConfig [ "component_key" ] } )
9774 } )
9875 }
9976 } ,
10077 created : function ( ) {
101-
102- this . asyncTemplateDOMelement = document . querySelector ( "#" + this . componentConfig [ "id" ] )
103- this . asyncTemplate = this . asyncTemplateDOMelement . outerHTML ;
104-
10578 const self = this
106- if ( this . componentConfig [ "show_on" ] != undefined ) {
107- this . showing = false
108- var show_events = this . componentConfig [ "show_on" ] . split ( "," )
109- show_events . forEach ( show_event => matestackEventHub . $on ( show_event . trim ( ) , self . show ) ) ;
110- }
111- if ( this . componentConfig [ "hide_on" ] != undefined ) {
112- var hide_events = this . componentConfig [ "hide_on" ] . split ( "," )
113- hide_events . forEach ( hide_event => matestackEventHub . $on ( hide_event . trim ( ) , self . hide ) ) ;
114- }
115- if ( this . componentConfig [ "rerender_on" ] != undefined ) {
116- var rerender_events = this . componentConfig [ "rerender_on" ] . split ( "," )
117- rerender_events . forEach ( rerender_event => matestackEventHub . $on ( rerender_event . trim ( ) , self . rerender ) ) ;
118- }
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- }
79+ self . registerEvents ( this . componentConfig [ 'show_on' ] , self . show )
80+ self . registerEvents ( this . componentConfig [ 'hide_on' ] , self . hide )
81+ self . registerEvents ( this . componentConfig [ 'rerender_on' ] , self . rerender )
12382 if ( this . componentConfig [ "show_on" ] != undefined ) {
12483 this . showing = false
12584 }
@@ -137,21 +96,9 @@ const componentDef = {
13796 beforeDestroy : function ( ) {
13897 const self = this
13998 clearTimeout ( self . hideAfterTimeout )
140- matestackEventHub . $off ( this . componentConfig [ "rerender_on" ] , self . rerender ) ;
141- matestackEventHub . $off ( this . componentConfig [ "show_on" ] , self . show ) ;
142- matestackEventHub . $off ( this . componentConfig [ "hide_on" ] , self . hide ) ;
143- if ( this . componentConfig [ "show_on" ] != undefined ) {
144- var shown_events = this . componentConfig [ "show_on" ] . split ( "," )
145- shown_events . forEach ( show_event => matestackEventHub . $off ( show_event . trim ( ) , self . show ) ) ;
146- }
147- if ( this . componentConfig [ "hide_on" ] != undefined ) {
148- var hiden_events = this . componentConfig [ "hide_on" ] . split ( "," )
149- hiden_events . forEach ( hide_event => matestackEventHub . $off ( hide_event . trim ( ) , self . hide ) ) ;
150- }
151- if ( this . componentConfig [ "rerender_on" ] != undefined ) {
152- var rerender_events = this . componentConfig [ "rerender_on" ] . split ( "," )
153- rerender_events . forEach ( rerender_event => matestackEventHub . $off ( rerender_event . trim ( ) , self . rerender ) ) ;
154- }
99+ self . removeEvents ( this . componentConfig [ "show_on" ] , self . show )
100+ self . removeEvents ( this . componentConfig [ "hide_on" ] , self . hide )
101+ self . removeEvents ( this . componentConfig [ "rerender_on" ] , self . rerender )
155102 } ,
156103 components : {
157104 VRuntimeTemplate : VRuntimeTemplate
0 commit comments