Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { setWith, TypedAction, TypedReducer } from 'redoodle';
import { User } from '../../modules/api/jophiel/user';
export interface SessionState {
isLoggedIn: boolean;
token?: string;
user?: User;
}
// Somehow redux-persist won't work after dispatching DelSession if the next state is an empty object...
export const INITIAL_STATE: SessionState = { isLoggedIn: false };
export const PutToken = TypedAction.define('session/PUT_TOKEN')();
export const PutUser = TypedAction.define('session/PUT_USER')();
export const DelSession = TypedAction.defineWithoutPayload('session/DEL')();
const createSessionReducer = () => {
const builder = TypedReducer.builder();
builder.withHandler(PutToken.TYPE, (state, payload) => ({
isLoggedIn: true,
token: payload,
}));
builder.withHandler(PutUser.TYPE, (state, payload) => setWith(state, { user: payload }));
builder.withHandler(DelSession.TYPE, () => INITIAL_STATE);
builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));
return builder.build();
};
import { setWith, TypedAction, TypedReducer } from 'redoodle';
import { User } from '../../modules/api/jophiel/user';
export interface SessionState {
isLoggedIn: boolean;
token?: string;
user?: User;
}
// Somehow redux-persist won't work after dispatching DelSession if the next state is an empty object...
export const INITIAL_STATE: SessionState = { isLoggedIn: false };
export const PutToken = TypedAction.define('session/PUT_TOKEN')();
export const PutUser = TypedAction.define('session/PUT_USER')();
export const DelSession = TypedAction.defineWithoutPayload('session/DEL')();
const createSessionReducer = () => {
const builder = TypedReducer.builder();
builder.withHandler(PutToken.TYPE, (state, payload) => ({
isLoggedIn: true,
token: payload,
}));
builder.withHandler(PutUser.TYPE, (state, payload) => setWith(state, { user: payload }));
builder.withHandler(DelSession.TYPE, () => INITIAL_STATE);
builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));
return builder.build();
};
export const sessionReducer = createSessionReducer();
function createContestReducer() {
const builder = TypedReducer.builder();
builder.withHandler(PutContest.TYPE, (state, payload) => ({ value: payload }));
builder.withHandler(DelContest.TYPE, () => ({ value: undefined }));
builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));
return builder.build();
}
import { setWith, TypedAction, TypedReducer } from 'redoodle';
import { Contest } from '../../../../modules/api/uriel/contest';
export interface ContestState {
value?: Contest;
isEditing?: boolean;
}
export const INITIAL_STATE: ContestState = {};
export const PutContest = TypedAction.define('uriel/contest/PUT')();
export const DelContest = TypedAction.defineWithoutPayload('uriel/contest/DEL')();
export const EditContest = TypedAction.define('uriel/contest/EDIT')();
function createContestReducer() {
const builder = TypedReducer.builder();
builder.withHandler(PutContest.TYPE, (state, payload) => setWith(state, { value: payload }));
builder.withHandler(DelContest.TYPE, () => ({ value: undefined }));
builder.withHandler(EditContest.TYPE, (state, payload) => setWith(state, { isEditing: payload }));
builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));
return builder.build();
}
export const contestReducer = createContestReducer();
import { setWith, TypedAction, TypedReducer } from 'redoodle';
import { Contest } from '../../../../modules/api/uriel/contest';
export interface ContestState {
value?: Contest;
isEditing?: boolean;
}
export const INITIAL_STATE: ContestState = {};
export const PutContest = TypedAction.define('uriel/contest/PUT')();
export const DelContest = TypedAction.defineWithoutPayload('uriel/contest/DEL')();
export const EditContest = TypedAction.define('uriel/contest/EDIT')();
function createContestReducer() {
const builder = TypedReducer.builder();
builder.withHandler(PutContest.TYPE, (state, payload) => setWith(state, { value: payload }));
builder.withHandler(DelContest.TYPE, () => ({ value: undefined }));
builder.withHandler(EditContest.TYPE, (state, payload) => setWith(state, { isEditing: payload }));
builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));
return builder.build();
}
export const contestReducer = createContestReducer();
import { TypedAction, TypedReducer } from 'redoodle';
import { ContestWebConfig } from '../../../../modules/api/uriel/contestWeb';
export interface ContestWebConfigState {
value?: ContestWebConfig;
}
export const INITIAL_STATE: ContestWebConfigState = {};
export const PutWebConfig = TypedAction.define('uriel/contest/web/PUT_CONFIG')();
export const DelWebConfig = TypedAction.defineWithoutPayload('uriel/contest/web/DEL_CONFIG')();
function createContestWebConfigReducer() {
const builder = TypedReducer.builder();
builder.withHandler(PutWebConfig.TYPE, (state, payload) => ({ value: payload }));
builder.withHandler(DelWebConfig.TYPE, () => ({ value: undefined }));
builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));
return builder.build();
}
export const contestWebConfigReducer = createContestWebConfigReducer();
import { setWith, TypedAction, TypedReducer } from 'redoodle';
import { Contest } from '../../../../modules/api/uriel/contest';
export interface ContestState {
value?: Contest;
isEditing?: boolean;
}
export const INITIAL_STATE: ContestState = {};
export const PutContest = TypedAction.define('uriel/contest/PUT')();
export const DelContest = TypedAction.defineWithoutPayload('uriel/contest/DEL')();
export const EditContest = TypedAction.define('uriel/contest/EDIT')();
function createContestReducer() {
const builder = TypedReducer.builder();
builder.withHandler(PutContest.TYPE, (state, payload) => setWith(state, { value: payload }));
builder.withHandler(DelContest.TYPE, () => ({ value: undefined }));
builder.withHandler(EditContest.TYPE, (state, payload) => setWith(state, { isEditing: payload }));
builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));
return builder.build();
}
export const contestReducer = createContestReducer();
import { TypedAction, TypedReducer } from 'redoodle';
import { Contest } from '../../../../../../modules/api/uriel/contest';
export interface ContestState {
value?: Contest;
}
export const INITIAL_STATE: ContestState = {};
export const PutContest = TypedAction.define('uriel/contest/PUT')();
export const DelContest = TypedAction.defineWithoutPayload('uriel/contest/DEL')();
function createContestReducer() {
const builder = TypedReducer.builder();
builder.withHandler(PutContest.TYPE, (state, payload) => ({ value: payload }));
builder.withHandler(DelContest.TYPE, () => ({ value: undefined }));
builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));
return builder.build();
}
export const contestReducer = createContestReducer();
builder.withHandler(PutContest.TYPE, (state, payload) => setWith(state, { value: payload }));
builder.withHandler(DelContest.TYPE, () => ({ value: undefined }));
const createSessionReducer = () => {
const builder = TypedReducer.builder();
builder.withHandler(PutToken.TYPE, (state, payload) => ({
isLoggedIn: true,
token: payload,
}));
builder.withHandler(PutUser.TYPE, (state, payload) => setWith(state, { user: payload }));
builder.withHandler(DelSession.TYPE, () => INITIAL_STATE);
builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));
return builder.build();
};