kadirahq / mantra

Mantra - An Application Architecture for Meteor
https://kadirahq.github.io/mantra/
978 stars 52 forks source link

Transforming Mantra module into package #133

Open tomitrescak opened 8 years ago

tomitrescak commented 8 years ago

Hi, I have created an account-ui modue based on semantic ui. I aam trying to transform it into the NPM module (yet still preserving Mantra structure and functionality) but I am running into little difficulties. Would you advise how can we solve following:

  1. The context and actions that are injected to the imported module are those of the App, not those of the module. Therefore, how can I register e.g. actions or context extensions with the app, so that container contained in the package accesses them when it is being rendered?

Is there any guideline on how should the process of transofrming module to NPM package be done?

tomitrescak commented 8 years ago

What I do now is that I export the module definition "index.js" from the NPM package and I register this module with mantra app. The drawback of this is that:

  1. Package action names can clash when more packages are used (need for the unique naming)
  2. The app context has to contain all the elements expected by the package.
arunoda commented 8 years ago

I think you can simply wrap the module as it the way it is now. Only issue is you can't use CSS using the meteor way.

The way how you can load the module.

import coreModule from './modules/core';
import accounts-ui from 'mantra-accounts-ui';

// init context
const context = initContext();

// create app
const app = createApp(context);
app.loadModule(coreModule);
app.loadModule(accountsUI);
app.init();

The way you can use a container.

import LoginScreen from 'mantra-accounts-ui/containers/login_screen';

....

<LoginScreen />

When doing this, this module should expect the App Context has Meteor field. Otherwise it's can throw an error when loading the module.

aykutyaman commented 8 years ago

@tomitrescak could you share sample code if it's not a private thing? I am also interested in the case.

adamdawkins commented 8 years ago

+1 El El jue, 10 mar 2016 a las 8:02, Aykut Yaman notifications@github.com escribió:

@tomitrescak https://github.com/tomitrescak could you share sample code if it's not a private thing? I am also interested in the case.

— Reply to this email directly or view it on GitHub https://github.com/kadirahq/mantra/issues/133#issuecomment-194722797.

tomitrescak commented 8 years ago

The code can be found here: https://github.com/tomitrescak/meteor-accountsui-semanticui-react.git

Please note that it is a work in progress, so it can break at any given time, so consider it only as a matter to discuss. My biggest problem with the Mantra approach in packages is that I have to import the code at different places:

  1. Import module and register it
  2. Import the container to view it
  3. Import the server part (methods and publications)

With Meteor packages you simply import the template and you are good to go.

Yet, I guess it is only matter of getting used to. Please leave your comments on the structure of this NPM package, and let me know what would you do differently.

And one off topic. How do you import "Session" ? which module is it part of? I tried to look in the meteor source but it is not clear to me.

aykutyaman commented 8 years ago

Thank you.

adamdawkins commented 8 years ago

Where I'm struggling here is when a module expects extra things in the client context. The only thing I can think of doing is adding a README detailing what is required, which is awful... unless context itself is made up of imported contexts?