Skip to content

Instantly share code, notes, and snippets.

☕️
Focusing

John O'Sullivan john-osullivan

☕️
Focusing
Block or report user

Report or block john-osullivan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@john-osullivan
john-osullivan / no-stutter.ts
Created Sep 16, 2019
Dev Diaries #2: Demonstration of stuttering
View no-stutter.ts
// Stuttering
const args: AuthMethods.LoginMethod.LoginArgs = { ... };
// No stuttering
const args: Auth.Login.Args = { ... };
@john-osullivan
john-osullivan / package.json
Created Sep 16, 2019
Dev Diaries #2 - Sample package.json from the User submodule
View package.json
{
"main" : "../../build/user/index.js",
"types": "./index.ts"
}
@john-osullivan
john-osullivan / index.ts
Last active Sep 16, 2019
Dev Diaries #2 - Sample index file from the User submodule
View index.ts
// This line takes all of the exports from that
// file and wraps them into a single namespace.
// If we didn't do this "* as User" syntax here,
// then a consumer would have to do it in order
// to get a convenient namespace.
import * as User from './user';
// This line directly surfaces all of its non-default
// exports from right here, so that users can just
// grab one item from there, e.g.:
@john-osullivan
john-osullivan / easy-imports.ts
Last active Sep 17, 2019
Dev Diaries #2 - Module layout for easy imports
View easy-imports.ts
// The type reference is so wordy! This isn't convenient.
import Types from '@eximchain/dappbot-types';
const args: Types.Methods.Auth.Login.Args = { ... };
// We can make the reference more compact by importing a
// more specific slice of the overall types.
import Auth from '@eximchain/dappbot-types/spec/methods';
const args: Auth.Login.Args = { ... };
@john-osullivan
john-osullivan / sample-validator-naming.ts
Last active Sep 16, 2019
Dev Diaries #2 - Types Naming Convention
View sample-validator-naming.ts
export interface SomeData {
foo: string
bar: string
}
export function newSomeData(): SomeData {
return {
foo: 'example',
bar: 'object'
}
View sample-login-call.ts
import { Login } from '@eximchain/dappbot-types/spec/methods/auth';
import request from 'request-promise-native';
const baseApiUrl = 'https://api.dapp.bot';
async function loginToDappbot(creds:Login.Args):Login.Result {
const res:Login.Response = await request({
headers : { 'Content-Type' : 'application/json' },
method : Login.HTTP,
@john-osullivan
john-osullivan / auth.ts
Last active Sep 16, 2019
Dev Diaries #2 - Example API namespace
View auth.ts
import { XOR } from 'ts-xor';
import { ApiResponse } from '../../responses';
export namespace Login {
export const HTTP:HttpMethods.POST = 'POST';
export const Path = `${authBasePath}/${ResourcePaths.login}`
export interface Args {
username: string,
@john-osullivan
john-osullivan / using-stripe-types.ts
Created Sep 16, 2019
Dev Diaries #2 - StripeTypes Import
View using-stripe-types.ts
import API from '@eximchain/dappbot-api-client';
import Payment, { StripeTypes } from '@eximchain/dappbot-types/spec/methods/payment';
// Nested namespaces make for legible collision-free names
const res:Payment.Read.Response = await API.payment.read.call();
// Helper namespace cuts down on extra text
const subscription:StripeTypes.Subscription = res.data.subscription;
@john-osullivan
john-osullivan / sample-payment-type.ts
Created Sep 16, 2019
Dev Daries #2 - Example namespace of types from Stripe
View sample-payment-type.ts
import AllStripeTypes from 'stripe';
export namespace StripeTypes {
export type Customer = AllStripeTypes.customers.ICustomer;
export type Card = AllStripeTypes.ICard;
export type Subscription = AllStripeTypes.subscriptions.ISubscription;
export type SubscriptionState = AllStripeTypes.subscriptions.SubscriptionStatus;
export type Invoice = AllStripeTypes.invoices.IInvoice;
@john-osullivan
john-osullivan / LoginScreen.tsx
Last active Sep 16, 2019
Dev Diaries #2 - Type Factory in useState
View LoginScreen.tsx
export function LoginScreen(props) {
const [loginArgs, setLoginArgs] = React.useState(Login.newArgs());
async function submitLogin() {
const res:Login.Response = await DappbotAPI.auth.login.call(loginArgs);
...
}
return (
...
You can’t perform that action at this time.