-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
237 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
import { ApplicationConfig } from '@angular/core'; | ||
import { provideRouter, withEnabledBlockingInitialNavigation } from '@angular/router'; | ||
import { appRoutes } from './app.routes'; | ||
import { allIcons, provideBi, withHeight, withIcons, withWidth } from 'dfx-bootstrap-icons'; | ||
import { | ||
allIcons, | ||
biCacheInterceptor, | ||
provideBi, | ||
withHeight, | ||
withIcons, | ||
withWidth | ||
} from "dfx-bootstrap-icons"; | ||
import { provideDfxHelper, withWindow } from 'dfx-helper'; | ||
import { provideHttpClient, withInterceptors } from "@angular/common/http"; | ||
|
||
export const appConfig: ApplicationConfig = { | ||
providers: [ | ||
provideRouter(appRoutes, withEnabledBlockingInitialNavigation()), | ||
provideDfxHelper(withWindow()), | ||
provideHttpClient(withInterceptors([biCacheInterceptor])), | ||
provideBi(withIcons(allIcons), withWidth('32'), withHeight('48')), | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
apps/dfx-bootstrap-icons-demo/src/app/load-icon.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ChangeDetectionStrategy, Component, signal } from "@angular/core"; | ||
import { BiComponent, provideBi, withCDN } from "dfx-bootstrap-icons"; | ||
|
||
@Component({ | ||
template: ` | ||
<div class="d-flex align-items-center justify-content-end gap-2 my-2" (click)="showIcon.set(!showIcon())"> | ||
<span>This icon gets loaded via cdn </span> | ||
@if (showIcon()) { | ||
<bi name="box" size="16" /> | ||
} | ||
</div> | ||
`, | ||
standalone: true, | ||
imports: [BiComponent], | ||
providers: [provideBi(withCDN('https://playground.dafnik.me/bootstrap-icons/icons'))], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
selector: 'app-load-icon', | ||
}) | ||
export class LoadIconComponent { | ||
showIcon = signal(true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
libs/dfx-bootstrap-icons/src/lib/icons-cache.interceptor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { | ||
HttpContextToken, | ||
HttpEvent, | ||
HttpHandlerFn, | ||
HttpRequest, | ||
HttpResponse | ||
} from "@angular/common/http"; | ||
import { Observable, of, share, tap } from "rxjs"; | ||
|
||
export const ICON_CACHE_INTERCEPTOR = new HttpContextToken(() => false); | ||
|
||
const DEBUG = false; | ||
|
||
const cache: Map<string, Observable<HttpEvent<unknown>>> = new Map(); | ||
|
||
export function biCacheInterceptor(req: HttpRequest<unknown>, next: HttpHandlerFn): Observable<HttpEvent<unknown>> { | ||
if (DEBUG) console.warn('cache interceptor run') | ||
if (req.method !== "GET" || !req.context.get(ICON_CACHE_INTERCEPTOR)) { | ||
return next(req); | ||
} | ||
const url = req.url; | ||
const cachedResponse = cache.get(url); | ||
if (DEBUG) console.log(`reading cache of ${url}`, cachedResponse) | ||
if (cachedResponse) { | ||
return cachedResponse; | ||
} else { | ||
if (DEBUG) console.log(`trying new request ${url}`) | ||
const newRequest = next(req).pipe( | ||
tap(stateEvent => { | ||
if (stateEvent instanceof HttpResponse) { | ||
if (DEBUG) console.log(`setting response to cache ${url}`) | ||
cache.set(url, of(stateEvent.clone()).pipe(share())); | ||
} | ||
}), | ||
share() | ||
); | ||
if (DEBUG) console.log(`setting new request ${url} to cache`) | ||
cache.set(url, newRequest); | ||
|
||
return newRequest; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.