This commit is contained in:
Like Zhu 2021-07-28 19:21:03 -07:00
Родитель 60f78cc060
Коммит a593a9f104
12 изменённых файлов: 39 добавлений и 21 удалений

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

@ -20,6 +20,7 @@ import {
headerDecorator,
payloadDecorator,
processorDecorator,
keySelectorDecorator,
networkPolicy,
} from './action-decorators';
@ -60,12 +61,15 @@ const requestContract = createRequestContract({
uriFactoryFn: urlDecorator(odataUrlFactory),
headerFactoryFn: headerDecorator(odataHeaderFactory),
payloadFactoryFn: payloadDecorator(odataPayloadFactory),
// TODO: figure out how to do parentKey
parentKeySelector: variables => variables.locator.descriptor.<%- parentKey %>
});
const responseContract = createResponseContract({
requestContract,
responseType: <%- responseType %>,
keySelector: <%- key %>,
keySelector: keySelectorDecorator(<%- key %>),
processorFn: processorDecorator(<%- processor %>),
});

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

@ -19,6 +19,7 @@ import {
urlDecorator,
headerDecorator,
processorDecorator,
keySelectorDecorator,
networkPolicy,
} from './func-decorators';
@ -58,7 +59,7 @@ const requestContract = createRequestContract({
const responseContract = createResponseContract({
requestContract,
responseType: <%- responseType %>,
keySelector: <%- key %>,
keySelector: keySelectorDecorator(<%- key %>),
processorFn: processorDecorator(<%- processor %>),
});

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

@ -20,6 +20,7 @@ import {
headerDecorator,
payloadDecorator,
processorDecorator,
keySelectorDecorator,
networkPolicy,
} from './add-decorators';
@ -65,7 +66,7 @@ const requestContract = createRequestContract({
const responseContract = createResponseContract({
requestContract,
responseType: responseTypes.COLL,
keySelector: r => r.<%= key %>,
keySelector: keySelectorDecorator(r => r.<%= key %>),
processorFn: processorDecorator(r => r.value),
});

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

@ -19,6 +19,7 @@ import {
urlDecorator,
headerDecorator,
processorDecorator,
keySelectorDecorator,
networkPolicy,
} from './destroy-decorators';
@ -58,7 +59,7 @@ const requestContract = createRequestContract({
const responseContract = createResponseContract({
requestContract,
responseType: responseTypes.COLL,
keySelector: r => r.<%= key %>,
keySelector: keySelectorDecorator(r => r.<%= key %>),
processorFn: processorDecorator(r => r.value),
});

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

@ -19,6 +19,7 @@ import {
urlDecorator,
headerDecorator,
processorDecorator,
keySelectorDecorator,
networkPolicy,
} from './fetch-decorators';
@ -58,7 +59,7 @@ const requestContract = createRequestContract({
const responseContract = createResponseContract({
requestContract,
responseType: responseTypes.COLL,
keySelector: r => r.<%= key %>,
keySelector: keySelectorDecorator(r => r.<%= key %>),
processorFn: processorDecorator(r => r.value),
});

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

@ -20,6 +20,7 @@ import {
headerDecorator,
payloadDecorator,
processorDecorator,
keySelectorDecorator,
networkPolicy,
} from './mutation-decorators';
@ -65,7 +66,7 @@ const requestContract = createRequestContract({
const responseContract = createResponseContract({
requestContract,
responseType: responseTypes.COLL,
keySelector: r => r.<%= key %>,
keySelector: keySelectorDecorator(r => r.<%= key %>),
processorFn: processorDecorator(r => r.value),
});

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

@ -19,6 +19,7 @@ import {
urlDecorator,
headerDecorator,
processorDecorator,
keySelectorDecorator,
networkPolicy,
} from './destroy-decorators';
@ -58,7 +59,7 @@ const requestContract = createRequestContract({
const responseContract = createResponseContract({
requestContract,
responseType: responseTypes.ENTITY,
keySelector: r => r.<%= key %>,
keySelector: keySelectorDecorator(r => r.<%= key %>),
processorFn: processorDecorator(r => r),
});

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

@ -19,6 +19,7 @@ import {
urlDecorator,
headerDecorator,
processorDecorator,
keySelectorDecorator,
networkPolicy,
} from './fetch-decorators';
@ -58,7 +59,7 @@ const requestContract = createRequestContract({
const responseContract = createResponseContract({
requestContract,
responseType: responseTypes.ENTITY,
keySelector: r => r.<%= key %>,
keySelector: keySelectorDecorator(r => r.<%= key %>),
processorFn: processorDecorator(r => r),
});

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

@ -20,6 +20,7 @@ import {
headerDecorator,
payloadDecorator,
processorDecorator,
keySelectorDecorator,
networkPolicy,
} from './mutation-decorators';
@ -65,7 +66,7 @@ const requestContract = createRequestContract({
const responseContract = createResponseContract({
requestContract,
responseType: responseTypes.ENTITY,
keySelector: r => r.<%= key %>,
keySelector: keySelectorDecorator(r => r.<%= key %>),
processorFn: processorDecorator(r => r),
});

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

@ -17,7 +17,7 @@ export const middlewares = {
const store = new Store();
let env = null;
export const ENVIRONMENT_TAG = <%= environmentTag %>;
export const ENVIRONMENT_TAG = '<%= environmentTag %>';
export function getEnvironmentInstance(requestor, customStore, customMiddleWares) {
if (!env) {

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

@ -24,14 +24,11 @@ export function <%- hookName %>(dataLocator, config = {}) {
const callFn = useCallback((param = {}, requestConfig, ...rest) => {
action({
variables: {
...dataLocator,
...param.variables,
},
payload: {
...param.payload,
},
}, requestConfig, ...rest);
...dataLocator,
...param.variables,
},
param.payload,
requestConfig, ...rest);
}, [dataLocator, action]);
const [data, error] = fetch;

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

@ -29,11 +29,20 @@ export function payloadDecorator(fn) {
return params => decorator(params, fn(params));
}
export function processorDecorator(fn) {
function decorator(response, originValue) {
export function keySelectorDecorator(fn) {
function decorator(obj, originValue) {
// TODO: Add decoration
return originValue;
}
return response => decorator(response, fn(response));
return obj => decorator(obj, fn(obj));
}
export function processorDecorator(fn) {
function decorator(response, request, originValue) {
// TODO: Add decoration
return originValue;
}
return (response, request) => decorator(response, request, fn(response, request));
}