How to use the redoodle.TypedAction.defineWithoutPayload function in redoodle

To help you get started, we’ve selected a few redoodle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ia-toki / judgels / judgels-frontends / raphael / src / modules / session / sessionReducer.ts View on Github external
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();
github ia-toki / judgels / judgels-frontends / raphael / src / routes / contests / contests / modules / contestWebConfigReducer.ts View on Github external
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();
github ia-toki / judgels / judgels-frontends / raphael / src / routes / contests / contests / modules / contestReducer.ts View on Github external
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();
github ia-toki / judgels / src / routes / uriel / competition / routes / contests / modules / contestReducer.ts View on Github external
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();
github fawind / notes / app / src / store / actions / auth.ts View on Github external
import { TypedAction } from 'redoodle';
import { loadNotes } from '@src/store/actions/notesAsync';
import { Dispatch } from 'redux';
import { ShowError } from '@src/store/actions/error';

const CLIENT_ID = '998747770178-tsvdpds9s2kam1u57u67ltuj383f7p3s.apps.googleusercontent.com';

export const SignedIn = TypedAction.define('SIGNED_IN')<{ idToken: string }>();
export const SignedOut = TypedAction.defineWithoutPayload('SIGNED_OUT')();

export const signIn = () => gapi.auth2.getAuthInstance().signIn();
export const signOut = () => gapi.auth2.getAuthInstance().signOut();

export const updateSignInStatus = (isSignedIn: boolean, dispatch: Dispatch) => {
  if (isSignedIn) {
    const idToken = gapi.auth2.getAuthInstance()
      .currentUser.get()
      .getAuthResponse().id_token;
    dispatch(SignedIn.create({ idToken }));
    dispatch(loadNotes());
  } else {
    dispatch(SignedOut.create());
  }
};
github ia-toki / judgels / judgels-frontends / raphael / src / routes / jophiel / modules / publicProfileReducer.ts View on Github external
import { TypedAction, TypedReducer } from 'redoodle';

import { PublicUserProfile } from '../../../modules/api/jophiel/userProfile';

export interface PublicProfileState {
  value?: PublicUserProfile;
}

export const INITIAL_STATE: PublicProfileState = {};

export const PutPublicProfile = TypedAction.define('jophiel/publicProfile/PUT')();
export const DelPublicProfile = TypedAction.defineWithoutPayload('jophiel/publicProfile/profile/DEL')();

function createPublicProfileReducer() {
  const builder = TypedReducer.builder();

  builder.withHandler(PutPublicProfile.TYPE, (state, payload) => ({ value: payload }));
  builder.withHandler(DelPublicProfile.TYPE, () => ({ value: undefined }));
  builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));

  return builder.build();
}

export const publicProfileReducer = createPublicProfileReducer();
github ia-toki / judgels / judgels-frontends / raphael / src / routes / courses / courses / single / chapters / modules / courseChapterReducer.ts View on Github external
import { setWith, TypedAction, TypedReducer } from 'redoodle';

import { CourseChapter } from '../../../../../../modules/api/jerahmeel/courseChapter';

export interface CourseChapterState {
  value?: CourseChapter;
  name?: string;
}

export const INITIAL_STATE: CourseChapterState = {};

export const PutCourseChapter = TypedAction.define('jerahmeel/courseChapter/PUT')<{
  value: CourseChapter;
  name: string;
}>();
export const DelCourseChapter = TypedAction.defineWithoutPayload('jerahmeel/courseChapter/DEL')();

function createCourseChapterReducer() {
  const builder = TypedReducer.builder();

  builder.withHandler(PutCourseChapter.TYPE, (state, payload) => setWith(state, payload));
  builder.withHandler(DelCourseChapter.TYPE, () => ({ value: undefined, name: undefined }));
  builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));

  return builder.build();
}

export const courseChapterReducer = createCourseChapterReducer();
github ia-toki / judgels / judgels-frontends / raphael / src / routes / jophiel / modules / profileReducer.ts View on Github external
import { TypedAction, TypedReducer } from 'redoodle';

export interface ProfileState {
  userJid?: string;
  username?: string;
}

export const INITIAL_STATE: ProfileState = {};

export const PutUser = TypedAction.define('jophiel/profile/PUT')<{
  userJid: string;
  username: string;
}>();
export const DelUser = TypedAction.defineWithoutPayload('jophiel/profile/DEL')();

function createProfileReducer() {
  const builder = TypedReducer.builder();

  builder.withHandler(PutUser.TYPE, (state, payload) => payload);
  builder.withHandler(DelUser.TYPE, () => ({ userJid: undefined, username: undefined }));
  builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));

  return builder.build();
}

export const profileReducer = createProfileReducer();
github ia-toki / judgels / judgels-frontends / raphael / src / routes / courses / courses / modules / courseReducer.ts View on Github external
import { setWith, TypedAction, TypedReducer } from 'redoodle';

import { Course } from '../../../../modules/api/jerahmeel/course';

export interface CourseState {
  value?: Course;
}

export const INITIAL_STATE: CourseState = {};

export const PutCourse = TypedAction.define('jerahmeel/course/PUT')();
export const DelCourse = TypedAction.defineWithoutPayload('jerahmeel/course/DEL')();

function createCourseReducer() {
  const builder = TypedReducer.builder();

  builder.withHandler(PutCourse.TYPE, (state, payload) => setWith(state, { value: payload }));
  builder.withHandler(DelCourse.TYPE, () => ({ value: undefined }));
  builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));

  return builder.build();
}

export const courseReducer = createCourseReducer();