Skip to content

Instantly share code, notes, and snippets.

View CharlieGreenman's full-sized avatar
🔎
Have you found my lost AI?

Charlie Greenman CharlieGreenman

🔎
Have you found my lost AI?
View GitHub Profile
@CharlieGreenman
CharlieGreenman / app.routing.module.ts
Created August 29, 2019 17:59
Pre-loading route data inside of app.routing.module.ts
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
@NgModule({
imports: [
RouterModule.forRoot(
[
{
path: 'books',
loadChildren: () =>
@CharlieGreenman
CharlieGreenman / app.module.routing.ts
Created August 29, 2019 18:06
app.routing.module.ts with CustomPreloadingService Provider
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { CustomPreloadingService } from '@razroo/common/ui/services';
@NgModule({
imports: [
RouterModule.forRoot(
[
// ...routes go here
],
@CharlieGreenman
CharlieGreenman / on-demand-preload.service.ts
Created August 29, 2019 18:12
OnDemandPreloadService that will be using within our CustomPreloadService
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
export class OnDemandPreloadOptions {
constructor(public routePath: string, public preload = true) {}
}
@Injectable({
providedIn: 'root'
})
@CharlieGreenman
CharlieGreenman / custom-preloading.service.ts
Created August 29, 2019 18:16
CustomPreloadingService with integrated OnDemandPreloadService
import { Injectable } from '@angular/core';
import { PreloadingStrategy, Route } from '@angular/router';
import { EMPTY, Observable, of } from 'rxjs';
import { mergeMap } from 'rxjs/operators';
import { OnDemandPreloadOptions, OnDemandPreloadService } from './on-demand-preload.service';
@Injectable({ providedIn: 'root', deps: [OnDemandPreloadService] })
export class CustomPreloadingService implements PreloadingStrategy {
private preloadOnDemand$: Observable<OnDemandPreloadOptions>;
@CharlieGreenman
CharlieGreenman / preload.directive.ts
Created August 29, 2019 18:23
Directive for preloading Angular Modules
import { Directive, ElementRef, HostListener } from '@angular/core';
import { OnDemandPreloadService } from '@razroo/common/services';
@Directive({
selector: '[razrooPreload]'
})
export class PreloadDirective {
constructor(private elementRef : ElementRef,
private onDemandPreloadService: OnDemandPreloadService) {}
@CharlieGreenman
CharlieGreenman / custom-preloading.service.ts
Created August 29, 2019 18:31
CustomPreloadingService with added logic for having a good connection
import { Injectable } from '@angular/core';
import { PreloadingStrategy, Route } from '@angular/router';
import { EMPTY, Observable, of } from 'rxjs';
import { mergeMap } from 'rxjs/operators';
import { OnDemandPreloadOptions, OnDemandPreloadService } from './on-demand-preload.service';
export declare var navigator;
@Injectable({ providedIn: 'root', deps: [OnDemandPreloadService] })
export class CustomPreloadingService implements PreloadingStrategy {
private preloadOnDemand$: Observable<OnDemandPreloadOptions>;
@CharlieGreenman
CharlieGreenman / mat-typography-config.scss
Created September 3, 2019 12:37
Angular Material Themes Sass file - mat-tyopgraphy-config file
// Represents a collection of typography levels.
// Defaults come from https://material.io/guidelines/style/typography.html
// Note: The spec doesn't mention letter spacing. The values here come from
// eyeballing it until it looked exactly like the spec examples.
@function mat-typography-config(
$font-family: 'Roboto, "Helvetica Neue", sans-serif',
// Large, one-off header, usually at the top of the page (e.g. a hero header).
$display-4: mat-typography-level(112px, 112px, 300, $letter-spacing: -0.05em),
// Large, one-off header, usually at the top of the page (e.g. a hero header).
$display-3: mat-typography-level(56px, 56px, 400, $letter-spacing: -0.02em),
@CharlieGreenman
CharlieGreenman / theming.scss
Created September 3, 2019 12:55
mat-base-typography part 1
@mixin mat-base-typography($config, $selector: '.mat-typography') {
.mat-h1, .mat-headline, #{$selector} h1 {
@include mat-typography-level-to-styles($config, headline);
margin: 0 0 16px;
}
.mat-h2, .mat-title, #{$selector} h2 {
@include mat-typography-level-to-styles($config, title);
margin: 0 0 16px;
}
@CharlieGreenman
CharlieGreenman / theming.scss
Created September 3, 2019 12:55
mat-base-typography part 1
@mixin mat-base-typography($config, $selector: '.mat-typography') {
.mat-h1, .mat-headline, #{$selector} h1 {
@include mat-typography-level-to-styles($config, headline);
margin: 0 0 16px;
}
.mat-h2, .mat-title, #{$selector} h2 {
@include mat-typography-level-to-styles($config, title);
margin: 0 0 16px;
}
@CharlieGreenman
CharlieGreenman / _theming.scss file
Created September 3, 2019 13:01
material header part 2
// Note: the spec doesn't have anything that would correspond to h5 and h6, but we add these for
// consistency. The font sizes come from the Chrome user agent styles which have h5 at 0.83em
// and h6 at 0.67em.
.mat-h5, #{$selector} h5 {
@include mat-typography-font-shorthand(
// calc is used here to support css variables
calc(#{mat-font-size($config, body-1)} * 0.83),
mat-font-weight($config, body-1),
mat-line-height($config, body-1),
mat-font-family($config, body-1)