Comments (6)
Yeah for the first case you can use the onRendered
hook. For the second, I'm not sure what HCR means :-).
from iron-router.
Hot Code Reload.
Hopefully there'll be a way to do this without having to define a controller (I haven't had to explicitly do so so far!).
from iron-router.
To be clearer: it's a common use case to want to set "view" state for a page in the session.
For example, you might want to Session.set('sidebarOpen', false)
every time you browse to a page with a sidebar in it.
If you browse away and then come back, you want the "view" to be reset, so the sidebar to be closed again. However, if there's a HCR, you do not want the view to be reset.
From the router's perspective, it's difficult to tell the difference. I don't think it's impossible though.
from iron-router.
Ah yes, Hot Code Reload. I thought about that issue a few times. My inclination is to allow components to handle this as each component will have scoped reactive state. I'm assuming David's implementation allows for HCR, but I haven't confirmed this.
Putting the per page state in the Router would require creating a global reactive dictionary that the router uses. When the page reloads, the route necessarily runs again, creating a new instance of the controller. So the controller instance reactive dictionary would not survive the HCR.
Maybe we should take a closer look at the Component implementation. So far I've only studied the base.js code from a week or so ago. I didn't see a scoped reactive dictionary, but David mentioned it in his talk.
from iron-router.
Ahh, yes. Well, without knowing details of how UI/Components might work I would hazard a guess that the right thing for the router to do would be register itself for migration and defer to the currently rendered controller to save it's state. Then when a "migrated" startup happens (i.e. after HCR), the first thing the router could do is read that data back out and use it to establish both it's own internal state and that of the rendered controller. After which it would check the URL and make sure everything is kosher with what it expects.
But that's pretty complex and out of scope, I am not suggesting that we do so now!
In the meantime whilst we are stuck using the Session for component state, I'm wondering if the following solution isn't to janky:
// just a little note so we know when we are starting up based on migration
Meteor._reload.onMigrate('iron-router', function() { return [true, Location.path()]; });
// When routing to a controller:
// we don't want to do this when it's the first route we are rendering and we are coming out of HCR
if (! (firstRoute && Meteor._reload.migrationData('iron-router') === Location.path())) {
controller.beforeRoutingTo();
}
firstRoute = false;
Then I can write something like:
Router.map(function() {
this.route('foo', {
beforeRoutingTo: function() {
Session.set('menuState', 'open');
}
});
});
And know for sure that menuState
will always be set, but will not be reset when HCR happens.
from iron-router.
Assuming this is covered in your PR. Will look today.
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.