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.
88 lines
2.0 KiB
88 lines
2.0 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 _umi() {
|
|
const data = require("umi");
|
|
|
|
_umi = function _umi() {
|
|
return data;
|
|
};
|
|
|
|
return data;
|
|
}
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
const winPath = _umi().utils.winPath;
|
|
|
|
function _default(imports, userModels, extraImports, extraModels) {
|
|
if (!extraImports && !imports) {
|
|
return `import React from 'react';
|
|
export default ({ children }: { children: React.ReactNode }) => children
|
|
`;
|
|
}
|
|
|
|
return `import React from 'react';
|
|
${extraImports}
|
|
${imports}
|
|
// @ts-ignore
|
|
import Dispatcher from '${winPath((0, _path().join)(__dirname, '..', 'helpers', 'dispatcher'))}';
|
|
// @ts-ignore
|
|
import Executor from '${winPath((0, _path().join)(__dirname, '..', 'helpers', 'executor'))}';
|
|
// @ts-ignore
|
|
import { UmiContext } from '${winPath((0, _path().join)(__dirname, '..', 'helpers', 'constant'))}';
|
|
|
|
export const models = { ${extraModels ? `${extraModels}, ` : ''}${userModels} };
|
|
|
|
export type Model<T extends keyof typeof models> = {
|
|
[key in keyof typeof models]: ReturnType<typeof models[T]>;
|
|
};
|
|
|
|
export type Models<T extends keyof typeof models> = Model<T>[T]
|
|
|
|
const dispatcher = new Dispatcher!();
|
|
const Exe = Executor!;
|
|
|
|
export default ({ children }: { children: React.ReactNode }) => {
|
|
|
|
return (
|
|
<UmiContext.Provider value={dispatcher}>
|
|
{
|
|
Object.entries(models).map(pair => (
|
|
<Exe key={pair[0]} namespace={pair[0]} hook={pair[1] as any} onUpdate={(val: any) => {
|
|
const [ns] = pair as [keyof typeof models, any];
|
|
dispatcher.data[ns] = val;
|
|
dispatcher.update(ns);
|
|
}} />
|
|
))
|
|
}
|
|
{children}
|
|
</UmiContext.Provider>
|
|
)
|
|
}
|
|
`;
|
|
} |