removed unnecessary factory classes, simplified existing services
This commit is contained in:
parent
2a59014f0b
commit
64a4b68216
15 changed files with 69 additions and 158 deletions
|
@ -1,27 +0,0 @@
|
|||
import { ViewArrayFactory } from './view-array.factory';
|
||||
import { ViewArray } from './view-array';
|
||||
|
||||
|
||||
describe("Factory: ViewArrayFactory", () => {
|
||||
var viewArrayFactory: ViewArrayFactory;
|
||||
var $intervalMock: any;
|
||||
|
||||
beforeEach(() => {
|
||||
$intervalMock = jasmine.createSpy('$intervalSpy');
|
||||
$intervalMock.cancel = jasmine.createSpy('cancelSpy');
|
||||
viewArrayFactory = new ViewArrayFactory($intervalMock)
|
||||
});
|
||||
|
||||
describe("constructor", () => {
|
||||
|
||||
});
|
||||
|
||||
describe("create", () => {
|
||||
|
||||
it("returns a ViewArray object", () => {
|
||||
var viewArray: ViewArray = viewArrayFactory.create();
|
||||
|
||||
expect(viewArray).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,29 +0,0 @@
|
|||
import { ViewArray } from './view-array';
|
||||
import { ViewArrayImpl } from './view-array.impl';
|
||||
import { Inject } from '../../decorators/inject/inject.decorator';
|
||||
|
||||
|
||||
/**
|
||||
* Factory for creating ViewArray instances.
|
||||
*/
|
||||
export class ViewArrayFactory {
|
||||
|
||||
private ADDITIONAL_ENTRIES: number = 20;
|
||||
|
||||
/**
|
||||
* @param $interval Angular $interval service.
|
||||
* @return viewArrayFactory A factory for creating ViewArray objects.
|
||||
*/
|
||||
constructor(@Inject('$interval') private $interval: ng.IIntervalService) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ViewArray object.
|
||||
* @return viewArray New ViewArrayImpl instance.
|
||||
*/
|
||||
public create(): ViewArray {
|
||||
return new ViewArrayImpl(this.$interval, this.ADDITIONAL_ENTRIES);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,14 +4,12 @@ import { ViewArrayImpl } from './view-array.impl';
|
|||
describe("ViewArrayImplImpl", () => {
|
||||
var viewArrayImpl: ViewArrayImpl;
|
||||
var $intervalMock: any;
|
||||
var additionalCount: number;
|
||||
|
||||
beforeEach(() => {
|
||||
$intervalMock = jasmine.createSpy('$intervalSpy');
|
||||
$intervalMock.and.returnValue({});
|
||||
$intervalMock.cancel = jasmine.createSpy('cancelSpy');
|
||||
additionalCount = 20;
|
||||
viewArrayImpl = new ViewArrayImpl($intervalMock, additionalCount);
|
||||
viewArrayImpl = new ViewArrayImpl($intervalMock);
|
||||
});
|
||||
|
||||
|
||||
|
@ -137,4 +135,13 @@ describe("ViewArrayImplImpl", () => {
|
|||
expect($intervalMock.cancel).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("create", () => {
|
||||
|
||||
it("returns a new ViewArrayImpl instance", () => {
|
||||
var newViewArrayImpl: ViewArrayImpl = viewArrayImpl.create();
|
||||
|
||||
expect(newViewArrayImpl).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import { ViewArray } from './view-array';
|
||||
import { Inject } from '../../decorators/inject/inject.decorator';
|
||||
|
||||
|
||||
export class ViewArrayImpl implements ViewArray {
|
||||
|
@ -10,8 +11,9 @@ export class ViewArrayImpl implements ViewArray {
|
|||
public hasHiddenEntries: boolean;
|
||||
private timerRef: any;
|
||||
private currentIndex: number;
|
||||
private additionalCount: number = 20;
|
||||
|
||||
constructor(private interval: any, private additionalCount: number) {
|
||||
constructor(@Inject('$interval') private interval: any) {
|
||||
this.isVisible = false;
|
||||
this.visibleEntries = null;
|
||||
this.hasEntries = false;
|
||||
|
@ -57,6 +59,10 @@ export class ViewArrayImpl implements ViewArray {
|
|||
}
|
||||
}
|
||||
|
||||
public create(): ViewArrayImpl {
|
||||
return new ViewArrayImpl(this.interval);
|
||||
}
|
||||
|
||||
private showAdditionalEntries(): void {
|
||||
var i: number = 0;
|
||||
for (i = this.currentIndex; i < (this.currentIndex + this.additionalCount) && i < this.entries.length; ++i) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ViewArrayImpl } from "static/js/services/view-array/view-array.impl";
|
||||
/**
|
||||
* Specialized wrapper around array which provides a toggle() method for viewing the contents of the
|
||||
* array in a manner that is asynchronously filled in over a short time period. This prevents long
|
||||
|
@ -59,4 +60,10 @@ export abstract class ViewArray {
|
|||
* @param newState True/False if the contents are visible.
|
||||
*/
|
||||
public abstract setVisible(newState: boolean): void;
|
||||
|
||||
/**
|
||||
* Factory function to create a new ViewArray.
|
||||
* @return viewArray New ViewArray instance.
|
||||
*/
|
||||
public abstract create(): ViewArrayImpl;
|
||||
}
|
Reference in a new issue