Skip to content

Instantly share code, notes, and snippets.

const style = document.createElement('style');
style.innerText = `
.text-base {
max-width: 100% !important;
padding-left: 20px !important;
padding-right: 20px !important;
}
`;
document.head.appendChild(style);
@shane935
shane935 / tsFeatures.md
Last active May 8, 2017 05:03
Random TS features

Typeguards

function isMap(maybeMap: any): maybeMap is Map<any, any>;

keyof

@shane935
shane935 / generics.md
Last active May 9, 2017 06:48
What are generics?

Generics are a mechanism to provide typings for a component after you have defined the type or interface.

Imagine we are creating an Input component in react that has a has a default value that can be of type string | number | Moment | boolean the way of typing this without generics would be like this:

interface Input {
  name: string,
  defaultValue: string | number | Moment | boolean,
  required: boolean,
  id: string
@shane935
shane935 / type-inference.md
Last active May 4, 2017 01:31
How Type Inference Works (kinda)

This is in reference to a change pull request.

original

withReducer<any, any>("FormState", "dispatch", withReducerState, Map()))

changed

withReducer("FormState", "dispatch", withReducerState, Map()))
@shane935
shane935 / cloudSettings
Created February 28, 2017 04:00
Visual Studio Code Sync Settings Gist
{"lastUpload":"2017-02-28T04:00:45.232Z","extensionVersion":"v2.5.1"}
import React from "react";
import { getData } from "../../common/request";
import CSS from "../../less/main.less";
var Modal = require("../../components/model.jsx");
import Article from "../../components/article.jsx"
import ArticleImage1 from "../../images/article1.jpeg";
import React from "react";
import classnames from "classnames";
import CSS from "../less/modal.less";
import close from "../images/cross.svg";
var eventPrefix = "Modal";
export default class Modal extends React.Component {
@shane935
shane935 / formData
Created April 4, 2015 07:01
Form Data
module.exports = function (formNodes) {
let formObject = {};
for (let i = 0; i < formNodes.length; i++) {
if (formNodes[i].nodeName === "INPUT" || formNodes[i].nodeName === "SELECT") {
formObject[formNodes[i].id] = formNodes[i].value;
}
}
return formObject;
};
@shane935
shane935 / For Loop
Created February 4, 2015 03:54
map vs for
for (var i = 0; i < recipes.length; i++) {
if (recipes[i][recipeProperty] !== undefined && recipes[i][recipeProperty].length > 0) {
filterArray = filterArray.concat(recipes[i][recipeProperty]);
}
}