36377

Observable array or in memory collection in Meteor

Question:

Is there a way to create an observable array or in memory collection in Meteor?

The way I'm faking it is by creating a session variable containing the array, Session.setDefault('people', []); and then updating that value when the array changes, Session.set('people', modifiedArray).

Answer1:

You can create a local collection by calling Meteor.Collection constructor without supplying collection name in the parameter, i.e.:

LocalList = new Meteor.Collection();

See this in <a href="http://docs.meteor.com/#meteor_collection" rel="nofollow">the Meteor documentation</a>.

Notice also that you can observe anything you want thanks to <a href="http://docs.meteor.com/#deps_dependency" rel="nofollow">Dependencies</a>.

Example:

List = function() { this.data = []; this.dep = new Deps.Dependency(); }; _.extends(List.prototype, { insert: function(element) { this.data.push(element); this.dep.changed(); }, }); var list = new List(); Template.observer.helper = function() { list.dep.depend(); return list.data; };

helper will be updated and observer template will rerender each time you call list.insert function.

Recommend

  • Cqlsh query for wildcard characters
  • Removing all empty elements in a vector from end
  • assembly intrinsic for bit test and set (BTS)
  • Cocoa validate menu items in multiple windows
  • TabBarController: Orienting views in different orientations
  • How can I merge my files when the folder structure has changed using Borland StarTeam?
  • Update SQL MS Access 2010
  • Is it safe to drop the -webkit vendor prefix from the css3 border-radius yet?
  • init_seg and warning C4073 from library code?
  • iOS Localization Doesn't Work with More Than 63 Files
  • Are there any side effects from calling SQLAlchemy flush() within code?
  • Accessing Rows In A LINQ Result Without A Foreach Loop?
  • why calling cd shell command through system() or execvp() from a child process won't work?
  • Where these are stored?
  • abstracting over a collection
  • How can I tell a form not to dispose a particular control when it closes?
  • How Get arguments value using inline assembly in C without Glibc?
  • Clear activity stack before launching another activity
  • Android application: how to use the camera and grab the image bytes?
  • How to use JavaScript to determine whether a file exists in a directory?
  • ADO and msqli connections very slow
  • How can the INSERT … ON CONFLICT (id) DO UPDATE… syntax be used with a sequence ID?
  • Create DicomImage from scratch using Dcmtk
  • PHP buffered output depending on server setting?
  • QLineEdit password safety
  • Retrieving value from sql ExecuteScalar()
  • Finding past revisions of files in StarTeam w/ .NET SDK / C#
  • Java applet as stand-alone Windows application?
  • Adding custom controls to a full screen movie
  • Jquery - Jquery Wysiwyg return html as a string
  • Why winpcap requires both .lib and .dll to run?
  • retrieve vertices with no linked edge in arangodb
  • SQL merge duplicate rows and join values that are different
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • reshape alternating columns in less time and using less memory
  • costura.fody for a dll that references another dll
  • Reading document lines to the user (python)