Skip to content
This repository was archived by the owner on Oct 14, 2024. It is now read-only.

Commit 74f9724

Browse files
author
Miller
committed
https://github.com/victos/angular-opensource/issues/6
1 parent cac60c9 commit 74f9724

File tree

5 files changed

+59
-78
lines changed

5 files changed

+59
-78
lines changed
Lines changed: 54 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,74 @@
11
import {Subscription} from 'rxjs';
22
import {Component, TemplateRef, Type, Inject, ChangeDetectorRef} from '@angular/core';
3+
import {InstanceConfigHolderService} from '../service/instance-config-holder.service';
34

45
export class BusyConfig implements IBusyConfig {
5-
template: TemplateRef<any> | Type<any>;
6-
delay: number;
7-
minDuration: number;
8-
backdrop: boolean;
9-
message: string;
10-
wrapperClass: string;
11-
disableAnimation: boolean;
6+
template: TemplateRef<any> | Type<any>;
7+
delay: number;
8+
minDuration: number;
9+
backdrop: boolean;
10+
message: string;
11+
wrapperClass: string;
12+
disableAnimation: boolean;
1213

13-
constructor(config: IBusyConfig = {}) {
14-
for (const option of Object.keys(BUSY_CONFIG_DEFAULTS)) {
15-
this[option] = config[option] !== undefined ? config[option] : BUSY_CONFIG_DEFAULTS[option];
16-
}
14+
constructor(config: IBusyConfig = {}) {
15+
for (const option of Object.keys(BUSY_CONFIG_DEFAULTS)) {
16+
this[option] = config[option] !== undefined ? config[option] : BUSY_CONFIG_DEFAULTS[option];
1717
}
18+
}
1819
}
1920

2021
@Component({
21-
selector: 'default-busy',
22-
template: `
23-
<div class="ng-busy-default-wrapper">
24-
<div class="ng-busy-default-sign">
25-
<div class="ng-busy-default-spinner">
26-
<div class="bar1"></div>
27-
<div class="bar2"></div>
28-
<div class="bar3"></div>
29-
<div class="bar4"></div>
30-
<div class="bar5"></div>
31-
<div class="bar6"></div>
32-
<div class="bar7"></div>
33-
<div class="bar8"></div>
34-
<div class="bar9"></div>
35-
<div class="bar10"></div>
36-
<div class="bar11"></div>
37-
<div class="bar12"></div>
38-
</div>
39-
<div class="ng-busy-default-text">{{message}}</div>
40-
</div>
41-
</div>
42-
`,
22+
selector: 'default-busy',
23+
template: `
24+
<div class="ng-busy-default-wrapper">
25+
<div class="ng-busy-default-sign">
26+
<div class="ng-busy-default-spinner">
27+
<div class="bar1"></div>
28+
<div class="bar2"></div>
29+
<div class="bar3"></div>
30+
<div class="bar4"></div>
31+
<div class="bar5"></div>
32+
<div class="bar6"></div>
33+
<div class="bar7"></div>
34+
<div class="bar8"></div>
35+
<div class="bar9"></div>
36+
<div class="bar10"></div>
37+
<div class="bar11"></div>
38+
<div class="bar12"></div>
39+
</div>
40+
<div class="ng-busy-default-text">{{message}}</div>
41+
</div>
42+
</div>
43+
`,
4344
})
4445
export class DefaultBusyComponent {
45-
private _msg: string;
4646

47-
constructor(@Inject('message') private msg: string, private _changeDetectionRef: ChangeDetectorRef) {
48-
}
49-
50-
get message() {
51-
if (this._msg === undefined) {
52-
this.message = this.msg;
53-
}
54-
return this._msg;
55-
}
47+
constructor(@Inject('instanceConfigHolder') private instanceConfigHolder: InstanceConfigHolderService) {
48+
}
5649

57-
set message(msg: string) {
58-
this._msg = msg;
59-
this._changeDetectionRef.detectChanges();
60-
}
50+
get message() {
51+
return this.instanceConfigHolder.config.message;
52+
}
6153
}
6254

6355
export interface IBusyConfig {
64-
template?: TemplateRef<any> | Type<any>;
65-
delay?: number;
66-
minDuration?: number;
67-
backdrop?: boolean;
68-
message?: string;
69-
wrapperClass?: string;
70-
busy?: Array<Promise<any> | Subscription>;
71-
disableAnimation?: boolean;
56+
template?: TemplateRef<any> | Type<any>;
57+
delay?: number;
58+
minDuration?: number;
59+
backdrop?: boolean;
60+
message?: string;
61+
wrapperClass?: string;
62+
busy?: Array<Promise<any> | Subscription>;
63+
disableAnimation?: boolean;
7264
}
7365

7466
export const BUSY_CONFIG_DEFAULTS = {
75-
template: DefaultBusyComponent,
76-
delay: 0,
77-
minDuration: 0,
78-
backdrop: true,
79-
message: 'Please wait...',
80-
wrapperClass: 'ng-busy',
81-
disableAnimation: false
67+
template: DefaultBusyComponent,
68+
delay: 0,
69+
minDuration: 0,
70+
backdrop: true,
71+
message: 'Please wait...',
72+
wrapperClass: 'ng-busy',
73+
disableAnimation: false
8274
};

projects/ng-busy/src/lib/ng-busy.directive.spec.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {BrowserDynamicTestingModule} from '@angular/platform-browser-dynamic/tes
1818
import {DefaultBusyComponent} from './model/busy-config';
1919
import {NgBusyComponent} from './component/ng-busy/ng-busy.component';
2020
import {Subscription, Observable} from 'rxjs';
21+
import {InstanceConfigHolderService} from './service/instance-config-holder.service';
2122

2223
const createPromiseWithDelay = (delay: number): Promise<any> => {
2324
return new Promise((resolve) => {
@@ -48,21 +49,12 @@ const createSubscriptionWithDelay = (delay: number): Subscription => {
4849
`,
4950
})
5051
export class CustomBusyComponent {
51-
private _msg: string;
5252

53-
constructor(@Inject('message') private msg: string, private _changeDetectionRef: ChangeDetectorRef) {
53+
constructor(@Inject('instanceConfigHolder') private instanceConfigHolder: InstanceConfigHolderService) {
5454
}
5555

5656
get message() {
57-
if (this._msg === undefined) {
58-
this.message = this.msg;
59-
}
60-
return this._msg;
61-
}
62-
63-
set message(msg: string) {
64-
this._msg = msg;
65-
this._changeDetectionRef.detectChanges();
57+
return this.instanceConfigHolder.config.message;
6658
}
6759
}
6860

projects/ng-busy/src/lib/ng-busy.directive.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,6 @@ export class NgBusyDirective implements DoCheck, OnDestroy {
144144
provide: 'instanceConfigHolder',
145145
useValue: this.instanceConfigHolder
146146
},
147-
{
148-
provide: 'message',
149-
useValue: this.optionsNorm.message
150-
},
151147
{
152148
provide: 'busyEmitter',
153149
useValue: this.busyEmitter

projects/ng-busy/src/lib/service/busy-config-holder.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ export class BusyConfigHolderService {
88
config: BusyConfig;
99

1010
constructor(@Optional() config: BusyConfig) {
11-
this.config = Object.assign(BUSY_CONFIG_DEFAULTS, config || new BusyConfig());
11+
this.config = Object.assign({}, BUSY_CONFIG_DEFAULTS, config || new BusyConfig());
1212
}
1313
}

projects/ng-busy/src/public_api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
export * from './lib/ng-busy.module';
66
export * from './lib/model/busy-config';
77
export {NgBusyDirective} from './lib/ng-busy.directive';
8+
export {InstanceConfigHolderService} from './lib/service/instance-config-holder.service';

0 commit comments

Comments
 (0)