Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/linbudu599/with-new-decorators
https://github.com/linbudu599/with-new-decorators
Last synced: 27 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/linbudu599/with-new-decorators
- Owner: linbudu599
- License: mit
- Created: 2022-10-24T07:16:36.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-27T05:53:36.000Z (almost 2 years ago)
- Last Synced: 2023-03-03T07:25:10.380Z (over 1 year ago)
- Language: JavaScript
- Size: 330 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# with-new-decorators
Deep dive in the [new ECMAScript Decorator](https://github.com/tc39/proposal-decorators), different kinds of decorators, new ones and old ones, and build IoC Container by various ways.
## With TypeScript
Please install TypeScript >= 5.0.0 to use new decorators.
```typescript
$ npm i typescript@beta
```IoC related samples:
- [IoC Related Samples](packages/with-typescript/ioc/)
And it would work like this(simplified):
```typescript
import { createApp } from "create-server";import { UserController } from "./Controllers/User.controller";
import { PetController } from "./Controllers/Pet.controller";
import { RootController } from "./Controllers/Root.controller";import { UserService } from "./Services/User.service";
const app = createApp(5999, {
controllers: [UserController, PetController],
services: [UserService],
});app.then((server) => {
server.on("listening", () => {
const serverBaseUrl = "http://localhost:5999";console.log(`✨✨✨ Server ready at ${serverBaseUrl} \n`);
});
});
```## With Babel
Install these dependencies to use new decorator proposals:
```bash
pnpm i @babel/cli @babel/core @babel/node @babel/preset-env @babel/plugin-proposal-decorators --save-dev
```Configure your `.babelrc` file like below:
```ini
{
"presets": ["@babel/preset-env"],
"plugins": [
[
"@babel/plugin-proposal-decorators",
{
// specify version to use latest impl
"version": "2022-03"
}
]
]
}
```Then you can use `babel-node` to execute javascript file, but `nodemon` can bring you better DX.
- [Common samples](packages/with-babel/samples/)
- [IoC related samples](packages/with-babel/ioc)