##// END OF EJS Templates
Added childContainer service to container services, ServiceContaier is destroyable, fixed browser Uuid version
cin -
r146:f3f5c56d3b3e v1.4.0-rc5 default
parent child
Show More
@@ -56,7 +56,7 typescript {
56 56
57 57 if(symbols != 'none') {
58 58 sourceMap = true
59 sourceRoot = packageName
59 sourceRoot = "pack:${packageName}"
60 60 }
61 61
62 62 if (flavour == 'node') {
@@ -14,6 +14,10 declare const Buffer: any;
14 14
15 15 const _window: any = "undefined" !== typeof window ? window : null;
16 16
17 function noop(): never {
18 throw new Error();
19 }
20
17 21 interface WritableArrayLike<T> {
18 22 length: number;
19 23 [n: number]: T;
@@ -24,13 +28,13 interface WritableArrayLike<T> {
24 28 // detect to determine the best RNG source, normalizing to a function
25 29 // that
26 30 // returns 128-bits of randomness, since that's what's usually required
27 let _rng: () => WritableArrayLike<number> = () => [];
31 let _rng: () => WritableArrayLike<number> = noop;
28 32
29 33 function setupBrowser() {
30 34 // Allow for MSIE11 msCrypto
31 35 const _crypto = _window.crypto || _window.msCrypto;
32 36
33 if (!_rng && _crypto && _crypto.getRandomValues) {
37 if (_rng === noop && _crypto && _crypto.getRandomValues) {
34 38 // WHATWG crypto-based RNG - http://wiki.whatwg.org/wiki/Crypto
35 39 //
36 40 // Moderately fast, high quality
@@ -44,7 +48,7 function setupBrowser() {
44 48 } catch (e) { /**/ }
45 49 }
46 50
47 if (!_rng) {
51 if (_rng === noop) {
48 52 // Math.random()-based (RNG)
49 53 //
50 54 // If all else fails, use Math.random(). It's fast, but is of
@@ -5,7 +5,7 import { ServiceMap, Descriptor, Partial
5 5 import { TraceSource } from "../log/TraceSource";
6 6 import { Configuration, RegistrationMap } from "./Configuration";
7 7 import { Cancellation } from "../Cancellation";
8 import { IDestroyable, ICancellation } from "../interfaces";
8 import { ICancellation } from "../interfaces";
9 9 import { isDescriptor } from "./traits";
10 10 import { LifetimeManager } from "./LifetimeManager";
11 11 import { each, isString } from "../safe";
@@ -14,7 +14,7 import { FluentConfiguration } from "./f
14 14
15 15 const trace = TraceSource.get("@implab/core/di/ActivationContext");
16 16
17 export class Container<S extends object = any> implements ServiceContainer<S>, IDestroyable {
17 export class Container<S extends object = any> implements ServiceContainer<S> {
18 18 readonly _services: ContainerServiceMap<S>;
19 19
20 20 readonly _lifetimeManager: LifetimeManager;
@@ -29,10 +29,11 export class Container<S extends object
29 29
30 30 constructor(parent?: Container<S>) {
31 31 this._parent = parent;
32 this._services = parent ? Object.create(parent._services) : {};
32 this._services = Object.create(parent ? parent._services : null);
33 33 this._cleanup = [];
34 34 this._root = parent ? parent.getRootContainer() : this;
35 35 this._services.container = new ValueDescriptor(this) as any;
36 this._services.childContainer = { activate: () => this.createChildContainer() };
36 37 this._disposed = false;
37 38 this._lifetimeManager = new LifetimeManager();
38 39 }
@@ -1,3 +1,4
1 import { IDestroyable } from "../interfaces";
1 2 import { ActivationContext } from "./ActivationContext";
2 3 import { LifetimeManager } from "./LifetimeManager";
3 4
@@ -27,7 +28,7 export interface ServiceLocator<S extend
27 28 resolve<K extends ContainerKeys<S>>(name: K, def?: TypeOfService<S, K>): TypeOfService<S, K>;
28 29 }
29 30
30 export interface ServiceContainer<S extends object> extends ServiceLocator<S> {
31 export interface ServiceContainer<S extends object> extends ServiceLocator<S>, IDestroyable {
31 32 getLifetimeManager(): LifetimeManager;
32 33 register<K extends keyof S>(name: K, service: Descriptor<S, S[K]>): this;
33 34 register(services: PartialServiceMap<S>): this;
@@ -37,6 +38,8 export interface ServiceContainer<S exte
37 38
38 39 export interface ContainerProvided<S extends object> {
39 40 container: ServiceLocator<S>;
41
42 childContainer: ServiceContainer<S>;
40 43 }
41 44
42 45 export type ContainerRegistered<S extends object> = /*{
@@ -2,6 +2,7 import { StringBuilder } from "../text/S
2 2 import { test } from "./TestTraits";
3 3 import { MockConsole } from "../mock/MockConsole";
4 4 import { ConsoleWriter } from "../log/ConsoleWriter";
5 import { Uuid } from "../Uuid";
5 6
6 7 test("String builder", async t => {
7 8 const sb = new StringBuilder();
@@ -84,3 +85,11 test("ConsoleWriter", t => {
84 85 t.deepEqual(mockConsole.getBuffer()[0].data, ["25 or 6 to 4! Let's have some ", { product: "tee" }], "Should handle many text chunks and object at the end");
85 86
86 87 });
88
89 test("Uuid test", (t, log) => {
90 const id = Uuid();
91 log.log("uuid = {0}", id);
92 t.assert(id, "Should generate uuid");
93 t.notEqual(id, Uuid(), "uuid should never match");
94
95 });
General Comments 0
You need to be logged in to leave comments. Login now