meteor.js iron-router: prevent static template re-render and glitching?

六眼飞鱼酱① 提交于 2019-12-11 13:56:39

问题


I have a global template:

<template name="layout">
{{> header}}
{{> primaryNav}}
{{yield 'banner'}}
{{yield}}
{{> footer}}
{{> deleteConfirmModal }}
<span class="responsive-state"></span>
</template>

and when I do a route

@route 'blog',
    path: '/blog/'

Everything works dandy. I can click back and forth through my header links and nav links with no glitching. But if I add a data context:

@route 'blog',
    path: '/blog/'
    data: ->
        blogPosts: BlogPosts.find({}, {date: -1, time: -1}) 

When providing a data context, whenever I navigate to and away from a route in which a data context is provided all the templates nested in the layout template appear to re-render, causing glitches due to style classes that get wiped and then replaced. If I route to any other paths that do not require (and are not provided) a data context, the static templates do not re-render.

Is there a way to prevent certain static templates from re-rendering when providing a data context for a specific route?


回答1:


With Meteor in the current state- you should probably rely on renders breaking most stuff.

As for iron-router - the data is stored in a ReactiveVar, and it ensures that any changes to data cause the layoutTemplate to re-render (this might be an over-simplified interpretation).

You might be able to:

  • Remove styles that animate on addition
  • Try using preserve to keep the elements in-tact. (note: that it does not preserve anything but the element reference, all values/attributes get reset as per template generated element)
  • Wait for meteor 1.0, or use one of the new template rendering previews which "patch" the DOM instead of re-inserting every element on render.


来源:https://stackoverflow.com/questions/20958299/meteor-js-iron-router-prevent-static-template-re-render-and-glitching

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!