(
ecModel: GlobalModel,
mainType: ComponentMainType,
userOption: QueryReferringUserOption,
opt?: QueryReferringOpt
)
| 936 | }; |
| 937 | |
| 938 | export function queryReferringComponents( |
| 939 | ecModel: GlobalModel, |
| 940 | mainType: ComponentMainType, |
| 941 | userOption: QueryReferringUserOption, |
| 942 | opt?: QueryReferringOpt |
| 943 | ): { |
| 944 | // Always be array rather than null/undefined, which is convenient to use. |
| 945 | models: ComponentModel[]; |
| 946 | // Whether there is indexOption/id/name specified |
| 947 | specified: boolean; |
| 948 | } { |
| 949 | opt = opt || SINGLE_REFERRING as QueryReferringOpt; |
| 950 | let indexOption = userOption.index; |
| 951 | let idOption = userOption.id; |
| 952 | let nameOption = userOption.name; |
| 953 | |
| 954 | const result = { |
| 955 | models: null as ComponentModel[], |
| 956 | specified: indexOption != null || idOption != null || nameOption != null |
| 957 | }; |
| 958 | |
| 959 | if (!result.specified) { |
| 960 | // Use the first as default if `useDefault`. |
| 961 | let firstCmpt; |
| 962 | result.models = ( |
| 963 | opt.useDefault && (firstCmpt = ecModel.getComponent(mainType)) |
| 964 | ) ? [firstCmpt] : []; |
| 965 | return result; |
| 966 | } |
| 967 | |
| 968 | if (indexOption === 'none' || indexOption === false) { |
| 969 | if (opt.enableNone) { |
| 970 | result.models = []; |
| 971 | return result; |
| 972 | } |
| 973 | else { |
| 974 | // Do not throw; consider if some component previously does not use this method, |
| 975 | // and start to use it, need to be fault-tolerant for backward compatibility. |
| 976 | if (__DEV__) { |
| 977 | error('`"none"` or `false` is not a valid value on index option.'); |
| 978 | } |
| 979 | indexOption = -1; // Can not query by index but may still query by id/name if specified. |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | // `queryComponents` will return all components if |
| 984 | // both all of index/id/name are null/undefined. |
| 985 | if (indexOption === 'all') { |
| 986 | if (opt.enableAll) { |
| 987 | indexOption = idOption = nameOption = null; |
| 988 | } |
| 989 | else { |
| 990 | if (__DEV__) { |
| 991 | error('`"all"` is not a valid value on index option.'); |
| 992 | } |
| 993 | indexOption = -1; |
| 994 | } |
| 995 | } |
no test coverage detected
searching dependent graphs…