##// END OF EJS Templates
Added childContainer service to container services, ServiceContaier is destroyable, fixed browser Uuid version
Added childContainer service to container services, ServiceContaier is destroyable, fixed browser Uuid version

File last commit:

r115:691199f665e0 ioc ts support
r146:f3f5c56d3b3e v1.4.0-rc5 default
Show More
template-compile.ts
49 lines | 1.3 KiB | video/mp2t | TypeScriptLexer
/ src / amd / ts / text / template-compile.ts
cin
text/template-compile ported to typescript
r56 import request = require("dojo/request");
import m = require("module");
import { TraceSource } from "../log/TraceSource";
import { TemplateCompiler } from "./TemplateCompiler";
import { TemplateParser } from "./TemplateParser";
import { isNullOrEmptyString } from "../safe";
import { MapOf } from "../interfaces";
type TemplateFn = (obj: object) => string;
const trace = TraceSource.get(m.id);
function compile(str: string) {
if (isNullOrEmptyString(str))
return () => "";
const parser = new TemplateParser(str);
const compiler = new TemplateCompiler();
return compiler.compile(parser);
}
const cache: MapOf<TemplateFn> = {};
interface OnLoadFn<T> {
(res: T): void;
error(e: any): void;
}
compile.load = (id: string, require: Require, callback: OnLoadFn<TemplateFn>) => {
const url = require.toUrl(id);
if (url in cache) {
trace.debug("{0} -> {1}: cached", id, url);
callback(cache[url]);
} else {
trace.debug("{0} -> {1}: load", id, url);
cin
corrected code to support ts strict mode...
r115 request<string>(url).then(compile).then((tc: TemplateFn) => {
cin
text/template-compile ported to typescript
r56 trace.debug("{0}: compiled", url);
callback(cache[url] = tc);
}, (err: any) => {
callback.error({
inner: err,
src: "@implab/core/text/template-compile"
});
});
}
};
export = compile;