You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.7 KiB
71 lines
1.7 KiB
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = _default;
|
|
|
|
function _react() {
|
|
const data = _interopRequireDefault(require("react"));
|
|
|
|
_react = function _react() {
|
|
return data;
|
|
};
|
|
|
|
return data;
|
|
}
|
|
|
|
function _path() {
|
|
const data = require("path");
|
|
|
|
_path = function _path() {
|
|
return data;
|
|
};
|
|
|
|
return data;
|
|
}
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function _default(util) {
|
|
return `\
|
|
import React, { useMemo } from 'react';
|
|
import { IRoute } from 'umi';
|
|
import { useModel } from '../core/umiExports';
|
|
import accessFactory from '../../access';
|
|
import AccessContext, { AccessInstance } from './context';
|
|
import { traverseModifyRoutes } from '${util.winPath((0, _path().join)(__dirname, '..', 'utils', 'runtimeUtil'))}';
|
|
|
|
type Routes = IRoute[];
|
|
|
|
interface Props {
|
|
routes: Routes;
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
const AccessProvider: React.FC<Props> = props => {
|
|
if (typeof useModel !== 'function') {
|
|
throw new Error('[plugin-access]: useModel is not a function, @umijs/plugin-initial-state is needed.')
|
|
}
|
|
|
|
const { children } = props;
|
|
const { initialState } = useModel('@@initialState');
|
|
|
|
const access: AccessInstance = useMemo(() => accessFactory(initialState as any), [initialState]);
|
|
|
|
if (process.env.NODE_ENV === 'development' && (access === undefined || access === null)) {
|
|
console.warn('[plugin-access]: the access instance created by access.ts(js) is nullish, maybe you need check it.');
|
|
}
|
|
|
|
props.routes.splice(0, props.routes.length, ...traverseModifyRoutes(props.routes, access));
|
|
|
|
return React.createElement(
|
|
AccessContext.Provider,
|
|
{ value: access },
|
|
children,
|
|
);
|
|
};
|
|
|
|
export default AccessProvider;
|
|
`;
|
|
} |