Skip to content
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

How to use template-level subscriptions? #24

Open
derwaldgeist opened this issue Oct 23, 2015 · 8 comments
Open

How to use template-level subscriptions? #24

derwaldgeist opened this issue Oct 23, 2015 · 8 comments

Comments

@derwaldgeist
Copy link

According to the docs, subscriptions have to be defined by using TAPi18n.subscribe(). But how does that match to template-level subscriptions, which have to be defined on the template via this.subscribe() in an onCreated() method?

PS: Is this repo still maintained? There are a lot of very old issues here without any replies.

@zayau
Copy link

zayau commented Dec 19, 2015

I haven't really tried this package. Did you find out how to use it with template subs or iron:router subs or reywood:publish-composite package with tap-i18n-db? I think you could do the same functionality without needing this package. Custom subscriptions with session var as selected language to pull fields depending on that language. e.g. french selected and pass that var in subscription and publish only french fields. What do you think?

@derwaldgeist
Copy link
Author

@zayaisshawn I gave up with this package, as I never got any reply. Seems to be a dead package.

@zayau
Copy link

zayau commented Dec 20, 2015

Yeah. I like to come up with my own solutions sometimes when there is no package that is actively maintained. For production apps you might want to avoid these kind of plugins.

@derwaldgeist
Copy link
Author

On the Meteor forums, SkinnyGeed1010 mentioned once, that he does only use a handful of packages because of that. But this is not really an option to me, since I do not want to code everything myself...

@ephemer
Copy link

ephemer commented Feb 4, 2016

@derwaldgeist, I just made this code for template-level subscriptions, it seems to correctly kill the subscription when the template is destroyed and also works with Template.instance().subscriptionsReady().

Just call TAPi18n.templateLevelSubscribe(this, "yourPublicationName"); from within your Template.xyz.onCreated() / onRendered() functions..

TAPi18n.templateLevelSubscribe = function(tmpl, publicationName) {
    let i18nHandle = TAPi18n.subscribe(publicationName);
    let sub = i18nHandle._getSubscription();
    tmpl._subscriptionHandles[sub.subscriptionId] = i18nHandle;

    if (tmpl._allSubsReady) {
        tmpl._allSubsReadyDep.changed();
    }

    tmpl.view.onViewDestroyed(function() {
        i18nHandle.stop();
    });

    return i18nHandle;
};

I'd make a pull request but it seems like @theosp isn't working on the package any more so for now I won't bother...

@derwaldgeist
Copy link
Author

Thanks for this code!

@Szayet
Copy link

Szayet commented Feb 6, 2016

@ephemer While we are waiting could you make a PR request to @phowat's working fork?
https://github.com/phowat/tap-i18n-db

@theosp
Copy link
Collaborator

theosp commented Feb 6, 2016

Hi guys,

@ephemer send a PR I'll pull it, but please also update the README as well with the new API.

Since these days I am not using tap:i18n-db in the projects I am actively working on, I have difficulty to find the time to evaluate PRs. So I need to see PRs approved by others to pull them without risking introducing bugs or breaking backward compatibility - which are my two chief concerns as maintainer.

As this case got approved by others as well as #20 I'll prepare a v0.5.0 with the two of them - as soon as you'll PR.

Thanks,
-Daniel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants