This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We can also use async/await which is a Syntactic Sugar For Promises | |
var addC = function (a, b) { | |
return new Promise((resolve, reject) => { | |
setTimeout (() => { | |
resolve(a + b); | |
}, 0); | |
}); | |
}; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {MongoClient} from 'mongodb'; | |
import UserController from './controller/user-controller'; | |
import UserService from './service/user-service' | |
import MongoDriver from './service/db-service'; | |
import Config from './service/config-service'; | |
export const config = { | |
constructor: () => new Config(process.env), | |
tags: ['boot'] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Container from './container'; | |
export default class Kernel { | |
constructor(builder) { | |
this.container = new Container(builder); | |
} | |
/** | |
* Boot the kernel, load all services | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class Container { | |
constructor(builder) { | |
this.services = new Map(); | |
if (builder !== undefined) { | |
Object.keys(builder).forEach(name => this.register(name, builder[name])); | |
} | |
} | |
/** | |
* Register a service |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Kernel from './kernel'; | |
import * as ServiceBuilder from './service'; | |
(async () => { | |
const kernel = new Kernel(ServiceBuilder); | |
await kernel.boot(); | |
await kernel.container.get('db').save('product', {}, {id: 1, name: 'ssssscar'}); | |
})(); |
OlderNewer