bitloops-language
bitloops-language copied to clipboard
'this' has limitations inside bl constructor
Subject of the issue
this has limitations of usage inside the constructor. See an example below:
Steps to reproduce
If anyone types this in bl:
ValueObject TitleVO {
constructor(props: TitleProps): (OK(TitleVO), Errors(DomainErrors.TitleOutOfBoundsError)) {
const title = this.toUpperCase(props.title);
applyRules(TitleOutOfBoundsRule(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);
const title = this.toUpperCase(props.title);
}
public static create(props: TitleProps): Either<TitleVO, DomainErrors.TitleOutOfBounds> {
const res = Domain.applyRules([new Rules.TitleOutOfBounds(title)]);
if (res) return fail(res);
return ok(new TitleVO(props));
}
private toUpperCase(title: string) {...}
}
Expected behaviour
I should be able to do something like the above in bl.
Actual behaviour
this.props.title in create will produce an error, because it is set in the static create method and this is not set yet.
Suggested solutions?
Redesign bl language to have both constructor and create in domain?