Code Monkey home page Code Monkey logo

Comments (9)

makstr avatar makstr commented on August 16, 2024

I was in for that idea initially. So just to be clear, nothing stops you from putting routes inside the module, but if you consider that your module might be redistributed between different apps than you will most likely look look to define routes in application wide config file.

from mantra-sample-blog-app.

payner35 avatar payner35 commented on August 16, 2024

Can i load my routes as part of an

app.loadModule(someModule);

from mantra-sample-blog-app.

makstr avatar makstr commented on August 16, 2024

Here is what my client/main.js file looks like

import {initContext} from '/imports/configs/context';
import routes from '/imports/configs/routes.jsx';
import {createApp} from '/imports/libs/mantra';

import coreModule from '/imports/modules/core';
import commentsModule from '/imports/modules/comments';

import _homeModule from '/imports/modules/_home';
import _homeRoutes from '/imports/modules/_home/configs/routes.jsx';

import _usersModule from '/imports/modules/_users';
import _usersRoutes from '/imports/modules/_users/configs/routes.jsx';

import _colorsModule from '/imports/modules/_colors';
import _colorsRoutes from '/imports/modules/_colors/configs/routes.jsx';


const context = initContext();

const app = createApp(context);
app.loadModule(coreModule);
app.loadModule(commentsModule);

app.loadModule(_homeModule);
app.loadModule(_usersModule);
app.loadModule(_colorsModule);

app.loadRoutes(routes);
app.loadRoutes(_homeRoutes);
app.loadRoutes(_usersRoutes);
app.loadRoutes(_colorsRoutes);

from mantra-sample-blog-app.

payner35 avatar payner35 commented on August 16, 2024

Ok.. thanks !

from mantra-sample-blog-app.

arunoda avatar arunoda commented on August 16, 2024

I like to place routes into a common place rather loading them from modules. I'm not disagreeing with it.
Then it's easy to visualize the whole app at a single place and modules does all the UI/action stuff.

Can I get some counter arguments and you reason on putting routes next to the modules?

from mantra-sample-blog-app.

payner35 avatar payner35 commented on August 16, 2024

My thinking is around the CMS side of things. if i can add a module that represents "Events" and it will come with the backend routes to create / manage / update / delete an Event item.

I'm playing with this concept of a modular CMS build-pack. Where a module can represent:

  • widgets that can be used to craft the UI experience
    • admin side features (including specific module admin routes)

a common place for routes then works for the main app.

I think for this to work.. the 'admin' routes would need to load up in the Module main.js file. And come loaded with the app.loadModule() call.

thoughts?

from mantra-sample-blog-app.

firrae avatar firrae commented on August 16, 2024

I don't mean to bring this back to life if it was finished, but personally I think separating the routes by their modules makes the most sense and means the modules are easier to maintain. From a CMS perspective, or any project in my mind, each module should be self contained. A "Users" module for example: EVERYTHING related to the users is put inside it, including the routes used for accessing them.

In the current setup you could have the users module, make a change, and need to go to the "Core" to update the routes associated to your change, but if you are using that same module in multiple projects then you have to do it for each individual project. This means that I have 3 apps all using the "Users" module I created, I have to open all 3, modify the core of all 3, before I can run my E2E and other tests, finally leading to push the update to staging/production. By putting the routes inside the module it cuts out the copy & pasting someone needs to do to use the module in different projects. It also makes it fully self contained, meaning you don't need to go outside of the module to update any aspect of it, meaning it's easier to maintain and expand.

As a general design rule I seperate everything down to core modules. I did this previously with packages in Meteor, but with the ability to use imports in 1.3, I will likely move away from that. This limits the amount of time spent hunting for where the component is that is having an issue. "Oh? There's a problem on 'example.com/user/ID/edit' CLIENT 1? I'll get right on that!." If you have multiple modules handling routes that start with /user then in my mind you didn't design things out well. Seeing that URL I should be able to tell what module it's related to. In the same thought process if I don't know where things are I can easily figure out what module I need to look at, and from there use it's route list to find the problem component if it didn't become evident. This helps immensely in the maintenance of an app, as well as in on boarding new team members who need to pick up and add new features, or help support older ones.

That's my thoughts on this. I'd be interested in hearing more. personally it comes down to ease of maintenance, expansion, and logical design.

from mantra-sample-blog-app.

payner35 avatar payner35 commented on August 16, 2024

im using dedicated routes in each of my modules.. no problem now.

The routes are defined in my configs folder as normal..

then my index.js sets them up

import methodStubs from './configs/method_stubs';
import actions from './actions';
import routes from './configs/routes.jsx';


export default {
  routes,
  actions,
  load(context) {
    methodStubs(context);
  }
};

from mantra-sample-blog-app.

firrae avatar firrae commented on August 16, 2024

I moved to the same concept @payner35, I just saw @arunoda request opinions and I'm an opinionated person at time on certain topics 😛

from mantra-sample-blog-app.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.