Update templates and replace lodash with underscore in odata

This commit is contained in:
Like Zhu 2021-07-29 16:02:05 -07:00
Родитель b95d3cdc38
Коммит f6da6b51f9
15 изменённых файлов: 37 добавлений и 37 удалений

Просмотреть файл

@ -55,6 +55,7 @@ const requestContract = createRequestContract({
fetchPolicy: networkPolicy,
uriFactoryFn: urlDecorator(odataUrlFactory),
headerFactoryFn: headerDecorator(odataHeaderFactory),
parentKeySelector: variables => variables.locator.descriptor.<%- parentKey %>,
});
const responseContract = createResponseContract({
@ -62,7 +63,6 @@ const responseContract = createResponseContract({
responseType: responseTypes.ENTITY,
keySelector: keySelectorDecorator(r => r.<%= key %>),
processorFn: processorDecorator(r => r),
parentKeySelector: variables => variables.locator.descriptor.<%- parentKey %>,
});
export const fetchSpec = createSpec(

Просмотреть файл

@ -11,8 +11,8 @@ import { environmentLookupFn } from '<%= envLocation %>';
import { fetchSpec, actionSpec } from '../../__specs/calls/action-spec';
export function <%- hookName %>(variables, config = {}) {
const { dataLocator } = variables;
const dataRefId = useDataRefId(`call_${stringify(dataLocator)}`, environmentLookupFn);
const { locator } = variables;
const dataRefId = useDataRefId(`call_${stringify(locator)}`, environmentLookupFn);
const defaultConfig = useMemo(() => ({
mutation: config.mutation || {},
@ -21,20 +21,20 @@ export function <%- hookName %>(variables, config = {}) {
const { fetch: fetchConfig, mutation: mutationConfig } = defaultConfig;
const fetch = useFetch(dataRefId, fetchSpec, dataLocator, fetchConfig);
const fetch = useFetch(dataRefId, fetchSpec, locator, fetchConfig);
const action = useMutation(dataRefId, actionSpec, mutationConfig);
const callFn = useCallback((param = {}, requestConfig, ...rest) => {
action(
{
...dataLocator,
...variables,
...param.variables,
},
param.payload,
requestConfig,
...rest
);
}, [dataLocator, action]);
}, [variables, action]);
const [data, error] = fetch;

Просмотреть файл

@ -16,8 +16,8 @@ import { fetchSpec, refetchSpec } from '../../__specs/coll/fetch-spec';
import { mutationSpec } from '../../__specs/coll/mutation-spec';
export function <%- hookName %>(variables, config = {}) {
const { dataLocator } = variables;
const dataRefId = useDataRefId(`coll_${stringify(dataLocator)}`, environmentLookupFn);
const { locator } = variables;
const dataRefId = useDataRefId(`coll_${stringify(locator)}`, environmentLookupFn);
const defaultConfig = useMemo(() => ({
refetch: config.refetch || {},
@ -42,23 +42,23 @@ export function <%- hookName %>(variables, config = {}) {
const refetchFn = useRefetch(dataRefId, refetchSpec, refetchConfig);
const update = useCallback((newData, ...rest) => {
mutateFn({ ...dataLocator }, newData, ...rest);
}, [mutateFn, dataLocator]);
mutateFn({ ...locator }, newData, ...rest);
}, [mutateFn, locator]);
// FIXME: likezh: Why would destroy need data?
const destroy = useCallback((newData, ...rest) => {
destroyFn({ ...dataLocator }, newData, ...rest);
}, [destroyFn, dataLocator]);
destroyFn({ ...locator }, newData, ...rest);
}, [destroyFn, locator]);
const create = useCallback((newData, ...rest) => {
createFn({ ...dataLocator }, newData, ...rest);
}, [createFn, dataLocator]);
createFn({ ...locator }, newData, ...rest);
}, [createFn, locator]);
const refetch = useCallback((parameter, ...rest) => {
refetchFn(
{
variables: {
...dataLocator,
...variables,
...parameter.variables,
},
payload: parameter.payload,
@ -66,7 +66,7 @@ export function <%- hookName %>(variables, config = {}) {
refetchConfig,
...rest
);
}, [refetchFn, refetchConfig, dataLocator]);
}, [refetchFn, refetchConfig, variables]);
const { loadMore, hasMore, isLoading } = paginationMethods;

Просмотреть файл

@ -15,8 +15,8 @@ import { fetchSpec, refetchSpec } from '../../__specs/entity/fetch-spec';
import { mutationSpec } from '../../__specs/entity/mutation-spec';
export function <%- hookName %>(variables, config = {}) {
const { dataLocator } = variables;
const dataRefId = useDataRefId(`entity_${stringify(dataLocator)}`, environmentLookupFn);
const { locator } = variables;
const dataRefId = useDataRefId(`entity_${stringify(locator)}`, environmentLookupFn);
const defaultConfig = useMemo(() => ({
fetch: config.fetch || {},
@ -50,7 +50,7 @@ export function <%- hookName %>(variables, config = {}) {
refetchFn(
{
variables: {
...dataLocator,
...variables,
...parameter.variables,
},
payload: parameter.payload,
@ -58,7 +58,7 @@ export function <%- hookName %>(variables, config = {}) {
refetchConfig,
...rest
);
}, [refetchFn, refetchConfig, dataLocator]);
}, [refetchFn, refetchConfig, variables]);
return [{ data, error }, { update, destroy, refetch }];
}

Просмотреть файл

@ -11,8 +11,8 @@ import { environmentLookupFn } from '<%= envLocation %>';
import { fetchSpec, refetchSpec } from '../../__specs/calls/func-spec';
export function <%- hookName %>(variables, config = {}) {
const { dataLocator } = variables;
const dataRefId = useDataRefId(`call_${stringify(dataLocator)}`, environmentLookupFn);
const { locator } = variables;
const dataRefId = useDataRefId(`call_${stringify(locator)}`, environmentLookupFn);
const defaultConfig = useMemo(() => ({
refetch: config.refetch || {},
@ -21,21 +21,21 @@ export function <%- hookName %>(variables, config = {}) {
const { fetch: fetchConfig, refetch: refetchConfig } = defaultConfig;
const fetch = useFetch(dataRefId, fetchSpec, dataLocator, fetchConfig);
const fetch = useFetch(dataRefId, fetchSpec, locator, fetchConfig);
const func = useRefetch(dataRefId, refetchSpec, refetchConfig);
const callFn = useCallback((param = {}, requestConfig, ...rest) => {
func(
{
variables: {
...dataLocator,
...variables,
...param.variables,
},
},
requestConfig,
...rest
);
}, [dataLocator, func]);
}, [variables, func]);
const [data, error] = fetch;

Просмотреть файл

@ -12,7 +12,7 @@
"json-stable-stringify": "^1.0.1",
"query-string": "^7.0.1",
"react": ">=16.8.0",
"underscore": "^1.13.1"
"underscore": "^1.10.2"
},
"devDependencies": {

Просмотреть файл

@ -27,7 +27,7 @@
"xml2js": "^0.4.23"
},
"peerDependencies": {
"lodash": "^4.17.21",
"underscore": "^1.10.2",
"react": ">=16.8.0"
},
"publishConfig": {

Просмотреть файл

@ -1,7 +1,7 @@
/**
* the reflection module for property defintions
*/
const _ = require('lodash');
const _ = require('underscore');
/**
* Define a const property

Просмотреть файл

@ -1,7 +1,7 @@
/* eslint-disable max-classes-per-file */
/* eslint-disable no-mixed-operators */
/* eslint no-param-reassign: 0 */
const _ = require('lodash');
const _ = require('underscore');
/** Class representing a namespace */
class Namespace {

Просмотреть файл

@ -1,6 +1,6 @@
/* eslint-disable max-classes-per-file */
const _ = require('lodash');
const _ = require('underscore');
const { Registry } = require('./registry');
const {

Просмотреть файл

@ -2,7 +2,7 @@
* the schema plugin module
*/
const _ = require('lodash');
const _ = require('underscore');
const { Registry } = require('./registry');
const {
defineConstProperty,

Просмотреть файл

@ -1,6 +1,6 @@
/* eslint-disable max-classes-per-file */
const _ = require('lodash');
const _ = require('underscore');
const { Registry } = require('./registry');
const {
defineConstProperty,
@ -260,7 +260,7 @@ module.exports = edm => {
defineConstProperty(this, 'properties', compileProperties.call(this, properties));
defineConstProperty(this, 'navigationPropertyNames', navigationPropertyNames.slice());
defineProducedProperty(this, 'navigationProperties', () => _.pickBy(this.properties, (property, propertyName) => _.includes(this.navigationPropertyNames, propertyName)));
defineProducedProperty(this, 'navigationProperties', () => _.pick(this.properties, (property, propertyName) => _.contains(this.navigationPropertyNames, propertyName)));
if (baseTypeName) {
defineConstProperty(this, 'baseTypeName', baseTypeName);
defineProducedProperty(this, 'baseType', () => resolveType(this.baseTypeName, this.namespace));

Просмотреть файл

@ -1,4 +1,4 @@
const _ = require('lodash');
const _ = require('underscore');
function join(first, ...frags) {
return frags.reduce((memo, frag) => {

Просмотреть файл

@ -1,4 +1,4 @@
const _ = require('lodash');
const _ = require('underscore');
const queryString = require('query-string');
const { parseSearch } = require('./parse-search');
@ -16,7 +16,7 @@ function composeSearchString(variables, edmEntity) {
};
const parsedSearch = parseSearch(search, edmEntity);
const searchCompact = _.omitBy(parsedSearch, x => _.isNull(x) || _.isUndefined(x));
const searchCompact = _.omit(parsedSearch, x => _.isNull(x) || _.isUndefined(x));
const searchString = _.isEmpty(searchCompact) ? '' : `?${queryString.stringify(searchCompact)}`;
return searchString;

Просмотреть файл

@ -1,4 +1,4 @@
const _ = require('lodash');
const _ = require('underscore');
// support a mongoDB like orderby object for now: { age : -1, name: 1 }
// for backward compatibility, support array format: [['age', 'desc'], ['name', 'asc]]
function parseOrderBy(orderby) {