Is there a way to ensure that the build
method is always called by the client at the end of the command chain?
const foo = new Foo();
foo.bar().a() // I need to guarantee that the `build` method is invoked.
Check out the following code snippet:
interface IFoo {
bar(): IBar;
build(): string;
}
class Foo {
public commands;
constructor() {
this.commands = []
}
public bar(): any {
return new Bar(this);
}
public build(): any {
return this.commands.join(' ')
}
}
interface IBar {
a(): IFoo
}
class Bar {
private foo: Foo;
constructor(foo){
this.foo = foo;
}
public a(): IFoo {
this.foo.commands.push('something')
return
}
}