Skip to content

Instantly share code, notes, and snippets.

@TheUltDev
Last active March 16, 2019 22:27
Show Gist options
  • Save TheUltDev/e7b3fd1ede08ee03cdd365e1d99a544e to your computer and use it in GitHub Desktop.
Save TheUltDev/e7b3fd1ede08ee03cdd365e1d99a544e to your computer and use it in GitHub Desktop.
type FunctionType = (...args: any[]) => any;
type ActionCreatorsMapObject = {[actionCreator: string]: FunctionType};
export type ActionsUnion<A extends ActionCreatorsMapObject> = ReturnType<A[keyof A]>
export interface Action<T extends string> {
type: T
};
export interface ActionWithPayload<T extends string, P> extends Action<T> {
payload: P
};
export function createAction<T extends string>(type: T): Action<T>;
export function createAction<T extends string, P>(type: T, payload: P): ActionWithPayload<T, P>;
export function createAction<T extends string, P>(type: T, payload?: P) {
return payload === undefined ? {type} : {type, payload};
};
import {ContentItem, ContentFolder} from './ContentModels';
import {createAction, ActionsUnion} from '../lib/actions';
export const enum ContentActionTypes {
MoveItem = '[content] move item',
CopyItem = '[content] copy item',
};
export const ContentActions = {
moveItem: (items: Array<ContentItem['id']>, destination: ContentFolder['id']) =>
createAction(ContentActionTypes.MoveItem, {items, destination}),
copyItem: (items: Array<ContentItem['id']>, destination: ContentFolder['id']) =>
createAction(ContentActionTypes.CopyItem, {items, destination}),
};
export type ContentActions = ActionsUnion<typeof ContentActions>;
export interface ContentItem {
readonly id: string;
readonly name: string;
readonly size: number;
readonly revision: number;
readonly parent?: ContentItem;
}
export interface ContentFile extends ContentItem {
readonly filetype: string;
}
export interface ContentFolder extends ContentItem {
readonly files: ContentFile[];
readonly folders: ContentFolder[];
}
export type ContentState = {
readonly items: {[id: string]: ContentItem},
readonly searchItems: ContentItem[],
readonly recentItems: ContentItem[]
};
import {ContentState} from './ContentModels';
import {ContentActionTypes, ContentActions} from './ContentActions';
export const InitialState: ContentState = {
items: {},
searchItems: [],
recentItems: []
};
export default (state = InitialState, action: ContentActions): ContentState => {
switch (action.type) {
case ContentActionTypes.MoveItem: {
return state;
}
case ContentActionTypes.CopyItem: {
return state;
}
default: return state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment