Call disambiguate on update/map

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-06-25 20:13:02 +05:30
parent bcb46fc54a
commit ef40027502

View file

@ -1,12 +1,14 @@
import {ViewModel} from "../../ViewModel.js"; import {ViewModel} from "../../ViewModel.js";
import {MemberTileViewModel} from "./MemberTileViewModel.js"; import {MemberTileViewModel} from "./MemberTileViewModel.js";
import {createMemberComparator} from "./comparator.js"; import {createMemberComparator} from "./comparator.js";
import {Disambiguator} from "./disambiguator.js";
export class MemberListViewModel extends ViewModel { export class MemberListViewModel extends ViewModel {
constructor(options) { constructor(options) {
super(options); super(options);
this.memberTileViewModels = this._mapTileViewModels(this._filterJoinedMembers(options.members)) this.memberTileViewModels = this._mapTileViewModels(this._filterJoinedMembers(options.members))
.sortValues(createMemberComparator(options.powerLevels)); .sortValues(createMemberComparator(options.powerLevels));
this.nameDisambiguator = new Disambiguator();
} }
_filterJoinedMembers(members) { _filterJoinedMembers(members) {
@ -14,10 +16,16 @@ export class MemberListViewModel extends ViewModel {
} }
_mapTileViewModels(members) { _mapTileViewModels(members) {
const mapper = (member, emitUpdate) => { const mapper = (member, emitChange) => {
return new MemberTileViewModel(this.childOptions({member, emitUpdate})); const vm = new MemberTileViewModel(this.childOptions({member, emitChange}));
this.nameDisambiguator.disambiguate(vm);
return vm;
} }
const updater = (vm, params, newMember) => vm.updateFrom(newMember); const updater = (vm, params, newMember) => {
vm.updateFrom(newMember);
this.nameDisambiguator.disambiguate(vm);
};
return members.mapValues(mapper, updater); return members.mapValues(mapper, updater);
} }
} }