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

Feature Request: manual initialization #180

Closed
DominikGuzei opened this issue Jun 29, 2015 · 16 comments
Closed

Feature Request: manual initialization #180

DominikGuzei opened this issue Jun 29, 2015 · 16 comments

Comments

@DominikGuzei
Copy link

Hey @arunoda!
Awesome package, works great for my current customer project 😉

There is only one thing that caused me some trouble: I can't control the initialization of flow-router.
i want routing to start exactly when the app is ready for it and not when your Meteor.startup hook is called internally. This works perfectly with iron router when telling it "not to autorun", could you add a similar api?

I even tried overriding the Router.prototype.initialize method but then i got other weird errors.

@arunoda
Copy link
Contributor

arunoda commented Jun 29, 2015

Can I have the usecase for this? Then I can think what are the possible things we can do.

@DominikGuzei
Copy link
Author

It's pretty simple: I want to initialize and run my custom app within a Meteor.startup block but flow-router is starting to route before that. So i can't reference my running app within the first route.

So here is the code i have which causes problems:

Meteor.startup -> 
  TestApp.app = new TestApp.Application()
  TestApp.app.start()

FlowRouter.route '/test/:code',
  name: 'testRoute'
  triggersEnter: [(context, redirect) -> redirect "#{context.path}/search"]

FlowRouter.route '/test/:code/search',
  name: 'testSearchRoute'
  action: (params) ->
    TestApp.app.publish new TestApp.SearchRouteVisited code: params.code

visiting test/123 redirects to the search route test/123/search which publishes an event to the app that triggers other stuff in the app. The problem here is that TestApp.app is not yet defined here because flow-router enters the action before my custom Meteor.startup hook was triggered.

@arunoda
Copy link
Contributor

arunoda commented Jun 29, 2015

Okay. We just faced a similar issue with flow-layout and we are fixing it with rendering it inside a Meteor.defer.

I hope that'll fix your problem too using a similar patten. It's a kind of tricky on how to give an handler to initialise Flow Router. (I mean in API wise)

@arunoda
Copy link
Contributor

arunoda commented Jun 29, 2015

I think I've the API in mind. We can introduce something called FlowRouter.wait(). Then it won't automatically initialise, but allow you to do it via FlowRouter.initialize() when it's ready.

@DominikGuzei
Copy link
Author

Ok great :-) i am happy about any solution that solves this problem!

@rhyslbw
Copy link
Contributor

rhyslbw commented Jun 29, 2015

Sounds good @arunoda

@arunoda
Copy link
Contributor

arunoda commented Jun 29, 2015

@arunoda
Copy link
Contributor

arunoda commented Jun 29, 2015

If this solved, I think this may be the fast feature request implementation I have done :D

@DominikGuzei
Copy link
Author

Awesome, thanks so much! 👍

@arunoda
Copy link
Contributor

arunoda commented Jun 29, 2015

Hope we fixed this :)

@arunoda arunoda closed this as completed Jun 29, 2015
@DominikGuzei
Copy link
Author

Yeah it works now! 😉 thanks again

@zachdixon
Copy link

I have another use case that I can't seem to get working with the current implementation of wait() and initialize(). I'm using react, jsx, universe:modules for import/export, etc. My main.js file looks like this:

FlowRouter.wait();

Meteor.startup(function() {
  System.import('client/scripts/routes');
  FlowRouter.initialize();
});

If I'm correct, FlowRouter doesn't allow the addition of FlowRouter.route()s later on. Or am I doing something wrong? What I would like to do is call FlowRouter.wait(), load my routes via System.import in Meteor.startup that way all of my react components are loaded/ready, and then call FlowRouter.initialize(). The reason I need to do this is since I'm rendering react components in the actions obviously.

@arunoda
Copy link
Contributor

arunoda commented Aug 4, 2015

You can add routes later on via FlowRouter.route(). Above code looks good to me. I'd like to see a sample project with your problem.

@zachdixon
Copy link

It sounded like it would work to me too, I may just be doing else wrong; definitely in the experimentation phase of this setup.

https://github.com/zachdixon/socialcentiv-meteor/tree/modules

@zachdixon
Copy link

I think you're right that this isn't a FlowRouter issue, I've tried it with React Router as well and got the same errors. It must be something with my app-deps package that I got from here
I've tried updating package versions which got me this error:
[Universe Modules]: Module app-deps does not exist! You will probably see other errors in the console because of that.

Sorry to bother you, still trying to figure out the issue.

@MiroHibler
Copy link

FlowRouter.wait() just saved my day! Thanks! :)

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