Quick Start for Mantra Newbies


#1

As a Mantra newbie myself, I have recently acquired some helpful tips for getting started with Mantra, thanks to great advice from many here and on the Github Mantra issues board.

  1. Do not pass go, do not collect $200, go directly to Mantra CLI and use it to construct the directory structure and initial code of your Mantra app. This can save you about a week if you are a total Mantra newbie like me.

  2. Data is passed from Container to Component via the composer function. Example:

    export const composer = ({context, clearErrors, planetID}, onData) => {
    const {Meteor, Collections} = context();
    if (Meteor.subscribe(‘planets’, planetID).ready()) {
    const options = {
    sort: {createdAt: -1}
    };
    const planets = Collections.planets.find({planetID}, options).fetch();
    onData(null, {planets}); //<==PASSES planets COLLECTION TO COMPONENT
    } else {
    onData();
    }
    };

I hope this is helpful. If I have gotten anything wrong, I hope others here will correct the error. And of course if anyone has additional tips for Mantra newbies, this might be a possible thread in which to post them.


#2

I think we’re in the same shoes, and you’re right, mantra CLI is incredibly helpful!

I have only one question I couldn’t find out: how to pass arguments to a container? i.e.:

import MyContainer from '../containers/my_container.js';
// ...
<MyContainer foo={bar} />

How can I access foo inside the container? For example in your code where does planetID come from?


#3

As soon as I find out I will post the info here. If you find out first, please do the same. Thanks!


#4

It seems it’s quite easy:

<MyContainer foo={bar} />
export const composer = ({context, foo}, onData) => {
  // foo === bar

#5

@cziszi, do you have any sort of accounts-ui (user registration/login/etc) working yet?


#6

Here’s a couple of new tips I’ve noticed in the past week. These are extreme newbie tips. At the same time of course, many people coming to Meteor/Mantra for the first time might find them helpful.

  • If you download code to a Meteor sample app, in many cases the terminal command npm install will identify and download all npm package dependencies needed by the app.

  • At this moment there’s no https://www.meteor.com/accounts plugin for React—they all want to run in Blaze. But there’s still a fast way to get user accounts working. You can use them in your Mantra app via @gadicc’s gadicc:blaze-react-component.


#7

It’s been a few weeks and I now am successfully accessing most of Mantra:

  • Containers
  • Components
  • Collections, both reading from and writing to
  • Actions
  • Publications
  • Methods

I guess the most important thing I’ve learned so far is:

Don’t merely use mantra-cli from time to time to create a component or container here or there. Use mantra-cli to create your initial empty application folder, and use it every time you add a component, container, action, etc. This will save you an enormous amount of time, as it can be very tricky figuring out all the many things Mantra/React needs to have set up, in order to launch any part of the app.