How to use the redoodle.TypedReducer.builder 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 / src / routes / uriel / competition / routes / contests / modules / contestReducer.ts View on Github external
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();
}
github ia-toki / judgels / judgels-frontends / raphael / src / modules / session / sessionReducer.ts View on Github external
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();
};
github ia-toki / judgels / judgels-frontends / raphael / src / modules / breadcrumbs / breadcrumbsReducer.ts View on Github external
const createBreadcrumbsReducer = () => {
  const builder = TypedReducer.builder();

  builder.withHandler(PushBreadcrumb.TYPE, (state, { link, ...rest }) => ({
    values: [...state.values, { link: cleanLink(link), ...rest }],
  }));
  builder.withHandler(PopBreadcrumb.TYPE, (state, payload) => ({
    values: state.values.filter(b => b.link !== cleanLink(payload.link)),
  }));
  builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));

  return builder.build();
};
github ia-toki / judgels / judgels-frontends / raphael / src / modules / webPrefs / webPrefsReducer.ts View on Github external
function createWebPrefsReducer() {
  const builder = TypedReducer.builder();

  builder.withHandler(PutStatementLanguage.TYPE, (state, statementLanguage) => setWith(state, { statementLanguage }));
  builder.withHandler(PutGradingLanguage.TYPE, (state, gradingLanguage) => setWith(state, { gradingLanguage }));
  builder.withDefaultHandler(state => (state !== undefined ? state : INITIAL_STATE));

  return builder.build();
}
github ia-toki / judgels / judgels-frontends / raphael / src / routes / jophiel / modules / roleReducer.ts View on Github external
function createRoleReducer() {
  const builder = TypedReducer.builder();

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

  return builder.build();
}
github ia-toki / judgels / judgels-frontends / raphael / src / routes / jophiel / modules / webConfigReducer.ts View on Github external
function createWebConfigReducer() {
  const builder = TypedReducer.builder();

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

  return builder.build();
}
github ia-toki / judgels / judgels-frontends / raphael / src / routes / courses / courses / modules / courseReducer.ts View on Github external
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();
}
github ia-toki / judgels / judgels-frontends / raphael / src / routes / jophiel / modules / publicProfileReducer.ts View on Github external
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();
}
github fawind / notes / app / src / store / reducers / selectedNote.ts View on Github external
function createReducer() {
  return TypedReducer.builder()
    .withHandler(Actions.NotesLoaded.TYPE, (state, payload) => {
      if (payload.notes.length === 0) {
        return { id: null };
      }
      return { id: sortNotes(payload.notes)[0].id };
    })
    .withHandler(Actions.NoteSelected.TYPE, (state, payload) => {
      return { id: payload.noteId };
    })
    .build();
}
github ia-toki / judgels / judgels-frontends / raphael / src / routes / jophiel / modules / profileReducer.ts View on Github external
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();
}