0.0.67 • Published 2 months ago

@easegram/framework v0.0.67

Weekly downloads
-
License
ISC
Repository
github
Last release
2 months ago

@easegram/framework

Get Start

Install

npm install @easegram/framework --save

Setup App

import {AppEvents, Application} from "@easegram/framework"

const main = async () => {
    const app = new Application({
        name: "test-app",
        modulePaths: ["dist/"]
    })

    app.events.on(AppEvents.Init, ()=>{
        console.log(`app init.`)
    })
    
    app.events.on(AppEvents.Ready, ()=>{
        console.log(`app ready.`)
    })
    
    app.events.on(AppEvents.Quit, ()=>{
        console.log(`app quit.`)
    })
    
    app.events.on(AppEvents.Tick, (delta: number)=>{
        console.log(`app running: ${app.time}`)
    })

    await app.run()
}

main();

IoC

  • Define a IoC object
import { IocDefine } from "@easegram/framework";

@IocDefine() // Define a object named 'A'.
@IocDefine('Instance-A') // Define a object named 'Instance-A'.
export class A {
    
}

//...
{
    const a = app.container.get('A')
    const instance = app.container.ge('Instance-A');
}
  • IoC object and field injections.
import { IocDefine, IocInject } from "@easegram/framework";


@IocDefine() // Define a object named 'A'.
@IocDefine('Instance-A') // Define a object named 'Instance-A'.
export class A {

}

@IocDefine() // Define a object named 'B'.
export class B {
    @IocInject() // Inject value with the object 'A'.
    private a: A;
    
    @IocInject('Instance-A') // Inject value with the object 'Instance-A'.
    private instanceA: A;

    start() {
        console.log(this.a);
        console.log(this.instanceA);
    }
}

Http Service

import {AppEvents, Application, IocDefine} from "@easegram/framework"
import {HttpService, HttpServiceOptions, HttpGet} from "@easegram/framework";

/**
 * Define a http route handler class
 * */
@IocDefine
class Hello {

    // Define a route handler
    // It is equivalent to: koa.router.get('/hello', http.handler(hello))
    @HttpGet('/hello')
    async hello({name}) {
        return `hello ${name}`
    }
    
}

// In main function
app.events.on(AppEvents.Ready, () => {
    // Install HttpService with args
    app.install('http', HttpService, {
        args: {
            name: 'http',
            host: '0.0.0.0',
            port: 80,
            log: true,
            cors: true,
            proxy: false
        },
        routes: [Hello]
    });

    // Construct and Get HttpService instance
    app.get<HttpService>('http');
})

For Developers

Build

npm run build

Publish

npm run publish

License

MIT License

0.0.65

2 months ago

0.0.66

2 months ago

0.0.67

2 months ago

0.0.63

2 months ago

0.0.64

2 months ago

0.0.62

4 months ago

0.0.60

4 months ago

0.0.61

4 months ago

0.0.59

4 months ago

0.0.57

4 months ago

0.0.58

4 months ago

0.0.56

5 months ago

0.0.55

5 months ago

0.0.54

5 months ago

0.0.53

5 months ago

0.0.52

5 months ago

0.0.51

5 months ago

0.0.50

5 months ago

0.0.49

5 months ago

0.0.48

6 months ago

0.0.47

6 months ago

0.0.46

6 months ago

0.0.45

6 months ago

0.0.44

6 months ago

0.0.43

6 months ago

0.0.42

6 months ago

0.0.41

6 months ago

0.0.40

6 months ago

0.0.39

6 months ago

0.0.38

6 months ago

0.0.37

6 months ago

0.0.36

6 months ago

0.0.35

6 months ago

0.0.34

6 months ago

0.0.33

6 months ago

0.0.32

6 months ago

0.0.31

6 months ago

0.0.30

6 months ago

0.0.29

6 months ago

0.0.28

6 months ago

0.0.27

6 months ago

0.0.26

6 months ago

0.0.25

6 months ago

0.0.24

6 months ago

0.0.23

6 months ago

0.0.22

6 months ago

0.0.21

6 months ago

0.0.20

6 months ago

0.0.19

6 months ago

0.0.18

6 months ago

0.0.17

6 months ago

0.0.16

6 months ago

0.0.14

6 months ago

0.0.13

6 months ago

0.0.12

6 months ago

0.0.11

6 months ago

0.0.10

6 months ago

0.0.9

6 months ago

0.0.8

6 months ago

0.0.7

6 months ago

0.0.6

6 months ago

0.0.5

6 months ago