@rontrol/babel-plugin-access-control-autocomplete
Autocomplete AccessControl React HoC.
When added access control for each Component, we may added some component as below:
import { mustAllOfPermissions } from "@rontrol/access";
import { AcComponent2 } from "other";
import { useRequest, useTempDataForRequest } from "@rontrol/request";
import { listApp, putApp } from "some-clients";
export const AcComponent = mustAllOfPermissions(
AcComponent2,
listApp,
putApp,
)(() => {
const [] = useRequest(putApp, {});
const [] = useTempDataForRequest(listApp, {});
return <AcComponent2 />;
});
but it will be boring and easy to make mistake.
with this plugin we could use special named component (Ac(Every)Component
and AcSomeComponet
) to autocomplete the AccessControlComponent
.
the key of access control should be from request method, we could collect them by use(\w+)?Request
or useAc(\w+)
hooks or create(\w+)?Request
HoC.
and AccessControlComponent
will be composed too.
export const AcComponent = () => {
const [] = useRequest(putApp, {});
const [] = useTempDataForRequest(listApp, {});
return <AcComponent2 />;
};
will be transform to
export const AcComponent = mustAllOfPermissions(
AcComponent2,
listApp,
putApp,
)(() => {
const [] = useRequest(putApp, {});
const [] = useTempDataForRequest(listApp, {});
return <AcComponent2 />;
});