title: How can I make a reactive array from a Meteor collection?
body: <p>I want to take a list of item names from a collection as a simple array to use for things like autocompleting user input and checking for duplicates. I would like this list to be reactive so that changes in the data will be reflected in the array. I have tried the following based on the Meteor documentation:</p>
  
  <pre><code>    setReactiveArray = (objName, Collection, field) -&gt;
          update = -&gt;
            context = new Meteor.deps.Context()
            context.on_invalidate update
            context.run -&gt; 
              list = Collection.find({},{field: 1}).fetch()
              myapp[objName] = _(list).pluck field
          update()
  
      Meteor.startup -&gt;
          if not app.items?
              setReactiveArray('items', Items, 'name')
  
      #set autocomplete using the array
      Template.myForm.set_typeahead =  -&gt;
         Meteor.defer -&gt;
          $('[name="item"]').typeahead {source: app.items}    
  </code></pre>
  
  <p>This code seems to work, but it kills my app's load time (takes 5-10 seconds to load on dev/localhost vs. ~1 second without this code). Am I doing something wrong? Is there a better way to accomplish this? </p>