Giter Club home page Giter Club logo

rakia's Introduction

RakiaJS

Minimalistic module loader based on require-all and BottleJS

Usage

Creating a static value

module.exports = {
  name: "someData",
  type: "value",
  call: "Hello World!"
}

Creating a service factory

module.exports = {
  name: "someFactory",
  type: "factory",
  requires: ["someData"],
  call: function(container)
  {
    //factories get the container as argument
    var someFactory = function(data){
      this.data = data
    }
    return new someFactory(container.someData)
  }

}

Creating a service provider

module.exports = {
  name: "someProvider",
  type: "provider",
  requires: ["someFactory","someData"],
  call: function(someFactory,someData)
  {
    var factoryPolyfill = () => "Hello world!",

    //replace HelloWorld with a polyfill if we're missing data
        helloWorld = someData ? factory : factoryPolyfill

    // this is the service factory
    this.$get = function(container){
      return {
        helloWorld
      }
    }
  }
}

Creating a service

module.exports = {
  name: "someService",
  type: "service",
  requires: ["someProvider"],
  call:function(someProvider){

    this.helloWorld = someProvider.helloWorld

  }
}

Tying it all together

var rakia = require('rakia'),
    application = rakia(__dirname+'/data', 
                        __dirname+'/services',
                        __dirname+'/factories', 
                        __dirname+'/providers')
                        
// Returns "Hello World" 
application.container.someService.helloWorld()

Module properties

property description values Required
name Module name, must be unique to namespace Any valid string Yes
type Import level, see BottleJS for type description value, constant, provider, factory, service, middleware, decorater Yes
requires Array of names to import to module call Array of string names No
call Value or module constructor Any function Yes

Installation

From Github

git clone https://github.com/Flubbex/rakia.git
cd rakia && npm install

To import:

var rakia = require('./rakia')
var application = rakia()

Dependencies

rakia's People

Contributors

flubbex avatar

Watchers

James Cloos avatar  avatar

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.