veliovgroup / flow-router

🚦 Carefully extended flow-router for Meteor
https://packosphere.com/ostrio/flow-router-extra
BSD 3-Clause "New" or "Revised" License
202 stars 29 forks source link

[Feature] Global waitOn hook #11

Closed WayneUong closed 7 years ago

WayneUong commented 7 years ago

Like this?

FlowRouter.globals.push({
  waitOn() {
    return [import(/*...*/)];
  }
});
dr-dimitru commented 7 years ago

@WayneUong ,

Thank you for suggestion. My guess same should also apply to the route groups, right?

WayneUong commented 7 years ago

@dr-dimitru Yeah on the route group level would be great too. Btw, I'm transitioning from the old FlowRouter and the global namespace seems to be gone. Right now I have to do a hack:

import {FlowRouter as flowRouter} from '...';
FlowRouter = flowRouter;

Is there a better way? We have too many unimported FlowRouter's around. Thank you.

dr-dimitru commented 7 years ago

Btw, I'm transitioning from the old

Great

the global namespace seems to be gone

Yes, thanks to Meteor new principles

Is there a better way?

// The best way to make sure you follow new Meteor principles
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';

// Expose FlowRouter to the global will work too
// This will work on both Client and Server
// Best if this done in the /lib/
import {FlowRouter as flowRouter} from 'meteor/ostrio:flow-router-extra';
this.FlowRouter = global.FlowRouter = flowRouter;
WayneUong commented 7 years ago

Thanks @dr-dimitru very nice package with lots of good features.

dr-dimitru commented 7 years ago

@WayneUong thank you for feedback, this means a lot for me, and feature suggestion, it will arrive on next release.

Please, support this project by:

valorloff commented 7 years ago

Hi @dr-dimitru!

layout.js:

import './layout.html';
import './main.html';
import './main.js';
import '/imports/ui/service.js';

routes.js (don't works):

FlowRouter.route('/cart',{
    name: 'cartItems',
    loadingTemplate: 'loading',
    waitOn() {
      import('/imports/ui/cart/layout.js');
    },

but

FlowRouter.route('/cart',{
    name: 'cartItems',
    loadingTemplate: 'loading',
    waitOn() {
    return [import('/imports/ui/cart/layout.html'),
      import('/imports/ui/cart/main.html'),
      import('/imports/ui/cart/main.js'),
      import('/imports/ui/service.js')]
      // import('/imports/ui/cart/layout.js');
    },

works! when bunch files is large, how improve this?

dr-dimitru commented 7 years ago

Hello @valorloff ,

You're missing return key word here:

FlowRouter.route('/cart',{
    name: 'cartItems',
    loadingTemplate: 'loading',
    waitOn() {
+      return  import('/imports/ui/cart/layout.js');
-      import('/imports/ui/cart/layout.js');
    },
valorloff commented 7 years ago

sorry, ...shame :)

dr-dimitru commented 7 years ago

@valorloff solved?

valorloff commented 7 years ago

sure! It's a stupid mistake, thanks! per route DynImport works nice

dr-dimitru commented 7 years ago

Great, no worries. Thank you for support and the choice )

btbjosh commented 7 years ago

+1 for Group route dynamic imports. I have a system admin panel that I would prefer to import all the system stuff in once there and not in each route :)

Keep up the great work. These are nice additions to FlowRouter!

dr-dimitru commented 7 years ago

Hello everyone,

Thank you for reminding me about this feature. It's implemented in v.3.2.0, please upgrade.

Feel free to close this issue if v.3.2.0 solved it.