优化 tpl 引入方式

This commit is contained in:
2betop 2020-01-07 20:05:01 +08:00
parent 3d6a6160f3
commit 4d81135021
4 changed files with 17 additions and 12 deletions

View File

@ -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';

View File

@ -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)
});
}

View File

@ -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)
});
}

View File

@ -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());