This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | |
}>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"exclude": [ | |
"node_modules" | |
], | |
"compilerOptions": { | |
"baseUrl": "src", | |
"allowJs": false, | |
"checkJs": false, | |
"sourceMap": true, | |
"experimentalDecorators": true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; |