Skip to content

Instantly share code, notes, and snippets.

View vahidvdn's full-sized avatar
🏠
Working from home

Vahid Najafi vahidvdn

🏠
Working from home
  • Berlin, Germany
View GitHub Profile
<div>test</div>
@vahidvdn
vahidvdn / gist:d776bbb029085b0c0eb0668226607bac
Last active December 12, 2021 12:19
Angular relation between component - Car
@Component({
selector: 'car',
template: '<wheel color="color"></wheel>',
})
export class CarComponent implements OnInit {
color: string = 'red';
}
@Component({
selector: 'wheel',
import { CashifyOptionsFactory } from 'nestjs-cashify';
@Injectable()
export class CashifyConfigService implements CashifyOptionsFactory {
constructor(private configService: ConfigService) {}
createCashifyOptions() {
const rates = {
GBP: 0.92,
EUR: 1.00,
const mapDispatchToProps = (dispatch) => {
return {
deletePost: (id) => dispatch({type: 'DELETE_POST', id: id}),
addPost: (post) => dispatch({type: 'ADD_POST', post: post})
}
}
// 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))
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);
@CommandHandler(AddProductToCartCommand)
export class AddProductToCartCommandHandler implements ICommandHandler<AddProductToCartCommand> {
constructor(private eventBus: EventBus) {}
async execute(command: AddProductToCartCommand): Promise<void> {
// ...
}
}
import { ICommand } from './command.interface';
export interface ICommandHandler<TCommand extends ICommand = any, TResult = any> {
execute(command: TCommand): Promise<TResult>;
}
@Module({
providers: [
{
provide: 'MY_TIMEOUT',
useFactory: () => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(true)
}, 10000);
})
@vahidvdn
vahidvdn / public-api.decorator.ts
Last active February 21, 2024 15:54
Custom Public Decorator instead of nestjs
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 (