Skip to content

Commit

Permalink
fix(ng-core): DirectiveSuperclass can now be used for a pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
ersimont committed Nov 23, 2020
1 parent 3e1b208 commit 7fcd056
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"@angular/compiler-cli": "~11.0.2",
"@angular/material": "~11.0.0",
"@types/jasmine": "~3.6.0",
"@types/jasminewd2": "~2.0.3",
"@types/lodash-es": "^4.17.3",
"@types/node": "^12.11.1",
"@types/prettier": "^2.0.1",
Expand Down
22 changes: 20 additions & 2 deletions projects/ng-core/src/lib/directive-superclass.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import {
Inject,
Injector,
Input,
Pipe,
PipeTransform,
} from '@angular/core';
import { ComponentFixtureAutoDetect } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { ComponentContext, expectSingleCallAndReset } from '@s-libs/ng-dev';
import { BehaviorSubject, combineLatest, Observable } from 'rxjs';
import {
AngularContext,
ComponentContext,
expectSingleCallAndReset,
} from '@s-libs/ng-dev';
import { BehaviorSubject, combineLatest, noop, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { click, find, findButton } from '../test-helpers';
import { DirectiveSuperclass } from './directive-superclass';
Expand Down Expand Up @@ -115,6 +121,18 @@ describe('DirectiveSuperclass', () => {

/////////

it('can be used as the superclass to a pipe (production bug)', () => {
@Pipe({ name: 'not' })
class NotPipe extends DirectiveSuperclass implements PipeTransform {
transform(value: any): boolean {
return !value;
}
}
expect(() => {
new AngularContext({ declarations: [NotPipe] }).run(noop);
}).not.toThrowError();
});

describe('.inputChanges$', () => {
it('emits the keys that change', () => {
ctx.run(() => {
Expand Down
4 changes: 4 additions & 0 deletions projects/ng-core/src/lib/directive-superclass.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ChangeDetectorRef,
Directive,
Injector,
OnChanges,
SimpleChanges,
Expand Down Expand Up @@ -45,6 +46,9 @@ import { InjectableSuperclass } from './injectable-superclass';
* }
* ```
*/
// maybe this won't need the fake selector after https://github.com/angular/angular/issues/36427
@Directive({ selector: '[sDirectiveSuperclass]' })
// tslint:disable-next-line:directive-class-suffix
export abstract class DirectiveSuperclass
extends InjectableSuperclass
implements OnChanges {
Expand Down
2 changes: 1 addition & 1 deletion projects/ng-core/src/lib/injectable-superclass.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OnDestroy } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { SubscriptionManager } from '@s-libs/rxjs-core';
import { Observable, Subject } from 'rxjs';

/**
* Use as the superclass for anything managed by angular's dependency injection for care-free use of `subscribeTo()`. It simply calls `unsubscribe()` during `ngOnDestroy()`. If you override `ngOnDestroy()` in your subclass, be sure to invoke the super implementation.
Expand Down
1 change: 1 addition & 0 deletions projects/ng-core/src/typing-tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"target": "es2015",

"baseUrl": "../lib",
"experimentalDecorators": true,
"paths": {
"@s-libs/micro-dash": ["../../../../dist/micro-dash"],
"@s-libs/rxjs-core": ["../../../../dist/rxjs-core"]
Expand Down
9 changes: 1 addition & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1339,18 +1339,11 @@
"@types/minimatch" "*"
"@types/node" "*"

"@types/jasmine@*", "@types/jasmine@~3.6.0":
"@types/jasmine@~3.6.0":
version "3.6.2"
resolved "https://registry.npmjs.org/@types/jasmine/-/jasmine-3.6.2.tgz#02f64450016f7de70f145d698be311136d7c6374"
integrity sha512-AzfesNFLvOs6Q1mHzIsVJXSeUnqVh4ZHG8ngygKJfbkcSLwzrBVm/LKa+mR8KrOfnWtUL47112gde1MC0IXqpQ==

"@types/jasminewd2@~2.0.3":
version "2.0.8"
resolved "https://registry.npmjs.org/@types/jasminewd2/-/jasminewd2-2.0.8.tgz#67afe5098d5ef2386073a7b7384b69a840dfe93b"
integrity sha512-d9p31r7Nxk0ZH0U39PTH0hiDlJ+qNVGjlt1ucOoTUptxb2v+Y5VMnsxfwN+i3hK4yQnqBi3FMmoMFcd1JHDxdg==
dependencies:
"@types/jasmine" "*"

"@types/json-schema@^7.0.3", "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.6":
version "7.0.6"
resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.6.tgz#f4c7ec43e81b319a9815115031709f26987891f0"
Expand Down

0 comments on commit 7fcd056

Please sign in to comment.