fast_render_route.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. FastRenderColl = new Mongo.Collection('fast-render-coll');
  2. FlowRouter.route('/the-fast-render-route', {
  3. subscriptions: function() {
  4. this.register('data', Meteor.subscribe('fast-render-data'));
  5. }
  6. });
  7. FlowRouter.route('/the-fast-render-route-params/:id', {
  8. subscriptions: function(params, queryParams) {
  9. this.register('data', Meteor.subscribe('fast-render-data-params', params, queryParams));
  10. }
  11. });
  12. FlowRouter.route('/no-fast-render', {
  13. subscriptions: function() {
  14. if(Meteor.isClient) {
  15. this.register('data', Meteor.subscribe('fast-render-data'));
  16. }
  17. }
  18. });
  19. var frGroup = FlowRouter.group({
  20. prefix: "/fr"
  21. });
  22. frGroup.route("/have-fr", {
  23. subscriptions: function() {
  24. this.register('data', Meteor.subscribe('fast-render-data'));
  25. }
  26. });
  27. if(Meteor.isServer) {
  28. if(!FastRenderColl.findOne()) {
  29. FastRenderColl.insert({_id: "one", aa: 10});
  30. FastRenderColl.insert({_id: "two", aa: 20});
  31. }
  32. Meteor.publish('fast-render-data', function() {
  33. return FastRenderColl.find({}, {sort: {aa: -1}});
  34. });
  35. Meteor.publish('fast-render-data-params', function(params, queryParams) {
  36. var fields = {params: params, queryParams: queryParams};
  37. this.added('fast-render-coll', 'one', fields);
  38. this.ready();
  39. });
  40. }