Git Product home page Git Product logo

mantra-core's Introduction

#mantra-core

Core API for Mantra.

Introduction

This repo contains the core APP api where we create an mantra app and initialize it.

Also, this package contains exported functions from both react-komposer and react-simple-di. That's purely for the ease of use.

Installation

npm i --save mantra-core react

App API

import MyComp from './myComp';
import {createApp} from 'mantra-core';

// Here's a simple Mantra Module
const module = {
  routes(injectDeps) {
    const InjectedComp = injectDeps(MyComp);
    // load routes and put `InjectedComp` to the screen.
  },
  load(context, actions) {
    // do any module initialization
  },
  actions: {
    myNamespace: {
      doSomething: (context, arg1) => {}
    }
  }
};

const context = {
  client: new DataClient()
};

const app = createApp(context);
app.loadModule(module);
// app.loadModule(someOtherModule);
app.init();

mantra-core's People

Contributors

arunoda avatar roonyh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mantra-core's Issues

Bug while separating route declarations into several modules

I have a main layout that renders a navigation bar and the content related to each route. The navigation bar is animated when rendered for the first time (Using Animate.css). When the user first goes to /, the index page is rendered and the navigation bar should animate down from the top of the window.

This works perfectly if I declare all my routes inside a single routes.js, but it seems not to work if I declare some routes in one module and the rest in another module. It seems that switching between routes that are not declared in the same file, re-renders the whole main layout (including the top bar). This behaviour results in the navigation bar animating "up" and down in some cases. I though maybe this behaviour comes from how mantra-core (or FlowRouter) handles things behind the scenes, correct me if I'm wrong.

Example illustrating the behaviour is seen below (The image is a GIF, try clicking on it if it is behaving like a static image). The route linked to the GrandView button is declared within an index module and the rest are declared within a core module.

5e7a9dbe-b713-4220-9cd7-38f126cc90f9-11065-00006ace3b0f2775

Problems with Meteor 1.6?

I've been trying to apply mantra architecture to one of my meteor apps, but I've my context is returning as undefined when wrapping my component with injectDeps...

Other apps I've worked on have all had Meteor versions < 1.6, so has anyone had any luck working with mantra-core with Meteor 1.6?

Upgrading to Meteor 1.3 doesn't work

I was running the Meteor 1.3-beta.11 and using mantra-core just fine. Recently the official 1.3 build was released. When I do meteor update it seems to break. I'm getting this error:

Unable to resolve some modules:

  "lib/CSSTransitionReplace.js" in            
/Users/hl/web-dev/meteor/olis-mantra/node_modules/react-css-transition-replace/package.json
(web.browser)
  ".dist/browser.js" in                       
/Users/hl/web-dev/meteor/olis-mantra/node_modules/mantra-core/node_modules/react-komposer/package.json
(web.browser)

Consider running: meteor npm install --save lib

And in my browser console

Uncaught Error: Cannot find module 'react-komposer'

I did try doing meteor npm install --save lib, but still getting the same errors.

Basic support for modularity using react-router

I have a proposition on how mantra could support react-router (as discussed here) while maintaining modularity and not changing the mantra API at all.

We can use the "huge apps" pattern to do the route setup inside the mantra modules (routes.jsx as it is now).

The only thing we'd need to do is return the resulting route configuration here like this:

const routes = this._routeFns.map(routeFn => {
  const inject = comp => {
    return injectDeps(this.context, this.actions)(comp);
  };
  return routeFn(inject, this.context, this.actions);
});

this._routeFns = [];
this.__initialized = true;

return routes;

Or, if you plan to use to return something else from init() in the future:

return { routes };

Then one could use the react route objects to build up the react-router root like this:

const {routes} = app.init();

const rootRoute = {
  childRoutes: [ {
    path: '/',
    component: require('./components/App'),
    childRoutes: routes
  } ]
}

render((
  <Router
    history={browserHistory}
    routes={rootRoute}
  />
), document.getElementById('react-root'))

I think this would provide a great deal of flexibility and open the way for users who want to use react-router (or any other routing library for that matter) using a minimal invasive change.

I'd be happy to discuss this further and also eventually provide a PR for this. Let me know what you think.

Actions with the same export name will be overwritten

For example, I have a projects action in core module for following/commenting projects, I also have a projects action in admin module for adding/editing projects

However, if I export these actions with same name from two different modules, one of them will be overwritten. Probably the better way is to merge them, not to overwrite one of them.

If this is considered as a bug, I can submit a PR to fix it.

deprecate imports from mantra-core

I'm wondering if the pulled in imports from react-simple-di and react-komposer should perhaps be deprecated?

Right now react-komposer is on version 1.9.0 and there are some pending pr's for react-simple-di. I'm concerned this repo that imports them into mantra-core package will always be slightly outdated unless an automated build is setup. Since this is the case, I'm wondering if these wrapper functions should be deprecated.

Module definition file : load method is mandatory in order to pass context by DI

Hi,

it would be interesting to note that the load method is mandatory (must be at least declared even without body) in the module definition file if we want to pass context by DI.

In your sample :

const module = {
routes(injectDeps) {
const InjectedComp = injectDeps(MyComp);
// load routes and put InjectedComp to the screen.
},
load(context) {
// don't forget this declaration or you won't be able to have your context in your containers !.
}
,
actions: {
myNamespace: {
doSomething: (context, arg1) => {}
}
}
};

Best regards,
Lawrence.

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.