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 interface Type<T = any> { | |
new (...args: any[]): T; | |
} | |
class Container { | |
public dependencies = []; | |
public init(deps: any[]) { | |
deps.map((target) => { | |
const isInjectable = Reflect.getMetadata('injectable', target); |
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
const reflectObj = {}; | |
function Injectable() { | |
return function (target: any) { | |
console.log('Injectable'); | |
Reflect.defineMetadata('injectable', true, target); | |
reflectObj[target] = true; | |
}; | |
} |
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 { SetMetadata } from '@nestjs/common'; | |
export const IS_PUBLIC_KEY = 'isPublic'; | |
export const Public0 = () => SetMetadata(IS_PUBLIC_KEY, true); // nestjs way | |
export const reflectObj = {}; | |
// custome way | |
export function Public() { | |
return function ( |
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
@Module({ | |
providers: [ | |
{ | |
provide: 'MY_TIMEOUT', | |
useFactory: () => { | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
resolve(true) | |
}, 10000); | |
}) |
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 { ICommand } from './command.interface'; | |
export interface ICommandHandler<TCommand extends ICommand = any, TResult = any> { | |
execute(command: TCommand): Promise<TResult>; | |
} |
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
@CommandHandler(AddProductToCartCommand) | |
export class AddProductToCartCommandHandler implements ICommandHandler<AddProductToCartCommand> { | |
constructor(private eventBus: EventBus) {} | |
async execute(command: AddProductToCartCommand): Promise<void> { | |
// ... | |
} | |
} |
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 { delay } from 'redux-saga'; | |
import { takeEvery, put } from 'redux-saga/effects'; | |
function* ageUpAsync() { | |
yield delay(4000); | |
yield put({ type: 'AGE_UP_ASYNC', value: 1 }) | |
} | |
export function* watchAgeUp() { | |
yield takeEvery('AGE_UP', ageUpAsync); |
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
// with thunk, instead of returning an object, we can return a function (for async tasks) | |
const callHttp = () => { | |
return function (dispatch) { | |
dispatch(beforeCall()) | |
axios.get() | |
.then((res) => { | |
dispatch(afterSuccess(res.data)) | |
}) | |
.catch((error) => { | |
dispatch(afterFail(error.message)) |
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
const mapDispatchToProps = (dispatch) => { | |
return { | |
deletePost: (id) => dispatch({type: 'DELETE_POST', id: id}), | |
addPost: (post) => dispatch({type: 'ADD_POST', post: post}) | |
} | |
} |
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 { CashifyOptionsFactory } from 'nestjs-cashify'; | |
@Injectable() | |
export class CashifyConfigService implements CashifyOptionsFactory { | |
constructor(private configService: ConfigService) {} | |
createCashifyOptions() { | |
const rates = { | |
GBP: 0.92, | |
EUR: 1.00, |
NewerOlder