Skip to content

Instantly share code, notes, and snippets.

View JonJam's full-sized avatar

Jonathan Harrison JonJam

View GitHub Profile
@JonJam
JonJam / groupSchema.ts
Last active September 11, 2017 07:40
Schemas
const groupSchema = {
type: "object",
properties: {
groups: {
type: "array",
minItems: 0,
maxItems: 5,
uniqueItems: true,
items: {
type: "object",
@JonJam
JonJam / generateData.ts
Created September 11, 2017 07:42
Creating a fake REST API with json-server - generateData
import { green, red } from "chalk";
import * as fs from "fs";
import * as jsf from "json-schema-faker";
import groupSchema from "./groupSchema";
import IGroup from "../src/models/IGroup";
import ISite from "../src/models/ISite";
import siteSchema from "./siteSchema";
const compiledGroupSchema = jsf(groupSchema);
@JonJam
JonJam / App.tsx
Last active October 25, 2017 18:33
react-redux-ts: Container component
import * as React from "react";
import { connect } from "react-redux";
import { RouteComponentProps, withRouter } from "react-router-dom";
import { bindActionCreators, Dispatch } from "redux";
import { signOut as signOutAction } from "../actions/authentication/authenticationActions";
import { homePath } from "../routes/paths";
import Routes from "../routes/Routes";
import { isBusy } from "../selectors";
import IStoreState from "../store/IStoreState";
import Header from "./header/Header";
@JonJam
JonJam / HomePage.tsx
Created October 25, 2017 18:00
react-redux-ts: Class component
import * as React from "react";
export default class HomePage extends React.Component {
public render() {
return (
<div className="jumbotron">
<h1 className="display-3 text-center">{"React app"}</h1>
<p className="lead text-center">
{
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vel augue turpis. Suspendisse malesuada lacus nec metus pharetra sodales. Nunc tellus quam, mollis a dictum et, luctus maximus libero."
@JonJam
JonJam / NavBar.tsx
Created October 25, 2017 18:04
react-redux-ts: Functional component
import * as React from "react";
import { Link } from "react-router-dom";
import { homePath, signUpPath } from "../../../routes/paths";
import logo from "./logo.svg";
import "./NavBar.css";
interface INavBarProps {
readonly isAuthenticated: boolean;
@JonJam
JonJam / IStoreState.ts
Last active October 25, 2017 18:10
react-redux-ts: Store
export default interface IStoreState {
readonly pendingActions: number;
readonly isAuthenticated: boolean;
};
@JonJam
JonJam / pendingActionsReducer.ts
Created October 25, 2017 18:12
react-redux-ts: Reducer
import ActionTypeKeys, { ActionTypeStates } from "../actions/ActionTypeKeys";
import ActionTypes from "../actions/ActionTypes";
import initialState from "./initialState";
export default function pendingActionsReducer(
state = initialState.pendingActions,
action: ActionTypes
) {
if (actionTypeEndsInInProgress(action.type)) {
return onInProgressAction(state);
@JonJam
JonJam / actionTypeKeys.ts
Last active October 27, 2017 06:57
react-redux-ts: Actions types
export enum ActionTypeStates {
INPROGRESS = "_INPROGRESS",
SUCCESS = "_SUCCESS",
FAIL = "_FAIL"
}
enum ActionTypeKeys {
SIGNIN_INPROGRESS = "SIGNIN_INPROGRESS",
SIGNIN_SUCCESS = "SIGNIN_SUCCESS",
SIGNIN_FAIL = "SIGNIN_FAIL",
@JonJam
JonJam / authenticationActions.ts
Last active October 27, 2017 06:56
react-redux-ts: Actions
import { Dispatch } from "redux";
import {
signIn as signInToApi,
signOut as signOutFromApi
} from "../../api/authenticationApi";
import IStoreState from "../../store/IStoreState";
import keys from "../ActionTypeKeys";
import {
ISignInFailAction,
ISignInInProgressAction,
@JonJam
JonJam / Site.ts
Created November 1, 2017 08:47
validation-ts: class
import { IsEmail, IsNotEmpty, IsUrl, MaxLength } from "class-validator";
interface ISite {
readonly name: string;
readonly url: string;
readonly emailAddress: string;
readonly password: string;
}
export default class Site implements ISite {