mesh-ioc 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ export declare class Mesh {
8
8
  childScopes: Map<string, Scope>;
9
9
  instances: Map<string, any>;
10
10
  middlewares: Middleware[];
11
- constructor(name?: string, parent?: Mesh | undefined);
11
+ constructor(name?: string, parent?: Mesh | undefined, scope?: Scope);
12
12
  service<T>(impl: ServiceConstructor<T>): this;
13
13
  service<T>(key: AbstractClass<T> | string, impl: ServiceConstructor<T>): this;
14
14
  constant<T>(key: ServiceKey<T>, value: T): this;
package/out/main/mesh.js CHANGED
@@ -6,13 +6,13 @@ const scope_1 = require("./scope");
6
6
  const util_1 = require("./util");
7
7
  exports.MESH_REF = Symbol.for('MESH_REF');
8
8
  class Mesh {
9
- constructor(name = 'default', parent = undefined) {
9
+ constructor(name = 'default', parent = undefined, scope) {
10
10
  this.name = name;
11
11
  this.parent = parent;
12
12
  this.childScopes = new Map();
13
13
  this.instances = new Map();
14
14
  this.middlewares = [];
15
- this.currentScope = new scope_1.Scope(name);
15
+ this.currentScope = scope !== null && scope !== void 0 ? scope : new scope_1.Scope(name);
16
16
  this.currentScope.constant('Mesh', this);
17
17
  }
18
18
  service(key, impl) {
@@ -65,8 +65,8 @@ class Mesh {
65
65
  createScope(scopeId, scopeName = scopeId) {
66
66
  const childScope = this.childScopes.get(scopeId);
67
67
  const newScope = new scope_1.Scope(scopeName, childScope !== null && childScope !== void 0 ? childScope : []);
68
- const mesh = new Mesh(scopeId, this);
69
- mesh.currentScope = newScope;
68
+ const mesh = new Mesh(scopeId, this, newScope);
69
+ // mesh.currentScope = newScope;
70
70
  return mesh;
71
71
  }
72
72
  instantiate(binding) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mesh-ioc",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Mesh: Powerful and Lightweight IoC Library",
5
5
  "main": "out/main/index.js",
6
6
  "types": "out/main/index.d.ts",
@@ -1,14 +0,0 @@
1
- import { ServiceConstructor } from './types';
2
- export declare type Binding<T> = ConstantBinding<T> | ServiceBinding<T> | AliasBinding;
3
- export declare type ConstantBinding<T> = {
4
- type: 'constant';
5
- value: T;
6
- };
7
- export declare type ServiceBinding<T> = {
8
- type: 'service';
9
- class: ServiceConstructor<T>;
10
- };
11
- export declare type AliasBinding = {
12
- type: 'alias';
13
- key: string;
14
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +0,0 @@
1
- import 'reflect-metadata';
2
- export declare function dep(options?: DepOptions): (target: any, propertyName: string) => void;
3
- export interface DepOptions {
4
- key?: string;
5
- }
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dep = void 0;
4
- require("reflect-metadata");
5
- const errors_1 = require("./errors");
6
- const mesh_1 = require("./mesh");
7
- const metadata_1 = require("./metadata");
8
- function dep(options = {}) {
9
- return function (target, propertyName) {
10
- var _a;
11
- const className = target.constructor.name;
12
- const designType = Reflect.getMetadata('design:type', target, propertyName);
13
- const key = (_a = options.key) !== null && _a !== void 0 ? _a : designType === null || designType === void 0 ? void 0 : designType.name;
14
- if (!key) {
15
- throw new errors_1.DepKeyNotInferred(className, propertyName);
16
- }
17
- metadata_1.depMetadata.push({
18
- className,
19
- propertyName,
20
- designTypeName: designType.name,
21
- key,
22
- });
23
- Object.defineProperty(target, propertyName, {
24
- get() {
25
- const mesh = this[mesh_1.MESH_REF];
26
- if (!mesh) {
27
- throw new errors_1.DepInstanceNotConnected(className, propertyName);
28
- }
29
- return mesh.resolve(key);
30
- }
31
- });
32
- };
33
- }
34
- exports.dep = dep;
@@ -1,7 +0,0 @@
1
- export declare const depMetadata: DepMetadata[];
2
- export interface DepMetadata {
3
- className: string;
4
- propertyName: string;
5
- designTypeName: string;
6
- key: string;
7
- }
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.depMetadata = void 0;
4
- exports.depMetadata = [];