@@ -36,28 +36,16 @@ define([
3636 this . dom . on ( 'change' , 'input,select' , submit ) ;
3737
3838 this . _values = new DataObject ( ) ;
39- this . template = Twig . twig ( {
40- data : this . module . getConfiguration ( 'template' )
41- } ) ;
42- } ,
43- blank : {
44- value : function ( ) {
45- this . getForm ( ) ;
46- this . dom . empty ( ) ;
47- } ,
48- tpl : function ( ) {
49- this . getForm ( ) ;
50- this . template = Twig . twig ( {
51- data : ''
52- } ) ;
53- } ,
54- form : function ( ) {
55-
56- } ,
5739
58- style : function ( ) {
59- this . getForm ( ) ;
40+ if ( ! this . renderPromise ) {
41+ this . renderPromise = Promise . resolve ( ) ;
6042 }
43+
44+ this . renderPromise . then ( ( ) => {
45+ this . template = Twig . twig ( {
46+ data : this . module . getConfiguration ( 'template' )
47+ } ) ;
48+ } ) ;
6149 } ,
6250 inDom : function ( ) {
6351 this . module . getDomContent ( ) . html ( this . dom ) ;
@@ -173,6 +161,28 @@ define([
173161 this . module . controller . onFormChanged ( out ) ;
174162 }
175163 } ,
164+ blank : {
165+ value : function ( ) {
166+ this . renderPromise = this . renderPromise . then ( ( ) => {
167+ this . getForm ( ) ;
168+ this . dom . empty ( ) ;
169+ } ) ;
170+ } ,
171+ tpl : function ( ) {
172+ this . renderPromise = this . renderPromise . then ( ( ) => {
173+ this . getForm ( ) ;
174+ this . template = Twig . twig ( {
175+ data : ''
176+ } ) ;
177+ } ) ;
178+
179+ } ,
180+ form : function ( ) {
181+ } ,
182+
183+ style : function ( ) {
184+ }
185+ } ,
176186 update : {
177187 value : function ( value , name ) {
178188 /*
@@ -185,14 +195,14 @@ define([
185195 } ,
186196 tpl : function ( value ) {
187197 var tpl = value . get ( ) . toString ( ) ;
188- try {
198+ this . renderPromise . then ( ( ) => {
189199 this . template = Twig . twig ( {
190200 data : tpl
191201 } ) ;
192202 this . rerender ( ) ;
193- } catch ( e ) {
203+ } ) . catch ( e => {
194204 Debug . info ( 'Problem with template: ' + e ) ;
195- }
205+ } ) ;
196206 } ,
197207
198208 form : function ( value ) {
@@ -219,13 +229,18 @@ define([
219229
220230 render : function ( cb ) {
221231 var that = this ;
222- var render = this . template . renderAsync ( this . _values ) ;
223- this . dom . html ( render . html ) ;
224- return render . render ( ) . then ( function ( ) {
225- if ( cb ) cb ( ) ;
226- that . setStyle ( ) ;
227- that . module . controller . onRendered ( that . dom . html ( ) ) ;
232+ this . renderPromise = this . renderPromise . then ( ( ) => {
233+ var render = this . template . renderAsync ( this . _values ) ;
234+ this . dom . html ( render . html ) ;
235+ return render . render ( ) . then ( function ( ) {
236+ if ( cb ) cb ( ) ;
237+ that . setStyle ( ) ;
238+ that . module . controller . onRendered ( that . dom . html ( ) ) ;
239+ } ) . catch ( e => {
240+ Debug . warn ( 'Error rendering twig template' , e ) ;
241+ } ) ;
228242 } ) ;
243+ return this . renderPromise ;
229244 }
230245 } ) ;
231246
0 commit comments