mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2025-01-08 09:14:55 +02:00
933f289250
Дополнение
1.6 KiB
1.6 KiB
Program invocation of form event handler
Assign a handler for each event. If different actions are required in case of events in different form items:
- Create a separate procedure or a function that executes the required action.
- Сreate a separate handler with a default name for each form item.
- Call the required procedure or function from each handler.
Noncompliant Code Example
&AtClient
Procedure ByPerformerOnChange(Item)
FilterParameters = New Map();
FilterParameters.Insert("ByAuthor", ByAuthor);
FilterParameters.Insert("ByPerformer", ByPerformer);
SetListFilter(List, FilterParameters);
EndProcedure
&AtClient
Procedure ByAuthorOnChange(Item)
ByPerformerOnChange(Undefined);
EndProcedure
Compliant Solution
&AtClient
Procedure ByPerformerOnChange(Item)
SetFilter();
EndProcedure
&AtClient
Procedure ByAuthorOnChange(Item)
SetFilter();
EndProcedure
&AtServer
Procedure SetFilter()
FilterParameters = New Map();
FilterParameters.Insert("ByAuthor", ByAuthor);
FilterParameters.Insert("ByPerformer", ByPerformer);
SetListFilter(List, FilterParameters);
EndProcedure
These requirements are provided as logically event handlers are not intended for use in the module code but are called directly by the platform. If you mix these two scenarios in a single procedure, its logic gets complicated and decreases its stability. Instead of one predefined call scenario by an event from the platform, the procedure code needs to consider other "direct" calls from the code.