Skip to content

Instantly share code, notes, and snippets.

View kasper573's full-sized avatar

Kasper kasper573

View GitHub Profile
import * as React from 'react';
const hoistNonReactStatic = require('hoist-non-react-statics');
/**
* Decorator to form a HOC that acts like a react context consumer.
* Useful when you want context to be made available in an entire component and not just in render.
*
* Example:
* type MyContextProps = {foo: string};
* const MyContext = createContext<MyContextProps>({foo: 'bar'});
import * as React from 'react';
import {Button, Typography} from '@material-ui/core';
import {FormTransportErrors, FormTransportResponse} from 'lib/FormTransport';
import {AppContext} from './AppContext';
import {Model} from './models/Model';
import {Snack, SnackStore} from './SnackStore';
import {failsafeUpdate} from './failsafeUpdate';
export async function failsafeUpdateWithSnack<T extends Model<any, any>> (
instance: T,
import {FormTransportErrors, FormTransportResponse} from 'lib/FormTransport';
import {Model} from './models/Model';
export async function failsafeUpdate<T extends Model<any, any>> (
instance: T,
changes: Partial<T>,
send: (updatedInstance: T) => Promise<FormTransportResponse<T, keyof T>>,
handleError?: (error: FormTransportErrors<keyof T>) => any
) {
const updated = new (instance.constructor as Class<T>)().update(instance).update(changes);
import {getDefaultModelSchema, object, PropSchema} from 'serializr';
/**
* A custom serializr schema that behaves like object() but requires the model later, allowing circular references.
*/
export function fnObject<T> (getModel: () => new (...args: any[]) => T): PropSchema {
const getSchema = () => getDefaultModelSchema(getModel());
return {
serializer: (...args: any[]) => (object(getSchema()).serializer as any)(...args),
deserializer: (...args: any[]) => (object(getModel()).deserializer as any)(...args)
import { CrudAction } from './CrudAction';
import { CrudReaction } from './CrudReaction';
import { CrudDefinition } from './CrudDefinition';
export type CrudDefinitions<Model = any, Query = ModelQuery<Model>> = Partial<{
create: CrudDefinition<Model, Model>,
read: CrudDefinition<Query, Model[]>,
update: CrudDefinition<Model, Model>,
delete: CrudDefinition<Model, boolean>
}>;
import {Crud} from 'lib/Crud';
import {FormTransportResponse} from 'lib/FormTransport';
import {User} from './models/User';
import {AppContext} from './AppContext';
import {createFixture} from '../lib/utils';
import {getDefaultModelSchema} from 'serializr';
const superAdmin = {
email: '[email protected]',
password: ''
{
"exclude": [
"node_modules"
],
"compilerOptions": {
"baseUrl": "src",
"allowJs": false,
"checkJs": false,
"sourceMap": true,
"experimentalDecorators": true,
type QueryValue = number | string | boolean | Date;
type Query<T> = {
[P in SubTypeKeys<T, QueryValue>]?: T[P] | T[P][]
};
type SubTypeKeys<Base, Condition> = {
[Key in keyof Base]: Base[Key] extends Condition ? Key : never
}[keyof Base];
function getInstances<T, C, B> (
target: T,
clazz: Class<C>,
transform: (instance: C) => B = noop
) {
const transformed: Record<keyof SubType<T, C>, B> = {} as any;
for (const key in target) {
const value = target[key];
if (value instanceof clazz) {
(transformed as any)[key] = transform(value);
import originalWithStyles, {
CSSProperties,
ClassNameMap,
StyleRules,
WithStylesOptions
} from '@material-ui/core/styles/withStyles'; // tslint:disable-line
import {IReactComponent} from 'mobx-react';
import {OcastTheme} from './OcastTheme';
export {CSSProperties};