Skip to content

Commit 3aaf595

Browse files
author
Diabeu
committed
refactor: change destroy description, _subscribe change param to ...args, _variable method check key length
1 parent 2912804 commit 3aaf595

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/ngx-core-common.dynamic-component.class.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ export abstract class DynamicComponentClass {
2727
}
2828

2929
protected _variable(key: string): any {
30-
return this[key];
30+
if (key.length > 0) {
31+
return this[key];
32+
} else {
33+
throw new Error(`DynamicComponentClass._variable(key) : key length is 0`);
34+
}
3135
}
3236

3337
// create component in container
@@ -38,7 +42,7 @@ export abstract class DynamicComponentClass {
3842
return this;
3943
}
4044

41-
// destroy component
45+
// destroy component if exist
4246
protected _destroy(): null {
4347
if (this._component) {
4448
this._component.destroy();
@@ -76,17 +80,14 @@ export abstract class DynamicComponentClass {
7680
/**
7781
* Subscribe to created component instance @Output
7882
* @param key instance variable of created component
79-
* @param callback function initiated in subscribe
83+
* @param args initiated in subscribe
8084
*/
81-
protected _subscribe(key: string, callback?: Function): this {
85+
protected _subscribe(key: string, ...args: any[]): this {
8286
// if created component has got property to subscribe
8387
if (this._component.instance.hasOwnProperty(key)) {
84-
this._component.instance[key].subscribe((result: any) => {
85-
// callback
86-
if (callback) {
87-
callback(result);
88-
}
89-
});
88+
this._component.instance[key].subscribe(...args);
89+
} else {
90+
throw new Error(`this._component.instance does not have property ${key}`);
9091
}
9192
return this;
9293
}

0 commit comments

Comments
 (0)