What is cursor?

时光怂恿深爱的人放手 提交于 2020-01-03 05:19:22

问题


In discover meteor,

posts: function() {
  return Posts.find();
}

is used, not this:

posts: function() {
  return Posts.find().fetch();
}

I tried function below, it also works, and can realtime update.

What is cursor exactly? And What is the different of above two functions?


回答1:


The Meteor cursor is like a lazy version of the array of documents.

It's designed to iterate through the results of a query while not actually loading each of the documents until they are actually requested or the cursor is at the position containing the document.

Its better to think of the results of the query as a book. If you use .fetch() all the pages are printed even though you're not reading them.

The cursor prints pages as you're reading them.

Additionally the cursor has several enhancements with regards to Blaze. Content is rendered less often as minute details in a document's change are able to change the DOM section on its own, without recreating an entire object. It's easier for Blaze to interact with the cursor than an array of Javascript objects.

Additionally a cursor can be observed, a plain array of Javascript object's can't

TLDR; Cursor is just like an array of objects, but designed to be more efficient & is slightly more extended with features.



来源:https://stackoverflow.com/questions/30837134/what-is-cursor

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