Skip to content

Commit

Permalink
BREAKING CHANGE: rename AutoDestroyable to InjectableSuperclass
Browse files Browse the repository at this point in the history
  • Loading branch information
ersimont committed Jul 17, 2019
1 parent d6e798f commit dae5abd
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
9 changes: 5 additions & 4 deletions projects/s-ng-utils/src/lib/directive-superclass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "@angular/core";
import { BehaviorSubject, Observable } from "rxjs";
import { filter, map } from "rxjs/operators";
import { AutoDestroyable } from "./auto-destroyable";
import { InjectableSuperclass } from "./injectable-superclass";

/**
* Extend this when creating a directive (including a component, which is a kind of directive) to gain access to the helpers demonstrated below. **Warning:** You _must_ include a constructor in your subclass.
Expand Down Expand Up @@ -45,10 +45,11 @@ import { AutoDestroyable } from "./auto-destroyable";
* }
* ```
*/
export abstract class DirectiveSuperclass extends AutoDestroyable
export abstract class DirectiveSuperclass extends InjectableSuperclass
implements OnChanges {
/** Emits the set of `@Input()` property names that change during each call to `ngOnChanges()`. */
// lastChangedKeys$ = new Subject<Set<keyof this>>();
/**
* Emits the set of `@Input()` property names that change during each call to `ngOnChanges()`.
*/
lastChangedKeys$ = new BehaviorSubject<Set<keyof this>>(new Set());

protected changeDetectorRef: ChangeDetectorRef;
Expand Down
4 changes: 2 additions & 2 deletions projects/s-ng-utils/src/lib/form-control-superclass.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import {
import { FormsModule } from "@angular/forms";
import { By } from "@angular/platform-browser";
import { click, find, findButton } from "../test-helpers";
import { AutoDestroyable } from "./auto-destroyable";
import { DirectiveSuperclass } from "./directive-superclass";
import {
FormControlSuperclass,
provideValueAccessor,
} from "./form-control-superclass";
import { InjectableSuperclass } from "./injectable-superclass";

@Component({
template: `
Expand Down Expand Up @@ -111,7 +111,7 @@ describe("FormControlSuperclass", () => {
init();
const counter = fixture.debugElement.query(By.directive(CounterComponent))
.componentInstance;
expect(counter instanceof AutoDestroyable).toBe(true);
expect(counter instanceof InjectableSuperclass).toBe(true);
expect(counter instanceof DirectiveSuperclass).toBe(true);
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import {
import { By } from "@angular/platform-browser";
import { Subject } from "rxjs";
import { expectSingleCallAndReset } from "s-ng-dev-utils";
import { AutoDestroyable } from "./auto-destroyable";
import { InjectableSuperclass } from "./injectable-superclass";

@Injectable()
class DestroyableService extends AutoDestroyable {}
class DestroyableService extends InjectableSuperclass {}

@Directive({
selector: `[sDestroyableDirective]`,
providers: [DestroyableService],
})
class DestroyableDirective extends AutoDestroyable {
class DestroyableDirective extends InjectableSuperclass {
constructor(subject: Subject<any>, public service: DestroyableService) {
super();
this.subscribeTo(subject);
Expand All @@ -33,7 +33,7 @@ class TestComponent {
showThings = true;
}

describe("AutoDestroyable", () => {
describe("InjectableSuperclass", () => {
let subject: Subject<void>;
let fixture: ComponentFixture<TestComponent>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SubscriptionManager } from "s-rxjs-utils";
* // or @Component() (also consider DirectiveSuperclass)
* // or @Directive() (also consider DirectiveSuperclass)
* // or @Pipe()
* class MyThing extends AutoDestroyable {
* class MyThing extends InjectableSuperclass {
* constructor(somethingObservable: Observable) {
* super();
* this.subscribeTo(somethingObservable);
Expand All @@ -23,7 +23,7 @@ import { SubscriptionManager } from "s-rxjs-utils";
* }
* ```
*/
export abstract class AutoDestroyable extends SubscriptionManager
export abstract class InjectableSuperclass extends SubscriptionManager
implements OnDestroy {
/**
* An observable that emits once when this object is destroyed, then completes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import {
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { By } from "@angular/platform-browser";
import { click, find, findButton, setValue } from "../test-helpers";
import { AutoDestroyable } from "./auto-destroyable";
import { DirectiveSuperclass } from "./directive-superclass";
import {
FormControlSuperclass,
provideValueAccessor,
} from "./form-control-superclass";
import { InjectableSuperclass } from "./injectable-superclass";
import { WrappedFormControlSuperclass } from "./wrapped-form-control-superclass";

@Component({
Expand Down Expand Up @@ -163,7 +163,7 @@ describe("WrappedFormControlSuperclass", () => {
init();
const component = fixture.debugElement.query(By.directive(StringComponent))
.componentInstance;
expect(component instanceof AutoDestroyable).toBe(true);
expect(component instanceof InjectableSuperclass).toBe(true);
expect(component instanceof DirectiveSuperclass).toBe(true);
expect(component instanceof FormControlSuperclass).toBe(true);
}));
Expand Down
2 changes: 1 addition & 1 deletion projects/s-ng-utils/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
* Public API Surface of s-ng-utils
*/

export { AutoDestroyable } from "./lib/auto-destroyable";
export { DirectiveSuperclass } from "./lib/directive-superclass";
export {
FormControlSuperclass,
provideValueAccessor,
} from "./lib/form-control-superclass";
export { InjectableSuperclass } from "./lib/injectable-superclass";
export {
WrappedFormControlSuperclass,
} from "./lib/wrapped-form-control-superclass";
4 changes: 2 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Component, Injector } from "@angular/core";
import { FormControl, Validators } from "@angular/forms";
import {
AutoDestroyable,
DirectiveSuperclass,
FormControlSuperclass,
InjectableSuperclass,
provideValueAccessor,
WrappedFormControlSuperclass,
} from "s-ng-utils";
Expand All @@ -23,8 +23,8 @@ export class AppComponent {
constructor(injector: Injector) {
// use each function once just to show in can be imported
// tslint:disable:no-unused-expression
new (class extends AutoDestroyable {})();
new (class extends DirectiveSuperclass {})(injector);
new (class extends InjectableSuperclass {})();
provideValueAccessor(AppComponent);
new (class extends FormControlSuperclass<string> {
handleIncomingValue() {}
Expand Down

0 comments on commit dae5abd

Please sign in to comment.