MCPcopy
hub / github.com/baidu/amis / isApiOutdated

Function isApiOutdated

packages/amis-core/src/utils/api.ts:854–910  ·  view source on GitHub ↗
(
  prevApi: Api | undefined,
  nextApi: Api | undefined,
  prevData: any,
  nextData: any
)

Source from the content-addressed store, hash-verified

852}
853
854export 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

Callers 15

componentDidUpdateMethod · 0.90
componentDidUpdateMethod · 0.90
componentDidUpdateMethod · 0.90
componentDidUpdateMethod · 0.90
componentDidUpdateMethod · 0.90
handleQueryMethod · 0.90
componentDidUpdateMethod · 0.90
componentDidUpdateMethod · 0.90
componentDidUpdateMethod · 0.90
componentDidUpdateMethod · 0.90
componentDidUpdateMethod · 0.90
componentDidUpdateMethod · 0.90

Calls 5

evalExpressionFunction · 0.90
normalizeApiFunction · 0.85
isValidApiFunction · 0.85
buildApiFunction · 0.85
tokenizeFunction · 0.70

Tested by

no test coverage detected