0.0.1 • Published 6 years ago

@botorjs/cord v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

Cord

Build Status Coverage Status

Library that core of Botorjs is connect component using Boot

Installation

npm install @botorjs/cord --save

Setup and Example

  • Folder
project
└───services
│   │   Service.ts
└───providers
│   │   ProviderTest.ts
└───start
│   │   app.ts
|
│   .env
|   index.ts
  • Service.ts
    export class ServiceTest {
        private _count: number;

        constructor() {
            this._count = 0;
        }

        public get count(): number {
            return this._count
        }

        public inc() {
            this._count++;
        }

        public sub() {
            this._count--;
        }
    }
  • ProviderTest.ts
    import { ServiceProvider, Boot } from '@botorjs/boot';
    import { ServiceTest } from '../services/Service';

    export class ProviderTest extends ServiceProvider {
        
        register(app: Boot) {
            app.ioc.singleton(ServiceTest.name, ServiceTest)
            app.alias.add("service", ServiceTest);
        }

        boot(app: Boot) {
            const service = app.ioc.get<ServiceTest>(ServiceTest);
            service.inc();
        }
    }
  • app.ts
    import { App } from '@botorjs/cord';
    import { ProviderTest } from '../providers/ProviderTest';

    const app: App = {
        providers: [
            ProviderTest
        ],
        aliases: {
            "APP_PATH": "ROOT",
        },
    }
    export = app;
  • .env
    TEST_ENV=test
  • index.ts
    import { App, Cord } from '@botorjs/cord';


    var cord: Cord = new Cord();

    cord.boot.hook.on("start", () => {
        console.log("start work");
    })

    cord.root(__dirname)
        .preload()
        .fire();

    var service =  cord.boot.get<ServiceTest>(ServiceTest);
    expect(service.count).to.eql(1);
    service.sub();
    expect(service.count).to.eql(0);

    var env: Env = cord.boot.get<Env>(Env);
    var val =  env.get("TEST_ENV");
    expect(val).to.eql("test");

API

Cord

  • Cord is backgroud connect to component
PropertyDescription
configget config cord
bootget Boot
root(folder)set folder root of appliction
preload()Preload application, it will load the ServiceProvider to Boot and load Alisa to boot. Load environment and file .env (defaul config) to Env and add to IoC of Boot
firecall event to system notification start application

Env

  • load config in file .env(default) to environment and get set environment
PropertyDescription
getget value environment
setset value environment

ConfigCord

  • load config in file .env(default) to environment and get set environment
PropertyDescriptionDefaul
start_folderFolder the file start is config input of component"start"
app_filesFile config provider of Boot"app.ts"
rootRoot folder of applicationnull
env_fileFile environment of application".env"

App

  • Config default of App
PropertyDescription
providersthe ServiceProvider of Boot
aliasesthe alias of Boot