New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template-level subscriptions #3559

Closed
wants to merge 2 commits into
base: devel
from

Conversation

Projects
None yet
8 participants
@stubailo
Contributor

stubailo commented Jan 26, 2015

Now, you can call this.subscribe inside the onCreated callback of a Template. This subscription is automatically stopped when the template is destroyed. You also get a bonus built-in helper, Template.ready, that returns true when all of the subscriptions are ready. You can also manage your ready state independently by using the handles returned from this.subscribe.

@stubailo

This comment has been minimized.

Show comment
Hide comment
@stubailo

stubailo Jan 26, 2015

Contributor

Added tests and documentation for the new feature.

Contributor

stubailo commented Jan 26, 2015

Added tests and documentation for the new feature.

@stubailo

This comment has been minimized.

Show comment
Hide comment
@stubailo

stubailo Jan 27, 2015

Contributor

@avital @dgreensp review please?

Contributor

stubailo commented Jan 27, 2015

@avital @dgreensp review please?

Show outdated Hide outdated packages/blaze/view.js
Show outdated Hide outdated packages/blaze/view.js
@avital

This comment has been minimized.

Show comment
Hide comment
@avital

avital Jan 27, 2015

Contributor

Added some comments, but this looks great! So simple!

Contributor

avital commented Jan 27, 2015

Added some comments, but this looks great! So simple!

@Slava Slava added the Project:Blaze label Jan 27, 2015

@arunoda

This comment has been minimized.

Show comment
Hide comment
@arunoda

arunoda Jan 27, 2015

Very nice :)

arunoda commented Jan 27, 2015

Very nice :)

@stubailo

This comment has been minimized.

Show comment
Hide comment
@stubailo

stubailo Jan 28, 2015

Contributor

Currently in the middle of implementing onStopped for subscriptions, put this CR on hold please

Contributor

stubailo commented Jan 28, 2015

Currently in the middle of implementing onStopped for subscriptions, put this CR on hold please

}
if (subscriptionsFinished === 2) {
Tracker.afterFlush(checkBothReady);

This comment has been minimized.

@avital

avital Jan 28, 2015

Contributor

(Lost the original comment since you re-wrote the test)

Before we merge this, I'd like to understand why we can't use Deps.flush. (Happy to pair on it if that would be helpful)

@avital

avital Jan 28, 2015

Contributor

(Lost the original comment since you re-wrote the test)

Before we merge this, I'd like to understand why we can't use Deps.flush. (Happy to pair on it if that would be helpful)

This comment has been minimized.

@stubailo

stubailo Feb 11, 2015

Contributor

No progress on this. Do you want to pair on it?

@stubailo

stubailo Feb 11, 2015

Contributor

No progress on this. Do you want to pair on it?

@Tarang

This comment has been minimized.

Show comment
Hide comment
@Tarang

Tarang Jan 30, 2015

Contributor

Is it not possible to allow a reactive change with this, especially when the Tracker computation is not necessarily 'on its own' but part of a the template's lifetime too?

i.e

Template.hello.onCreated(function() {
    var self = this;
    self.autorun(function() {
      self.subscribe("list", Session.get('category'))
    });
  })
Contributor

Tarang commented Jan 30, 2015

Is it not possible to allow a reactive change with this, especially when the Tracker computation is not necessarily 'on its own' but part of a the template's lifetime too?

i.e

Template.hello.onCreated(function() {
    var self = this;
    self.autorun(function() {
      self.subscribe("list", Session.get('category'))
    });
  })
@stubailo

This comment has been minimized.

Show comment
Hide comment
@stubailo

stubailo Jan 30, 2015

Contributor

@Tarang the intention is that the code you provided will work as expected. I should add a test for that particular use case.

Contributor

stubailo commented Jan 30, 2015

@Tarang the intention is that the code you provided will work as expected. I should add a test for that particular use case.

@stubailo

This comment has been minimized.

Show comment
Hide comment
@stubailo

stubailo Feb 11, 2015

Contributor

Rebased on devel and fixed minor merge conflicts. @glasser, what do you think?

In particular, I have made two changes to subscriptions:

  1. The onError callback is deprecated now, and replaced with onStopped with an optional error callback. I still have to write docs for this change, but it's fully backwards compatible.
  2. Meteor.subscribe inside an autorun always returns the exact same handle, so you can compare them with ===.
Contributor

stubailo commented Feb 11, 2015

Rebased on devel and fixed minor merge conflicts. @glasser, what do you think?

In particular, I have made two changes to subscriptions:

  1. The onError callback is deprecated now, and replaced with onStopped with an optional error callback. I still have to write docs for this change, but it's fully backwards compatible.
  2. Meteor.subscribe inside an autorun always returns the exact same handle, so you can compare them with ===.
@stubailo

This comment has been minimized.

Show comment
Hide comment
@stubailo

stubailo Feb 11, 2015

Contributor

OK all of the tests pass and I have added a lot of new tests. @glasser, @avital what else should I do before merging this? Also, should I rebase some things to reduce the number of commits?

Contributor

stubailo commented Feb 11, 2015

OK all of the tests pass and I have added a lot of new tests. @glasser, @avital what else should I do before merging this? Also, should I rebase some things to reduce the number of commits?

@@ -267,6 +267,8 @@ Blaze.TemplateInstance = function (view) {
* @type {DOMNode}

This comment has been minimized.

@glasser

glasser Feb 11, 2015

Member

Is it possible to separate this into one commit which adds the feature to ddp (and doesn't touch blaze at all) followed by one commit that does the blaze/spacebars stuff?

eg, let's say we find a bug in the blaze thing and revert it. would be a shame to lose the new feature.

if you need help splitting git commits in two i can help :)

@glasser

glasser Feb 11, 2015

Member

Is it possible to separate this into one commit which adds the feature to ddp (and doesn't touch blaze at all) followed by one commit that does the blaze/spacebars stuff?

eg, let's say we find a bug in the blaze thing and revert it. would be a shame to lose the new feature.

if you need help splitting git commits in two i can help :)

This comment has been minimized.

@stubailo

stubailo Feb 12, 2015

Contributor

This is the commit you want to split? 1f77d8e

@stubailo

stubailo Feb 12, 2015

Contributor

This is the commit you want to split? 1f77d8e

@glasser

This comment has been minimized.

Show comment
Hide comment
@glasser

glasser Feb 12, 2015

Member

I didn't look at the blaze side of things, but finished a pass on the ddp side

Member

glasser commented Feb 12, 2015

I didn't look at the blaze side of things, but finished a pass on the ddp side

* @return {Boolean} True if all subscriptions on this template instance are
* ready.
*/
Blaze.TemplateInstance.prototype.subscriptionsReady = function () {

This comment has been minimized.

@glasser

glasser Feb 12, 2015

Member

It seems like this will often trigger deps changed without a value change. eg, on unsub, it will stay true.

what's the function that you can use to make that not happen?

@glasser

glasser Feb 12, 2015

Member

It seems like this will often trigger deps changed without a value change. eg, on unsub, it will stay true.

what's the function that you can use to make that not happen?

This comment has been minimized.

@stubailo

stubailo Feb 12, 2015

Contributor

Fixed this

@stubailo

stubailo Feb 12, 2015

Contributor

Fixed this

Show outdated Hide outdated packages/blaze/view.js
@stubailo

This comment has been minimized.

Show comment
Hide comment
@stubailo

stubailo Feb 12, 2015

Contributor

Merged manually

Contributor

stubailo commented Feb 12, 2015

Merged manually

@stubailo stubailo closed this Feb 12, 2015

@KrishnaPG

This comment has been minimized.

Show comment
Hide comment
@KrishnaPG

KrishnaPG Apr 10, 2015

Looks interesting and would love to use this kind of thing - any examples / tutorials on the how to take advantage of this feature?

KrishnaPG commented Apr 10, 2015

Looks interesting and would love to use this kind of thing - any examples / tutorials on the how to take advantage of this feature?

@stubailo

This comment has been minimized.

Show comment
Hide comment
@stubailo

stubailo Apr 10, 2015

Contributor

Here are the official docs: http://docs.meteor.com/#/full/Blaze-TemplateInstance-subscribe

Here is a great article by discover Meteor, written before the feature was added to Meteor: https://www.discovermeteor.com/blog/template-level-subscriptions/

Contributor

stubailo commented Apr 10, 2015

Here are the official docs: http://docs.meteor.com/#/full/Blaze-TemplateInstance-subscribe

Here is a great article by discover Meteor, written before the feature was added to Meteor: https://www.discovermeteor.com/blog/template-level-subscriptions/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment