Skip to content

Instantly share code, notes, and snippets.

@sirtimbly
sirtimbly / tslint.json
Created December 15, 2018 03:38
tslint for a design system project including legacy code
{
"defaultSeverity": "warning",
"extends": [
"tslint:recommended"
],
"rules": {
"quotemark": [true, "double"],
"indent": [true, "spaces", 2],
"interface-name": false,
"ordered-imports": false,
@sirtimbly
sirtimbly / stencil-plus-frets.ts
Last active November 13, 2018 22:27
Stencil and Function UI rendering experiment
import { Component, Prop } from "@stencil/core";
import { $ as t } from "../../tachyons-styles";
import { $ } from "./app-root-styles";
import { h } from "@stencil/core/dist/renderer/vdom";
@Component({
tag: "app-root",
styleUrls: ["app-root.css", "../../tachyons.css"],
shadow: false
})
export class MyActions {
public changeName: (e: Event) => void;
public saveName: (e: Event) => void;
public startOver: (e: Event) => void;
}
import { FRETS } from "frets";
@sirtimbly
sirtimbly / getIPLocation.ts
Created March 26, 2018 02:38
async network call
public getIPLocation = () => {
const context = this;
const req = axios.get("//freegeoip.net/json/")
.then((res) => {
if (res.data.region_code && res.data.region_code.length === 2) {
context.data.locationState = res.data.region_code;
}
context.renderer(context.data);
})
.catch((x) => { context.renderer(context.data); });
app.init([
{
comp: app.views.ViewLoader,
el: document.getElementById("mainapp"),
}]);
const app = new App<CalculationProps, ViewComponents>(container, {
locationState: "CO",
viewing: Views.HOME,
weight: 150,
} as CalculationProps);
const configuration: AppConfiguration<CustomProps, ViewComponents> = {
action: (m: Model<CustomProps>): ViewActions<CustomProps> => new AppViewActions(m),
model: {
validate: (props: CustomProps): Error[] => {
return []; // TODO
},
},
state: {
calculate: (props: CustomProps): CustomProps => {
props.hasUserData = ((props.gender === "MALE" || props.gender === "FEMALE") && props.weight > 0);
return $.button.circle.h({
classes: new CC().when(model.viewing === view)
.bgAqua.blue
.otherwise().bgSilver.red
.toObj,
}, ["OK"]);
return $.div.border.h({
classes: {
"bg-aqua": isActive,
"blue": isActive,
"bg-gray": !isActive,
"red": !isValid,
}}, []);