Answer the question
In order to leave comments, you need to log in
How to improve the tree processing module?
updateChildren(model, modes) {
model.get('children').forEach(child => {
if (child.has('children')) {
modes.forEach(mode => this[mode.actionName](child, mode));
this.applyTreeModes(child, modes);
}
});
},
setCollapsed(model, options) {
const { value, expandedConfiguration, save, reqres } = options;
const currentValue = (typeof value === 'boolean') ? value : NavigationItemFactory.getCollapsed(expandedConfiguration, model.get('id'));
model.set('collapsed', currentValue);
if (save) {
reqres.request('configuration:collapsed:save', model);
}
},
setCurrentEdited(model, options) {
const { value } = options;
model.set('currentEdited', value);
},
setChecked(model, options) {
const { value } = options;
model.set('checked', value);
},
setFilterChecked(model, options) {
const { value, filter } = options;
if (filter.length === 0 || filter.indexOf(model.get('id')) !== -1) {
model.set('checked', value);
}
},
formSelectedConfiguration(model, options) {
const { selectedConfiguration } = options;
if (model.get('checked')) {
selectedConfiguration.push(model.get('id'));
}
}
async __editMode() {
this.model.set('editMode', !this.model.get('editMode'));
const editMode = this.model.get('editMode');
if (editMode) {
await this.reload({ editMode: editMode });
TreeService.updateChildren(this.model, [
{ actionName: 'setFilterChecked', value: true, filter: this.configuration.selectedConfiguration || [] },
{ actionName: 'setCurrentEdited', value: true },
{ actionName: 'setCollapsed', value: false, save: true, reqres: this.reqres }
]);
} else {
const selectedConfiguration = [];
TreeService.updateChildren(this.model, [
{ actionName: 'setCurrentEdited', value: false },
{ actionName: 'formSelectedConfiguration', selectedConfiguration }
]);
this.__applyConfigurationChanges(selectedConfiguration, false);
}
}
Answer the question
In order to leave comments, you need to log in
This is all not typed - no specific classes / functions, but 'setCurrentEdited' is passed by name, which you need to search for by text search, and its options value: false - bad from the point of view of architecture
.. but it depends on your tasks, you can leave it like that , if you don’t need to return to this too often, in principle you can understand, but then at least all these classes are in a separate directory, and there are no extra dependencies, otherwise
ps will grow and model, modes are a very bad name, in 1x this difference is only in one character, and there will be confusion in the body of the method (someone will miss the last letter), I’ll tell you purely from experience
, besides, modes doesn’t say at all what kind of mode
is better - actions
what to
- scalability
- speed
.. then you should measure it in your own conditions.. afraid of slow interpretation of dynamic function names and passing parameters to them? read the docs, maybe someone else will answer
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question