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鈥檒l 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

Comments

Projects
None yet
5 participants
@DominikGuzei

DominikGuzei commented Jun 29, 2015

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

This comment has been minimized.

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

This comment has been minimized.

DominikGuzei commented Jun 29, 2015

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

DominikGuzei commented Jun 29, 2015

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

@rhyslbw

This comment has been minimized.

Contributor

rhyslbw commented Jun 29, 2015

Sounds good @arunoda

@arunoda

This comment has been minimized.

Contributor

arunoda commented Jun 29, 2015

@arunoda

This comment has been minimized.

Contributor

arunoda commented Jun 29, 2015

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

@DominikGuzei

This comment has been minimized.

DominikGuzei commented Jun 29, 2015

Awesome, thanks so much! 馃憤

@arunoda

This comment has been minimized.

Contributor

arunoda commented Jun 29, 2015

Hope we fixed this :)

@arunoda arunoda closed this Jun 29, 2015

@DominikGuzei

This comment has been minimized.

DominikGuzei commented Jun 29, 2015

Yeah it works now! 馃槈 thanks again

@zachdixon

This comment has been minimized.

zachdixon commented Aug 4, 2015

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

This comment has been minimized.

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

This comment has been minimized.

zachdixon commented Aug 4, 2015

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

This comment has been minimized.

zachdixon commented Aug 4, 2015

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

This comment has been minimized.

MiroHibler commented Mar 20, 2018

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