crux-wrapper
Version:
A React provider for your crux application
21 lines • 692 B
JavaScript
export class State extends EventTarget {
viewModel;
mergeViewModel;
constructor(viewModel, mergeViewModel = (state) => state) {
super();
this.viewModel = viewModel;
this.mergeViewModel = mergeViewModel;
}
getViewModel(selector = (model) => model) {
return selector(this.viewModel);
}
setViewModel(viewModel) {
this.viewModel = this.mergeViewModel(viewModel, this.viewModel);
this.dispatchEvent(new CustomEvent("updated"));
}
subscribe(callback) {
this.addEventListener("updated", callback);
return () => this.removeEventListener("updated", callback);
}
}
//# sourceMappingURL=state.js.map