Skip to content

Instantly share code, notes, and snippets.

Prashant Tiwari prashaantt

Block or report user

Report or block prashaantt

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
@prashaantt
prashaantt / BaseTable.ts
Last active Dec 26, 2016
Experiments with a tiny DB wrapper
View BaseTable.ts
// abstract: don't allow direct instantiation
abstract class BaseTable<T> {
// model holds the schema
protected model: T;
// convert kebab_case to camelCase
private camelCase(key: string) {
return key.replace(/_(\w)/g, function (...captures: string[]) {
return captures[1].toUpperCase();
});
View router-params.tsx
interface InjectedProps extends MyComponentProps {
params: RouterParams;
}
interface RouterParams {
name: string;
id: number; // nope
}
View non-nullable.ts
let s1: string;
s1 = "some string";
s1 = undefined; // Type 'undefined' is not assignable to type 'string'
s1 = null; // Type 'null' is not assignable to type 'string'
let s2: string | undefined;
s2 = "another string";
s2 = undefined;
s2 = null; // Type 'null' is not assignable to type 'string | undefined'
View nullable.ts
let s: string;
s = "some string";
s = null;
s = undefined;
View OtherComponent.tsx
interface MyComponentProps {
name: string;
countryCode?: string;
userStore: UserStore; // made required
router: InjectedRouter; // made required
}
...
class OtherComponent extends React.Component<{}, {}> {
View MyComponent3.tsx
@inject("userStore")
@withRouter
@observer
class MyComponent extends React.Component<MyComponentProps, {}> {
get injected() {
return this.props as InjectedProps;
}
render() {
const { name, countryCode } = this.props;
View MyComponent2.tsx
import * as React from "react";
import { inject, observer } from "mobx-react";
import { withRouter, InjectedRouter } from "react-router";
import { UserStore } from "../../stores/UserStore";
interface MyComponentProps {
name: string;
countryCode?: string;
userStore?: UserStore;
View interfaces.tsx
interface MyComponentProps {
name: string;
countryCode?: string;
}
interface InjectedProps extends MyComponentProps {
userStore: UserStore;
router: InjectedRouter;
}
View MyComponent.tsx
import * as React from "react";
interface MyComponentProps {
name: string;
countryCode?: string;
}
class MyComponent extends React.Component<MyComponentProps, {}> {
render() {
const { name, countryCode } = this.props;
View webpack.config.js
const Fs = require('fs');
const Path = require('path');
const files = [];
const nodeModules = {};
const getFilesAndSubdirectories = (dir) => {
Fs.readdirSync(dir)
.forEach((item) => {
You can’t perform that action at this time.