'this' has limitations inside bl constructor
Brought to you by:
sergiopreira
Originally created by: ellik95
this has limitations of usage inside the constructor. See an example below:
If anyone types this in bl:
ValueObject TitleVO {
constructor(props: TitleProps): (OK(TitleVO), Errors(DomainErrors.TitleOutOfBoundsError)) {
this.title = this.toUpperCase(props.title);
applyRules(TitleOutOfBoundsRule(this.title));
}
private toUpperCase() {...}
}
In typescript will be generated this:
export class TitleVO extends Domain.ValueObject<TitleProps> {
get title(): string {
return this.props.title;
}
private constructor(props: TitleProps) {
super(props);
this.props.title = this.toUpperCase(props.title);
}
public static create(props: TitleProps): Either<TitleVO, DomainErrors.TitleOutOfBounds> {
const res = Domain.applyRules([new Rules.TitleOutOfBounds(this.props.title)]);
if (res) return fail(res);
return ok(new TitleVO(props));
}
private toUpperCase(title: string) {...}
}
I should be able to do something like the above in bl.
this.props.title in create will produce an error, because it is set in the static create method and this is not set yet.
Redesign bl language to have both constructor and create in domain?