mirror of
https://github.com/flarum/framework.git
synced 2025-01-31 10:56:48 +08:00
Replace forum and admin global compat exports with a Proxy to allow namespace use (#2488)
This commit is contained in:
parent
6d96587205
commit
b6c4aae067
|
@ -10,8 +10,9 @@ export { app };
|
||||||
// Export public API
|
// Export public API
|
||||||
|
|
||||||
// Export compat API
|
// Export compat API
|
||||||
import compat from './compat';
|
import compatObj from './compat';
|
||||||
|
import proxifyCompat from '../common/utils/proxifyCompat';
|
||||||
|
|
||||||
compat.app = app;
|
compatObj.app = app;
|
||||||
|
|
||||||
export { compat };
|
export const compat = proxifyCompat(compatObj, 'admin');
|
||||||
|
|
|
@ -21,6 +21,7 @@ import stringToColor from './utils/stringToColor';
|
||||||
import subclassOf from './utils/subclassOf';
|
import subclassOf from './utils/subclassOf';
|
||||||
import SuperTextarea from './utils/SuperTextarea';
|
import SuperTextarea from './utils/SuperTextarea';
|
||||||
import patchMithril from './utils/patchMithril';
|
import patchMithril from './utils/patchMithril';
|
||||||
|
import proxifyCompat from './utils/proxifyCompat';
|
||||||
import classList from './utils/classList';
|
import classList from './utils/classList';
|
||||||
import extractText from './utils/extractText';
|
import extractText from './utils/extractText';
|
||||||
import formatNumber from './utils/formatNumber';
|
import formatNumber from './utils/formatNumber';
|
||||||
|
@ -94,6 +95,7 @@ export default {
|
||||||
'utils/SuperTextarea': SuperTextarea,
|
'utils/SuperTextarea': SuperTextarea,
|
||||||
'utils/setRouteWithForcedRefresh': setRouteWithForcedRefresh,
|
'utils/setRouteWithForcedRefresh': setRouteWithForcedRefresh,
|
||||||
'utils/patchMithril': patchMithril,
|
'utils/patchMithril': patchMithril,
|
||||||
|
'utils/proxifyCompat': proxifyCompat,
|
||||||
'utils/classList': classList,
|
'utils/classList': classList,
|
||||||
'utils/extractText': extractText,
|
'utils/extractText': extractText,
|
||||||
'utils/formatNumber': formatNumber,
|
'utils/formatNumber': formatNumber,
|
||||||
|
|
10
framework/core/js/src/common/utils/proxifyCompat.ts
Normal file
10
framework/core/js/src/common/utils/proxifyCompat.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
export default (compat: { [key: string]: any }, namespace: string) => {
|
||||||
|
// regex to replace common/ and NAMESPACE/ for core & core extensions
|
||||||
|
// e.g. admin/utils/extract --> utils/extract
|
||||||
|
// e.g. tags/common/utils/sortTags --> tags/utils/sortTags
|
||||||
|
const regex = new RegExp(`(\\w+\\/)?(${namespace}|common)\\/`);
|
||||||
|
|
||||||
|
return new Proxy(compat, {
|
||||||
|
get: (obj, prop: string) => obj[prop] || obj[prop.replace(regex, '$1')],
|
||||||
|
});
|
||||||
|
};
|
|
@ -15,8 +15,9 @@ export { app };
|
||||||
// export { IndexPage, DicsussionList } from './components';
|
// export { IndexPage, DicsussionList } from './components';
|
||||||
|
|
||||||
// Export compat API
|
// Export compat API
|
||||||
import compat from './compat';
|
import compatObj from './compat';
|
||||||
|
import proxifyCompat from '../common/utils/proxifyCompat';
|
||||||
|
|
||||||
compat.app = app;
|
compatObj.app = app;
|
||||||
|
|
||||||
export { compat };
|
export const compat = proxifyCompat(compatObj, 'forum');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user