Comments (15)
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.
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.
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.
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.
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.
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.
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.
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.
Have there been any developments regarding the flickering recently?
from iron-router.
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.
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.
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.
@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.
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.
Thanks!
from iron-router.
Related Issues (20)
- abort unload HOT 1
- Meteor, Iron router: Render makes the page to shake
- Parameters can't have *s in them
- post to serverside route forces client to the posts action url HOT 1
- undefined routes terminate web socket connection
- Iron router Issue with spiderable HOT 4
- can be read from a controller, variables from another controller?
- Defining routes using arrow functions doesn't work HOT 1
- Path name with '/' inside it... HOT 1
- Request entity too large error
- Errors prevented startup: W
- meteor iron:router not working HOT 1
- Dynamic Imports with Iron Router HOT 10
- Able users to save audio files for offline viewing HOT 2
- How to use pathFor have id like {{pathFor route='index.resource.show'}}/{{data._id}} HOT 2
- Subscription lost after a few minutes HOT 1
- Supporting newer versions of Meteor with compat packages
- ERR_OUT_OF_RANGE
- why async, promise?
- Source for iron-router 1.2.0? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iron-router.