almin / almin/ddd-base

Entity/ValueObject: receive Props Instead of Identifier

Abierto
#4 5 comentarios 0 reacciones 0 asignados Ver en GitHub
Status: Proposal
Lenguaje dominante
TypeScript
Estrellas
77
Forks
7
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

I've noticed that I often write a entity like following:

```ts
export class HatebuIdentifier extends Identifier {}
export interface HatebuProps {
readonly id: HatebuIdentifier;
readonly bookmark: Bookmark;
}

export class Hatebu extends Entity implements HatebuProps {
readonly bookmark: Bookmark;

constructor(args: HatebuProps) {
super(args.id);
this.bookmark = args.bookmark;
}

get name() {
return this.id.toValue();
}

addBookmarkItems(bookmarkItems: BookmarkItem[]) {
return new Hatebu({
...(this as HatebuProps),
bookmark: this.bookmark.addBookmarkItems(bookmarkItems)
});
}

updateBookmarkItems(bookmarkItems: BookmarkItem[]) {
return new Hatebu({
...(this as HatebuProps),
bookmark: this.bookmark.updateBookmarkItems(bookmarkItems)
});
}
}
```

This `Hatebu` entity has id and Props type.
We can use `Props` type insteadof `Id`.
Becaseue, Alwasys `Props` includes `id`.

## Props

- We can realize mixin meaningful #5
- `Copyable` insterface just use `Props` type
- It is similar with React https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L287-L288

## Cons

- `id` is fixed name
- Always arguments is object

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.