Skip to content

Commit

Permalink
feat(BlockUIService): Added update method
Browse files Browse the repository at this point in the history
  • Loading branch information
kuuurt13 committed Jan 22, 2020
1 parent d1f2886 commit f145f87
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ Instead of declaring seperate instances with the `@BlockUI()` decorator you can
| `isActive` | <code>target: string &#124; string[]</code> | Indicates if the targeted instance(s) is blocking. |
| `start` | <code>target: string &#124; string[], message?: any</code> | Starts blocking for a single instance or multiple instances by passing instance name(s). |
| `stop` | <code>target: string &#124; string[]</code> | Stops blocking for a single instance or multiple instances by passing instance name(s). |
| `update` | <code>target: string &#124; string[], message: any</code> | Updates message for a single instance or multiple instances by passing instance name(s). |
| `reset` | <code>target: string &#124; string[]</code> | Resets blocking for a single instance or multiple instances by passing instance name(s). |
| `unsubscribe` | <code>target: string &#124; string[]</code> | Unsubscribes a single instance or multiple instances by passing instance name(s). |
Expand Down
6 changes: 5 additions & 1 deletion dev/app/default/default.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export class DeafultComponent {
blockAllElements() {
this.blockUIService.start(this.blockInstances, 'Loading All');

setTimeout((blockUI) => {
setTimeout(() => {
this.blockUIService.update(this.blockInstances, 'Update Message');
}, this.timeout / 2);

setTimeout(() => {
this.blockUIService.stop(this.blockInstances);
}, this.timeout);
}
Expand Down
15 changes: 15 additions & 0 deletions lib/services/block-ui.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ describe('BlockUI service', () => {

it('methods disptach corresponding actions', () => {
blockUIService.start(instance);
blockUIService.update(instance);
blockUIService.stop(instance);
blockUIService.unsubscribe(instance);

expect(blockUIService.dispatch).toHaveBeenCalledWith(
instance, BlockUIActions.START, undefined
);

expect(blockUIService.dispatch).toHaveBeenCalledWith(
instance, BlockUIActions.UPDATE, undefined
);

expect(blockUIService.dispatch).toHaveBeenCalledWith(
instance, BlockUIActions.STOP
);
Expand All @@ -48,5 +53,15 @@ describe('BlockUI service', () => {
instance, BlockUIActions.START, message
);
});

it('passes a message to the update method', () => {
const message = 'Test message';

blockUIService.update(instance, message);

expect(blockUIService.dispatch).toHaveBeenCalledWith(
instance, BlockUIActions.UPDATE, message
);
});
});
});
7 changes: 7 additions & 0 deletions lib/services/block-ui.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ export class BlockUIService {
this.dispatch(target, BlockUIActions.RESET);
}

/**
* Updates message for given BlockUI instance or instances
*/
update(target: string | string[], message: any): void {
this.dispatch(target, BlockUIActions.UPDATE, message);
}

/**
* Unsubscribes for given BlockUI instance or instances
*/
Expand Down

0 comments on commit f145f87

Please sign in to comment.