diff --git a/src/index.tsx b/src/index.tsx index 1842fa2d..3ef54faf 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -14,8 +14,6 @@ import { } from './factory'; import {wrapFetcher, buildApi} from './utils/api'; import {filter, reigsterTplEnginer, evalExpression} from './utils/tpl'; -import './utils/tpl-builtin'; -import './utils/tpl-lodash'; import * as utils from './utils/helper'; import {resizeSensor} from './utils/resize-sensor'; import {setIconVendor} from './renderers/Form/IconPickerIcons'; diff --git a/src/utils/tpl-builtin.ts b/src/utils/tpl-builtin.ts index 95f108e5..4c56a70c 100644 --- a/src/utils/tpl-builtin.ts +++ b/src/utils/tpl-builtin.ts @@ -563,8 +563,10 @@ export function dataMapping(to: any, from: PlainObject): any { return ret; } -reigsterTplEnginer('builtin', { - test: str => !!~str.indexOf('$'), - compile: (str: string, data: object, defaultFilter = '| html') => - tokenize(str, data, defaultFilter) -}); +export function register() { + reigsterTplEnginer('builtin', { + test: str => !!~str.indexOf('$'), + compile: (str: string, data: object, defaultFilter = '| html') => + tokenize(str, data, defaultFilter) + }); +} diff --git a/src/utils/tpl-lodash.ts b/src/utils/tpl-lodash.ts index 689b1b5e..dbbce04d 100644 --- a/src/utils/tpl-lodash.ts +++ b/src/utils/tpl-lodash.ts @@ -47,7 +47,9 @@ function lodashCompile(str: string, data: object) { } } -reigsterTplEnginer('lodash', { - test: str => !!~str.indexOf('<%'), - compile: (str: string, data: object) => lodashCompile(str, data) -}); +export function register() { + reigsterTplEnginer('lodash', { + test: str => !!~str.indexOf('<%'), + compile: (str: string, data: object) => lodashCompile(str, data) + }); +} diff --git a/src/utils/tpl.ts b/src/utils/tpl.ts index 0ea09042..e6101b53 100644 --- a/src/utils/tpl.ts +++ b/src/utils/tpl.ts @@ -1,5 +1,6 @@ import {createObject} from './helper'; -import {getFilters} from './tpl-builtin'; +import {register as registerBulitin, getFilters} from './tpl-builtin'; +import {register as registerLodash} from './tpl-lodash'; export interface Enginer { test: (tpl: string) => boolean; @@ -74,3 +75,5 @@ export function evalJS(js: string, data: object): any { return null; } } + +[registerBulitin, registerLodash].forEach(fn => fn());