暴露store清理api

This commit is contained in:
2betop 2020-03-11 16:42:02 +08:00
parent 67fe342b73
commit 737696f81c
2 changed files with 16 additions and 7 deletions

View File

@ -1,7 +1,7 @@
import React from 'react';
import qs from 'qs';
import {RendererStore, IRendererStore, IIRendererStore} from './store/index';
import {getEnv} from 'mobx-state-tree';
import {getEnv, destroy} from 'mobx-state-tree';
import {Location} from 'history';
import {wrapFetcher} from './utils/api';
import {
@ -961,12 +961,19 @@ export function render(
);
}
export function clearStoresCache(sessions?: Array<string>) {
if (Array.isArray(sessions) && sessions.length) {
sessions.forEach(key => delete stores[key]);
} else {
stores = {};
export function clearStoresCache(
sessions: Array<string> | string = Object.keys(stores)
) {
if (!Array.isArray(sessions)) {
sessions = [sessions];
}
sessions.forEach(key => {
const store = stores[key];
delete stores[key];
store && destroy(store);
});
}
let cache: {[propName: string]: RendererConfig} = {};

View File

@ -10,7 +10,8 @@ import {
Renderer,
getRendererByName,
resolveRenderer,
filterSchema
filterSchema,
clearStoresCache
} from './factory';
import {wrapFetcher, buildApi} from './utils/api';
import {filter, reigsterTplEnginer, evalExpression} from './utils/tpl';
@ -195,6 +196,7 @@ const classPrefix = getClassPrefix();
export {
render,
clearStoresCache,
Renderer,
FormItem,
OptionsControl,