如何在流星中禁用实时重载?

时间:2014-12-29 03:00:28

标签: meteor

我想关闭每次更改文件时出现的meteor中的自动应用刷新。我该怎么做?

4 个答案:

答案 0 :(得分:18)

您可以使用--once标记启动您的应用,例如:meteor --once

答案 1 :(得分:16)

您可以通过在客户端代码中的任何位置添加HCP(热代码推送)来禁用它:

Meteor._reload.onMigrate(function() {
  return [false];
});

完成此操作后,您需要手动刷新页面才能看到任何新的更改。

答案 2 :(得分:4)

基于David的回复,以下是我一直在做的事情,让组件在活着时停止热代码推送:

let shouldReloadPage = false;
const componentsBlockingHCP = [];

Meteor._reload.onMigrate(function() {
  if (componentsBlockingHCP.length) { 
    shouldReloadPage = true;
    return [false];
  }
  shouldReloadPage = false;
  return [true];
});

/*
 * Prevent hot push
 */
export const delayHCP = (component) => {
  if (componentsBlockingHCP.indexOf(component) < 0)
    componentsBlockingHCP.push(component);
};

/*
 * Enable, and reload if hot pushed has been requested when it was not available
 */
export const stopHCPDelay = (component) => {
  const idx = componentsBlockingHCP.indexOf(component);
  if (idx !== -1)
    componentsBlockingHCP.splice(idx, 1);

  if (shouldReloadPage && !componentsBlockingHCP.length) {
    location.reload();
  }
};

然后,从一个组件(使用React语法):

componentDidMount() {
  delayHCP(this);
}
componentWillUnmount() {
  stopHCPDelay(this);
}

答案 3 :(得分:0)

有一个小技巧。将<div id="modal1" class='modal fade in'> <div id="modal2"> </div> </div> <input type="button" id="btn" value="Click to popup"/> <script type="text/javascript"> $(document).ready(function () { $("#btn").click(function () { $.ajax({ cache: false, url: '@Url.Action("Modal")', success: function (data) { $("#modal2").html(data); $("#modal1").modal('show'); } }); }); }); 放在您正在使用的网页的网址末尾,然后按#,然后继续处理您的代码。保存文件后,页面将不会刷新,直到您手动刷新(EnterF5)这种方式会阻止页面刷新,但新代码仍会推送到客户端而您不需要为整个站点禁用HCP。缺点:您不知道何时将新代码推送到客户端