Git Product home page Git Product logo

hmvc_loader's Introduction

hmvc_loader

A non opnionated HMVC loader for node. It traverses the folders indexing JS files trhough an MVC logic

Usage

Giving a structure like:

  • root
    • componentName1
      • controllers
        • A.js
      • models B.js
      • views C.js
      • components
        • componentName2
          • controllers
            • D.js

It loads the namespace on a sensible way, can be used to build urls or simply acess components by

Factory initialization

    const Loader = require('hmvc_loader').Loader
    const path = 'myPath/root'
    const myLoader = Loader.getLoaderFromPath(path)

Map initialization

    const Loader = require('hmvc_loader').Loader
    const componentMap = {'controllers':{'TheNameSpaceThatIWant':{'SomeElem€ntname':'file.js'}}}
    const myLoader = new Loader(componentMap)

Component loading

    //Acessing A 
    const aInstance = myLoader.getComponent('controllers','componentName1','A')
    //Acessing D
    const dInstance = myLoader.getComponent('controllers','componentName1/componentName2','D')
    //Notice how the components was sliced

URl handling

The motivation for this library is to make the components acessible within itself and to make urls based on the controllers Withing each controller you may expect an url on the form of

    namespace/controllerName 

And a map on the form of

{method:[param1,param2]}

so you can call it like this

    
    const urlBuilder = (url,methods,obj){
    }
    myLoader.buildRoutes(urlBuilder)

Making your own structur and creation

The factory function has the follow structure

   const factory = (loader, namespace, name, file) => {
       return new require(file)(someMongooseInstance, loader, namespace)
   }

hmvc_loader's People

Contributors

drfabio avatar

Stargazers

 avatar

Watchers

 avatar  avatar

hmvc_loader's Issues

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.