You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: single-page-express.js
+21-8Lines changed: 21 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -392,6 +392,19 @@ function singlePageExpress (options) {
392
392
// app.render implements the express api on the surface, then prescribes some default behavior specific to this module, provides a default method for dom manipulation, and allows for a user to override the default dom manipulation behaviors
393
393
app.render=function(template,model,callback){
394
394
model=model||{}
395
+
396
+
// clear all `this` variables so they do not persist but store local copies for this method invocation's use
397
+
constthisTitle=this.title
398
+
constthisBeforeRender=this.beforeRender
399
+
constthisTarget=this.target
400
+
constthisUpdateDelay=this.updateDelay
401
+
constthisAfterRender=this.afterRender
402
+
this.title=null
403
+
this.beforeRender=null
404
+
this.target=null
405
+
this.updateDelay=null
406
+
this.afterRender=null
407
+
395
408
if(options.renderMethod){
396
409
// execute user-supplied render method if it is provided
397
410
options.renderMethod(template,model,callback)
@@ -442,9 +455,9 @@ function singlePageExpress (options) {
442
455
443
456
if(!err){
444
457
// replace title tag with the new one
445
-
if(this.title){// check if res.title is set
458
+
if(thisTitle){// check if res.title is set
446
459
if(document.querySelector('title')){// check if the title element exists
447
-
document.querySelector('title').innerHTML=this.title// replace the page title with the new title from this.title
460
+
document.querySelector('title').innerHTML=thisTitle// replace the page title with the new title from res.title
448
461
}
449
462
}elseif(doc.querySelector('title')&&document.querySelector('title')){// otherwise check if a <title> tag exists in the template
450
463
document.querySelector('title').innerHTML=doc.querySelector('title').innerHTML// if so, replace the page title with the new title from the <title> tag
@@ -453,12 +466,12 @@ function singlePageExpress (options) {
453
466
// call app.beforeEveryRender function if it exists
454
467
if(app.beforeEveryRender&&typeofapp.beforeEveryRender==='function')app.beforeEveryRender(model)// e.g. document.body.style.opacity = 0
455
468
456
-
// call this.beforeRender function if it exists
457
-
if(this.beforeRender&&typeofthis.beforeRender==='function')this.beforeRender(model)// e.g. document.body.style.opacity = 0
469
+
// call res.beforeRender function if it exists
470
+
if(thisBeforeRender&&typeofthisBeforeRender==='function')thisBeforeRender(model)// e.g. document.body.style.opacity = 0
458
471
459
472
// update DOM
460
473
window.setTimeout(function(){
461
-
consttarget=this.target||app.defaultTarget// check if a target is set
474
+
consttarget=thisTarget||app.defaultTarget// check if a target is set
462
475
if(target){
463
476
if(document.querySelector(target)){// check if the target is a valid DOM element
464
477
if(doc.querySelector(target)){// if the new template has an element with the same id as the target container, then that's the container we're writing to
@@ -484,9 +497,9 @@ function singlePageExpress (options) {
484
497
// call app.afterEveryRender function if it exists
485
498
if(app.afterEveryRender&&typeofapp.afterEveryRender==='function')app.afterEveryRender(model)// e.g. document.body.style.opacity = 1
486
499
487
-
// call this.afterRender function if it exists
488
-
if(this.afterRender&&typeofthis.afterRender==='function')this.afterRender(model)// e.g. document.body.style.opacity = 1
0 commit comments