Skip to content

Commit

Permalink
change!: use standalone components everywhere
Browse files Browse the repository at this point in the history
Standalone brings better treeshaking and easier integration with the
host applications.
  • Loading branch information
daelmaak committed Aug 5, 2023
1 parent ab75712 commit 392ed51
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 69 deletions.
4 changes: 2 additions & 2 deletions projects/demo/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ShowcaseComponent } from './components/showcase/showcase.component';
import { DemoThumbsOrientationComponent } from './components/demo-thumbs-orientation/demo-thumbs-orientation.component';
import { DemoMultipleItemsComponent } from './components/demo-multiple-items/demo-multiple-items.component';
import { DemoCustomTemplatesComponent } from './components/demo-custom-templates/demo-custom-templates.component';
import { GalleryModule } from '@daelmaak/ngx-gallery';
import { GalleryComponent } from '@daelmaak/ngx-gallery';

const materialModules = [
MatButtonModule,
Expand Down Expand Up @@ -46,7 +46,7 @@ const materialModules = [
BrowserAnimationsModule,
CommonModule,
FormsModule,
GalleryModule,
GalleryComponent,
],
providers: [],
bootstrap: [AppComponent],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { CounterComponent } from './counter.component';

describe('CounterComponent', () => {
let component: CounterComponent;
let fixture: ComponentFixture<CounterComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [CounterComponent],
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(CounterComponent);
component = fixture.componentInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { VerticalOrientation } from '../../core';
`,
styleUrls: ['./counter.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
})
export class CounterComponent {
@Input()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,24 @@
import { DebugElement } from '@angular/core';
import {
async,
ComponentFixture,
fakeAsync,
TestBed,
tick,
} from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { SafePipe } from '../../pipes/safe.pipe';
import { CounterComponent } from '../counter/counter.component';
import { ChevronIconComponent } from '../icons/chevron/chevron-icon.component';
import { ThumbsComponent } from '../thumbs/thumbs.component';
import { ViewerComponent } from '../viewer/viewer.component';
import { GalleryComponent } from './gallery.component';

describe('GalleryComponent', () => {
let component: GalleryComponent;
let fixture: ComponentFixture<GalleryComponent>;
let de: DebugElement;

beforeEach(async(() => {
TestBed.configureTestingModule({
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [NoopAnimationsModule],
declarations: [
GalleryComponent,
ViewerComponent,
ThumbsComponent,
ChevronIconComponent,
CounterComponent,
SafePipe,
],
}).compileComponents();
}));
});

beforeEach(() => {
fixture = TestBed.createComponent(GalleryComponent);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CommonModule } from '@angular/common';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Expand Down Expand Up @@ -33,6 +34,8 @@ import { ViewerComponent } from '../viewer/viewer.component';
templateUrl: './gallery.component.html',
styleUrls: ['./gallery.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [CommonModule, ThumbsComponent, ViewerComponent],
})
export class GalleryComponent {
@Input() items: GalleryItem[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import { Component, ChangeDetectionStrategy } from '@angular/core';
templateUrl: './chevron-icon.component.html',
styleUrls: ['./chevron-icon.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
})
export class ChevronIconComponent {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,26 @@ import {
import {
ComponentFixture,
TestBed,
async,
fakeAsync,
flush,
tick,
} from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { GalleryItem, SUPPORT } from '../../core';
import { ChevronIconComponent } from '../icons/chevron/chevron-icon.component';
import { ThumbsComponent } from './thumbs.component';

describe('ThumbnailsComponent', () => {
let component: ThumbsComponent;
let fixture: ComponentFixture<ThumbsComponent>;
let de: DebugElement;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ThumbsComponent, ChevronIconComponent],
})
beforeEach(async () => {
await TestBed.configureTestingModule({})
.overrideComponent(ThumbsComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default },
})
.compileComponents();
}));
});

beforeEach(() => {
fixture = TestBed.createComponent(ThumbsComponent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ import {
} from '../../core';
import { Aria } from '../../core/aria';
import { GalleryItemEvent, GalleryItemInternal } from '../../core/gallery-item';
import { ChevronIconComponent } from '../icons/chevron/chevron-icon.component';
import { CommonModule } from '@angular/common';

@Component({
selector: 'thumbs',
templateUrl: './thumbs.component.html',
styleUrls: ['./thumbs.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [CommonModule, ChevronIconComponent],
})
export class ThumbsComponent implements OnChanges, OnDestroy {
@Input() items: GalleryItemInternal[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { OrientationFlag } from '../../core';
import { GalleryItemInternal } from '../../core/gallery-item';
import { SafePipe } from '../../pipes/safe.pipe';
import { CounterComponent } from '../counter/counter.component';
import { ChevronIconComponent } from '../icons/chevron/chevron-icon.component';
import { ViewerComponent } from './viewer.component';

describe('ViewerComponent', () => {
Expand All @@ -32,13 +29,6 @@ describe('ViewerComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [NoopAnimationsModule],
declarations: [
ViewerComponent,
ChevronIconComponent,
CounterComponent,
SafePipe,
TestCustomTemplatesComponent,
],
})
.overrideComponent(ViewerComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default },
Expand Down
13 changes: 13 additions & 0 deletions projects/gallery/src/lib/components/viewer/viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ import {
VerticalOrientation,
} from '../../core';
import { GalleryItemInternal } from '../../core/gallery-item';
import { CounterComponent } from '../counter/counter.component';
import { ChevronIconComponent } from '../icons/chevron/chevron-icon.component';
import { SafePipe } from '../../pipes/safe.pipe';
import { CommonModule } from '@angular/common';
import { MediaDirective } from '../../directives/media.directive';

const passiveEventListenerOpts = {
passive: true,
Expand All @@ -52,6 +57,14 @@ const passiveEventListenerOpts = {
]),
]),
],
standalone: true,
imports: [
CommonModule,
CounterComponent,
ChevronIconComponent,
MediaDirective,
SafePipe,
],
})
export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
@Input() items: GalleryItemInternal[];
Expand Down
1 change: 1 addition & 0 deletions projects/gallery/src/lib/directives/media.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {

@Directive({
selector: '[media]',
standalone: true,
})
export class MediaDirective implements OnInit, OnDestroy {
@Output()
Expand Down
25 changes: 0 additions & 25 deletions projects/gallery/src/lib/gallery.module.ts

This file was deleted.

1 change: 1 addition & 0 deletions projects/gallery/src/lib/pipes/safe.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DomSanitizer } from '@angular/platform-browser';

@Pipe({
name: 'safe',
standalone: true,
})
export class SafePipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {}
Expand Down
1 change: 0 additions & 1 deletion projects/gallery/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
* Public API Surface of the gallery
*/
export * from './lib/components/gallery/gallery.component';
export * from './lib/gallery.module';
export * from './lib/core';

0 comments on commit 392ed51

Please sign in to comment.