1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/open-hand-choerodon-ui

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
Group.tsx 2.2 КБ
Копировать Редактировать Исходные данные Просмотреть построчно История
HughHzWu Отправлено 3 лет назад 8afe7e4
import { action, computed, observable, ObservableMap } from 'mobx';
import Record, { EXPANDED_KEY } from './Record';
import { getIf } from './utils';
export default class Group {
readonly name: string | symbol;
parentName?: string | symbol;
readonly value: any;
parentValue?: any;
records: Record[];
readonly totalRecords: Record[];
// 子分组, 非同组
subGroups: Group[];
subHGroups?: Set<Group>;
// 父分组, 非同组
readonly parentGroup?: Group | undefined;
readonly index: number;
@observable state?: ObservableMap<string, any>;
// 同组下的树形子分组
children?: Group[] | undefined;
// 同组下的父分组
parent?: Group | undefined;
get isExpanded(): boolean {
return this.getState(EXPANDED_KEY) !== false;
}
set isExpanded(isExpanded: boolean) {
this.setState(EXPANDED_KEY, isExpanded);
}
get level(): number {
const { parent } = this;
if (parent) {
return parent.level + 1;
}
return 0;
}
@computed
get expandedRecords(): Record[] {
const { subGroups } = this;
if (subGroups.length) {
return subGroups.reduce<Record[]>((list, group) => {
const newList = list.concat(group.expandedRecords);
const { children } = group;
if (children && group.isExpanded) {
return children.reduce((childList, childGroup) => childList.concat(childGroup.expandedRecords), newList);
}
return newList;
}, []);
}
return this.records;
}
constructor(name: string | symbol, index: number, value?: any, parentGroup?: Group) {
this.index = index;
this.name = name;
this.value = value;
this.parentGroup = parentGroup;
this.records = [];
this.totalRecords = [];
this.subGroups = [];
}
getState(key: string): any {
const { state } = this;
return state && state.get(key);
}
@action
setState(key: string, value: any) {
if (value !== undefined || this.state) {
const state = getIf<Group, ObservableMap>(this, 'state', () => observable.map());
return state.set(key, value);
}
}
mergeState(newState: ObservableMap<string, any>) {
const state = getIf<Group, ObservableMap>(this, 'state', () => observable.map());
state.merge(newState);
}
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://gitlife.ru/oschina-mirror/open-hand-choerodon-ui.git
git@gitlife.ru:oschina-mirror/open-hand-choerodon-ui.git
oschina-mirror
open-hand-choerodon-ui
open-hand-choerodon-ui
1.6.4