##// END OF EJS Templates
fixes to css, nls to support requirejs optimizer
cin -
r36:a1a1ef050ecc 1.0.0-rc17 default
parent child
Show More
@@ -1,16 +1,17
1 import inject = require("./dom-inject");
1 import inject from "./dom-inject";
2 import { id as mid} from "module";
2
3 import { TraceSource } from "@implab/core-amd/log/TraceSource";
3 interface OnLoad {
4 const log = TraceSource.get(mid);
4 (result?: any): void;
5 error(err: any): void;
6 }
5
7
6 const plugin = {
8 const plugin = {
7 load: async (id: string, require: Require, cb: (param: any) => void) => {
9 load: (id: string, require: Require, cb: OnLoad, config: { isBuild?: boolean }) => {
8 const url = require.toUrl(id);
10 if (config.isBuild) {
9 try {
11 cb();
10 await inject.injectStylesheet(url);
12 } else {
11 cb({ url });
13 const url = require.toUrl(id);
12 } catch (e) {
14 inject.injectStylesheet(url).then(() => cb({ url }), e => cb.error(e));
13 log.error("CSS plugin failed to load {0} ({1}): {2}", id, url, e);
14 }
15 }
15 }
16 }
16 };
17 };
@@ -18,8 +18,8 interface NodeLoadResult {
18 }
18 }
19
19
20 class DomInject {
20 class DomInject {
21 injectionPoint = document.head;
21 injectionPoint?: HTMLElement;
22 injectBefore = document.head.firstChild;
22 injectBefore?: HTMLElement;
23
23
24 _map: MapOf<Promise<NodeLoadResult>> = {};
24 _map: MapOf<Promise<NodeLoadResult>> = {};
25
25
@@ -48,7 +48,10 class DomInject {
48
48
49 mixin(node, attr);
49 mixin(node, attr);
50
50
51 this.injectionPoint.insertBefore(node, this.injectBefore);
51 const _injectionPoint = this.injectionPoint || document.head;
52 const _injectBefore = this.injectBefore || _injectionPoint.firstChild;
53
54 _injectionPoint.insertBefore(node, _injectBefore);
52 });
55 });
53 }
56 }
54
57
@@ -94,4 +97,4 class DomInject {
94 };
97 };
95
98
96 const instance = new DomInject();
99 const instance = new DomInject();
97 export = instance; No newline at end of file
100 export default instance;
@@ -2,6 +2,11 import { MapOf } from "@implab/core-amd/
2 import { NlsBundle } from "./NlsBundle";
2 import { NlsBundle } from "./NlsBundle";
3 import { isPromise } from "@implab/core-amd/safe";
3 import { isPromise } from "@implab/core-amd/safe";
4
4
5 interface OnLoad {
6 (result?: any): void;
7 error(err: any): void;
8 }
9
5 export function bundle<T extends object>(nls: T, locales?: MapOf<any>) {
10 export function bundle<T extends object>(nls: T, locales?: MapOf<any>) {
6 const nlsBundle = new NlsBundle(nls, locales);
11 const nlsBundle = new NlsBundle(nls, locales);
7
12
@@ -16,12 +21,16 export function bundle<T extends object>
16
21
17 fn.define = (pack: Partial<T>) => pack;
22 fn.define = (pack: Partial<T>) => pack;
18 fn.default = nlsBundle.default;
23 fn.default = nlsBundle.default;
19 fn.load = async (id: string, require: Require, cb: { (): void; error: (arg0: any) => void; }) => {
24 fn.load = async (id: string, require: Require, cb: OnLoad, config: any) => {
20 try {
25 if (config.isBuild) {
21 await nlsBundle.getLocale(id);
22 cb();
26 cb();
23 } catch (e) {
27 } else {
24 cb.error(e);
28 try {
29 await nlsBundle.getLocale(id);
30 cb();
31 } catch (e) {
32 cb.error(e);
33 }
25 }
34 }
26 };
35 };
27
36
General Comments 0
You need to be logged in to leave comments. Login now