feat: permissions service full access.

This commit is contained in:
a.bouhuolia
2021-12-26 18:26:05 +02:00
parent 1d505db7bf
commit 0dddf3d1d0
14 changed files with 790 additions and 202 deletions

View File

@@ -6,4 +6,6 @@ export * from './useWhen';
export * from './useRequestPdf';
export * from './useAsync';
export * from './useIntersectionObserver';
export * from './useAbilityContext';
export * from './useAbilityContext';
export * from './useCustomCompareEffect';
export * from './useDeepCompareEffect';

View File

@@ -0,0 +1,44 @@
import { DependencyList, EffectCallback, useEffect, useRef } from 'react';
const isPrimitive = (val: any) => val !== Object(val);
type DepsEqualFnType<TDeps extends DependencyList> = (
prevDeps: TDeps,
nextDeps: TDeps,
) => boolean;
const useCustomCompareEffect = <TDeps extends DependencyList>(
effect: EffectCallback,
deps: TDeps,
depsEqual: DepsEqualFnType<TDeps>,
) => {
if (process.env.NODE_ENV !== 'production') {
if (!(deps instanceof Array) || !deps.length) {
console.warn(
'`useCustomCompareEffect` should not be used with no dependencies. Use React.useEffect instead.',
);
}
if (deps.every(isPrimitive)) {
console.warn(
'`useCustomCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead.',
);
}
if (typeof depsEqual !== 'function') {
console.warn(
'`useCustomCompareEffect` should be used with depsEqual callback for comparing deps list',
);
}
}
const ref = useRef<TDeps | undefined>(undefined);
if (!ref.current || !depsEqual(deps, ref.current)) {
ref.current = deps;
}
useEffect(effect, ref.current);
};
export { useCustomCompareEffect };

View File

@@ -0,0 +1,24 @@
import { DependencyList, EffectCallback } from 'react';
import isDeepEqualReact from 'fast-deep-equal/react';
import { useCustomCompareEffect } from './useCustomCompareEffect';
const isPrimitive = (val: any) => val !== Object(val);
const useDeepCompareEffect = (effect: EffectCallback, deps: DependencyList) => {
if (process.env.NODE_ENV !== 'production') {
if (!(deps instanceof Array) || !deps.length) {
console.warn(
'`useDeepCompareEffect` should not be used with no dependencies. Use React.useEffect instead.',
);
}
if (deps.every(isPrimitive)) {
console.warn(
'`useDeepCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead.',
);
}
}
useCustomCompareEffect(effect, deps, isDeepEqualReact);
};
export { useDeepCompareEffect };