What is the most effective way to access the store within a facade base class, allowing for the encapsulation of commonly used methods for interacting with the store?
Imagine we have a store (repository)
export class SomeRepository {
private readonly store;
constructor() {
this.store = createStore()
}
}
And we have a facade that extends from a base facade
export abstract class BaseFacade {
protected store: ReturnType<typeof createStore>;
constructor(protected store: ReturnType<typeof createStore>) {
this.store = store;
}
setEntity(entity: SomeEntity) {
this.store.update(setEntities(entity))
}
}
With an implementation of a Concrete Class
@Injectable({ providedIn: 'root'})
export class SomeFacade extends BaseFacade {
constructor(protected store: Store<SomeRepository>) { <---- I am facing difficulties here, unsure how to utilize the store
super(store)
}
}
In a component
export class SomeComponent implements OnInit {
constructor(private readonly facade: SomeFacade) {}
ngOnInit() {
const entity = { name: 'Jon', age: 30 };
this.facade.setEntity(entity); <----- This allows us to use methods from the abstract class without needing to implement them each time a Facade class is defined
}
}