Search code examples
javascriptmeteorddp

how to tell DDP to selectively observe change certain field,, instead all defined fields..?


we normally publish data as follow...

Meteor.publish('items', function(a) {
  return Items.find(a, {fields: {observeA:1, observeB:1, noobserveA:1, noobserveB:1}});
});

i have conditions as follow...

  • observeA and observeB are reactive data,, so i need to observe them...
  • noobserveA and noobserveB are static data,, so i don't need to observe them...

with above publication,, DDP still observe noobserveA and noobserveB..

how to tell DDP not to observe noobserveA and noobserveB..??

what i can think possible is to directly control published record... but i don't have even single idea how to make it work.. advanced publication feel too much for me for now...

Meteor.publish('items', function(a) {
  var self = this;
  var handle = Items.find(a || {}).observeChanges({
    changed: function(id, fields) {
      self.changed("itemdata", id, fields);
    }
  });
  self.ready();
  self.onStop(function () {
    handle.stop();
  });
});

after this what should i do..?? i'm stuck with no idea what i'm doing right now... so if you know how to not to observer noobserveA and noobserveB either with advanced publication or other idea,, feel free to write answer... what i need is not to observe noobserveA and noobserveB field... that's it and that's all...

thank Youu...


Solution

  • Why don't you store noobserveA and noobserveB into local collection?

    After you store into local collection, you fetch noobserveA and noobserveB from local collection. Since local collection has no connection with server, then every update in server won't have any effect with noobserveA and noobserveB. Then, noobserveA and noobserveB would be static as you wish.

    By this, you don't have to touch Advanced Publications.