简体   繁体   English

有关如何在设定的时间间隔内不断初始化此模型的建议?

[英]Suggestions on how to deal with this model constantly being re-initialized in a set interval?

I have been recently assigned to maintain EmberJS code at work and I am complete newbie with EmberJS or Javascript, Hence, I came here for help. 我最近被分配维护工作中的EmberJS代码,并且我对EmberJS或Javascript完全是个新手,因此,我来​​这里寻求帮助。

Context 语境

I have a live feed page (like a news feed) that is integrated with Infinity Loading and this feed constantly checks with the backend to see for any new messages. 我有一个实时供稿页面(如新闻供稿),该页面已与Infinity Loading集成在一起,并且此供稿不断检查后端以查看是否有新消息。 This is causing this code to be constantly invoked. 这导致该代码不断被调用。

import InfinityRoute from "ember-infinity/mixins/route";

export default Ember.Route.extend(InfinityRoute,{
  perPageParam: "perPage",
  totalPagesParam: "meta.totalPages",
  queryParams: { dateFrom:.... },
  model(params){
    const defaultParams = { perPage: 25, startingPage: 1 } ;
    const modelParams = Ember.$.extend(defaultParams, params);
      return this.infinityModel("message", modelParams);
  }

The above code will load 25 pages with startingPage as 1 and pass it to the infinityModel which will contact the data store to get the necessary information. 上面的代码将加载25个页面,其中startingPage为1,并将其传递给infinityModel,后者将与数据存储联系以获取必要的信息。

Question Scenario 问题场景

Above code is constantly bringing you back to page 1 and lose track of the current page (Example, If you scroll above 25 messages and are in the 2nd page, then the 2nd page keeps disappearing and re-appearing because of the scroll position and model re-initialization setting the startingPage back to 1) 上面的代码不断使您回到第1页,而无法跟踪当前页面(例如,如果您滚动显示25条以上的消息并在第二页中,则由于滚动位置和型号的原因,第二页会不断消失并重新出现重新初始化,将startingPage设置回1)

I would love if you guys can provide me with any suggestions on how to handle this model re-initialization and infinityScroll issue? 如果您能为我提供有关如何处理此模型重新初始化和infinityScroll问题的任何建议,我会很乐意?

I'm not sure if I understand your problem correctly but likely we had to solve similar problem. 我不确定我是否正确理解了您的问题,但是可能我们必须解决类似的问题。 Our backend periodically rewrites model that is used to generate recursive components. 我们的后端定期重写用于生成递归组件的模型。 These components have some state information that was loose after each model reload. 这些组件具有一些状态信息,这些状态信息在每次重新加载模型后都会松散。 We had decided to solve this using Ember.ArrayProxy. 我们决定使用Ember.ArrayProxy解决此问题。

You want to record 'live-array' where changes will be sent to templates, like when you are using store.findAll() - on other side store.peekAll() returns standard array. 您想记录“实时数组”,将更改发送到模板,就像您在使用store.findAll()一样-在另一面,store.peekAll()返回标准数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM