GithubHelp home page GithubHelp logo

Comments (15)

mizzao avatar mizzao commented on May 30, 2024 1

Hi @dalgard, as long as the subscription is hit before the route loads, you can pass it to the router to wait on. I usually put all of my subscriptions - including autorun ones and router-loaded ones - into one file, and give the array of relevant ones to wait on. This is okay even if the global subscriptions change as long as they are stored back in the file's closure.

See this file for an example, although not a perfect one: https://github.com/alicexigao/wisdomOfCrowds/blob/master/client/router.coffee

from iron-router.

yasinuslu avatar yasinuslu commented on May 30, 2024
How do i manage subscriptions with parameters? 

Following code should do the trick:

ProductsController = ApplicationController.extend({
  // without parameter
  list: function () {
    this.waitOn = Meteor.subscribe('active_auctions');

    this.render("other_auctions");
  },

  // with parameters
  show: function () {

    this.waitOn =  Meteor.subscribe('full_auction', this.params.slug, this.params._id);

    this.data = function () {
      return Auctions.findOne(this.params._id);
    }

    this.render("auction_item_v");
  }
});

I don't know any specific solution to this one:

How do i manage to NOT subscribe to every subscription that exists in my application? And how do i unsubscribe those i don't need?

from iron-router.

DerMambo avatar DerMambo commented on May 30, 2024

This is great, thank you very much!

Maybe it would be an idea to link the video from evented mind to the readme. Made things easier for me, too.

from iron-router.

cmather avatar cmather commented on May 30, 2024

waitOn can also take a function that returns a handle or an array if handles for delayed execution. If you have time to contribute enhancements to the readme that would be awesome.

Sent from my iPhone

On Aug 14, 2013, at 4:51 AM, Manuel Schoebel [email protected] wrote:

This is great, thank you very much!

Maybe it would be an idea to link the video from evented mind to the readme. Made things easier for me, too.


Reply to this email directly or view it on GitHub.

from iron-router.

tmeasday avatar tmeasday commented on May 30, 2024

I'm interested, is this the right way to do this? Questions:

  • Does Meteor know to unsubscribe when you browse away?
  • What if more than one page wants the same subscription? Does Meteor end up un-subbing and then resubbing to the same subscription?

Honestly interested in the answer to both questions.

from iron-router.

cmather avatar cmather commented on May 30, 2024

Meteor will automatically call stop on a subscription handle if the subscription method was called inside an active computation and that computation is invalidated. See: https://github.com/meteor/meteor/blob/devel/packages/livedata/livedata_connection.js#L528.

In this case if you make waitOn a function, it will get called from the render method of the RouteController instance. There are two computations created: One for running the controller, unless you specified reactive: false as an option; and another around the wait(...) call inside the render method.

So I think there is a hole here if you have a non-reactive route, and the route changes. But in the standard case it should be okay.

from iron-router.

DerMambo avatar DerMambo commented on May 30, 2024

In my case i have several routes with the same subscriptions
/profile/:slug
/profile/:slug/about
/profile/:slug/followers
...
My Problem is, that there is a resubscribe on every route change. And due to the waiting there is a unnecessary flicker on the screen. I subscribe to everything i need for the profile routes, so that there is no flickr.

I found out that the base subscriptions i configure on the Router.configure are not resubscribed. Can i somehow make use of that? Dynamically change the Router config or sth.?

from iron-router.

tmeasday avatar tmeasday commented on May 30, 2024

Mmm.. I feared as much.

@cmather If I remember correctly, there's some magic in Deps.autorun that detects if it's torn down a sub and then resubbed with the same arguments. We should figure out some way to re-use that magic...

from iron-router.

thatjuan avatar thatjuan commented on May 30, 2024

Have there been any developments regarding the flickering recently?

from iron-router.

DerMambo avatar DerMambo commented on May 30, 2024

You should check out the dev branch (v 0.6.0). The problem is solved there. In 0.6.0 are lots of improvements but you also need to change some of your code. But it is not that much and absolutely worth it! ;)

from iron-router.

bryanaka avatar bryanaka commented on May 30, 2024

I am on 0.6.0 and I am still having a lot of issues when dealing with multiple subscriptions on the same collection.

Basically a lot of flickering issues. using both waitOn and wait() haven't been working for me. Either...

  • The Page hangs in loading indefinitely
  • The Template loads empty, but on querying the collection directly, the data is there
  • The Template loads and flickers the data, then disappears and leaves an empty template or renders not found template (can't debug when which one happens over the other yet)

And each conditions happens in the respective situation

  • using before and wait() combo, but seems to only happen when I have multiple subscriptions to the same collection, with different restrictions. Can't quite narrow down this one yet.
  • using waitOn as a function that returns a subscription or an array of subscriptions
  • placing this.waitOn = subscription in the action

Here is my code
https://gist.github.com/bryanaka/7253198

ideas?

from iron-router.

mizzao avatar mizzao commented on May 30, 2024

Hey @tmeasday and @cmather,

Is wait / waitOn now part of a reactive computation now that properly tears down a subscription after a route is browsed away from?

from iron-router.

cmather avatar cmather commented on May 30, 2024

@mizzao, The route's controller is run in a computation. When you run a different route, the previous computation is stopped. This has the effect of stopping any subscriptions that weren't re-subscribed before the next flush.

So yes, if you subscribe in waitOn, before, action that subscription will be stopped if you navigate to a different route, provided you don't re-subscribe to the exact same subscription on the next route.

from iron-router.

dalgard avatar dalgard commented on May 30, 2024

The big question on my mind is:

If I create my subscription outside a waitOn hook (i.e. globally), how can I make sure the loadingTemplate is displayed, in case the route is called before the subscription has finished its first load?

from iron-router.

dalgard avatar dalgard commented on May 30, 2024

Thanks!

from iron-router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.