( prevApi: Api | undefined, nextApi: Api | undefined, prevData: any, nextData: any )
| 852 | } |
| 853 | |
| 854 | export function isApiOutdated( |
| 855 | prevApi: Api | undefined, |
| 856 | nextApi: Api | undefined, |
| 857 | prevData: any, |
| 858 | nextData: any |
| 859 | ): nextApi is Api { |
| 860 | if (!nextApi) { |
| 861 | return false; |
| 862 | } |
| 863 | |
| 864 | // 通常是编辑器里加了属性,一开始没值,后来有了 |
| 865 | if (prevApi === undefined) { |
| 866 | return true; |
| 867 | } |
| 868 | |
| 869 | nextApi = normalizeApi(nextApi); |
| 870 | prevApi = (prevApi ? normalizeApi(prevApi) : prevApi) as ApiObject; |
| 871 | |
| 872 | if (nextApi.autoRefresh === false) { |
| 873 | return false; |
| 874 | } |
| 875 | |
| 876 | // api 本身有变化 |
| 877 | if ((prevApi && prevApi.url !== nextApi.url) || !prevApi) { |
| 878 | return !!( |
| 879 | isValidApi(nextApi.url) && |
| 880 | (!nextApi.sendOn || evalExpression(nextApi.sendOn, nextData)) |
| 881 | ); |
| 882 | } |
| 883 | |
| 884 | const trackExpression = nextApi.trackExpression ?? nextApi.url; |
| 885 | if (typeof trackExpression !== 'string' || !~trackExpression.indexOf('$')) { |
| 886 | return false; |
| 887 | } |
| 888 | |
| 889 | let isModified = false; |
| 890 | |
| 891 | if (nextApi.trackExpression || prevApi.trackExpression) { |
| 892 | isModified = |
| 893 | tokenize(prevApi.trackExpression || '', prevData) !== |
| 894 | tokenize(nextApi.trackExpression || '', nextData); |
| 895 | } else { |
| 896 | prevApi = buildApi(prevApi as Api, prevData as object, { |
| 897 | ignoreData: true |
| 898 | }); |
| 899 | nextApi = buildApi(nextApi as Api, nextData as object, { |
| 900 | ignoreData: true |
| 901 | }); |
| 902 | isModified = prevApi.url !== nextApi.url; |
| 903 | } |
| 904 | |
| 905 | return !!( |
| 906 | isModified && |
| 907 | isValidApi(nextApi.url) && |
| 908 | (!nextApi.sendOn || evalExpression(nextApi.sendOn, nextData)) |
| 909 | ); |
| 910 | } |
| 911 |
no test coverage detected