Skip to content

Instantly share code, notes, and snippets.

View brandonroberts's full-sized avatar

Brandon Roberts brandonroberts

View GitHub Profile
import {Injectable} from 'angular2/core';
import {Http} from 'angular2/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/map';
const GITHUB_API_URL = 'https://api.github.com';
export class Repository {
name: string;
full_name: string;
@brandonroberts
brandonroberts / introrx.md
Created January 11, 2018 18:12 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
import { Store, Action, ofType } from '@ngrx/store';
import { catchError } from 'rxjs/operators';
import { of } from 'rxjs/observable/of';
import { switchMap, map } from 'rxjs/operators';
export class EffectError implements Action {
readonly type = '[Error] Effect Error';
}
@Injectable()

Everything I Know About UI Routing

Definitions

  1. Location - The location of the application. Usually just a URL, but the location can contain multiple pieces of information that can be used by an app
    1. pathname - The "file/directory" portion of the URL, like invoices/123
    2. search - The stuff after ? in a URL like /assignments?showGrades=1.
    3. query - A parsed version of search, usually an object but not a standard browser feature.
    4. hash - The # portion of the URL. This is not available to servers in request.url so its client only. By default it means which part of the page the user should be scrolled to, but developers use it for various things.
    5. state - Object associated with a location. Think of it like a hidden URL query. It's state you want to keep with a specific location, but you don't want it to be visible in the URL.
@brandonroberts
brandonroberts / Every possible TypeScript type.md
Created January 5, 2021 00:06 — forked from laughinghan/Every possible TypeScript type.md
Diagram of every possible TypeScript type

Hasse diagram of every possible TypeScript type

  • any: magic, ill-behaved type that acts like a combination of never (the proper [bottom type]) and unknown (the proper [top type])
    • Anything at all is assignable to any, and any is assignable to anything at all.
    • Identities: any & AnyTypeExpression = any, any | AnyTypeExpression = any
    • Key TypeScript feature that allows for [gradual typing].
  • unknown: proper, well-behaved [top type]
    • Anything at all is assignable to unknown. unknown is only assignable to itself (unknown) and any.
    • Identities: unknown & AnyTypeExpression = AnyTypeExpression, unknown | AnyTypeExpression = unknown
  • Prefer over any whenever possible. Anywhere in well-typed code you're tempted to use any, you probably want unknown.
@brandonroberts
brandonroberts / ngrx.ts
Created May 6, 2022 13:30 — forked from alxhub/ngrx.ts
ngrx add features example
function configureStoreWithFeature(feature: ...): Provider[] {
return [
{
provide: Store,
useFactory: () => {
const rootStore = inject(RootStore);
for (const feature of inject(STORE_FEATURE, [])) {
rootStore.registerFeature(feature);
}
return rootStore;
@brandonroberts
brandonroberts / 1.ngx-reactify.tsx
Created August 16, 2022 13:24 — forked from lacolaco/1.ngx-reactify.tsx
A React component to render a standalone Angular component (Angular v14.2 is required)
import { ComponentRef, createComponent, Type } from "@angular/core";
import { createApplication } from "@angular/platform-browser";
import React, { useEffect, useRef, useState } from "react";
type AnyComponentRef = ComponentRef<unknown>;
export type ReactifyProps = {
component: Type<unknown>;
inputs?: Record<string, unknown>;
};