How to use the redux-act.createReducer function in redux-act

To help you get started, we’ve selected a few redux-act 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 WorldBrain / Memex / src / overview / onboarding / reducer.ts View on Github external
// Decides whether or not to show the Congrats message
    // Set to true after all stages are done
    congratsMessage: boolean
}

const defState = {
    annotationStage: '',
    powerSearchStage: '',
    taggingStage: '',
    backupStage: '',
    showOnboardingBox: false,
    congratsMessage: false,
}

const reducer = createReducer({}, defState)

reducer.on(actions.setAnnotationStage, (state, payload) => ({
    ...state,
    annotationStage: payload,
}))

reducer.on(actions.setPowerSearchStage, (state, payload) => ({
    ...state,
    powerSearchStage: payload,
}))

reducer.on(actions.setTaggingStage, (state, payload) => ({
    ...state,
    taggingStage: payload,
}))
github WorldBrain / Memex / src / overview / results / reducer.ts View on Github external
: [...state.results, ...payload.docs]

    const annotsByDay =
        payload.annotsByDay && overwrite
            ? payload.annotsByDay
            : { ...state.annotsByDay, ...payload.annotsByDay }

    return {
        ...state,
        ...commonState,
        results,
        annotsByDay,
    }
}

const reducer = createReducer({}, defState)

reducer.on(acts.setShowOnboardingMessage, (state, showOnboardingMessage) => ({
    ...state,
    showOnboardingMessage,
}))

reducer.on(acts.addTag, (state, { tag, index }) => {
    const doc = state.results[index]

    return {
        ...state,
        results: [
            ...state.results.slice(0, index),
            {
                ...doc,
                tags: [...doc.tags, tag],
github gluon-project / gluon-rxp / src / Reducers / ContactsReducer.ts View on Github external
}

const initialState: ContactsState = {
  groupClaimsBy: null,
  roomForSharing: null,
  editing: null,
  newClaimType: null,
  newClaimValue: null,
  selectedContact: null,
  list: Config.contacts.defaultList,
  claims: Config.contacts.defaultClaimsList,
  matrixClaims: [],
  hiddenDataSources: [],
}

export const reducer = createReducer({}, initialState)
reducer.on(resetToInitialState, (state: ContactsState) => {
  return initialState
})

export const toggleHiddenDataSource = createAction('Toggle hidden datasource')
reducer.on(toggleHiddenDataSource, (state: ContactsState, payload?: DataSource) => {
  let currentHiddenDataSources = [...state.hiddenDataSources]
  if (find(currentHiddenDataSources, payload)) {
    remove(currentHiddenDataSources, (source: DataSource) => {
      return source.type === payload.type && source.id === payload.id
    })
  } else {
    currentHiddenDataSources.push(payload)
  }
  return {
    ...state,
github gluon-project / gluon-rxp / src / Reducers / TokensReducer.ts View on Github external
const emptyBurnTransaction: BurnTransaction = {
  numTokens: '0',
  reward: '0',
}

const initialState: TokensState = {
  current: Config.tokens.defaultList[0].address,
  mintTransaction: emptyMintTransaction,
  burnTransaction: emptyBurnTransaction,
  new: null,
  list: Config.tokens.defaultList,
  available: [],
}

export const reducer = createReducer({}, initialState)
reducer.on(resetToInitialState, (state: TokensState) => {
  return initialState
})

export const addToken = createAction('Add token')
reducer.on(addToken, (state: TokensState, payload?: Token) => {
  return {
    ...state,
    list: uniqBy([ ...state.list, payload ], (token: Token) => token.address),
  }
})

export const selectToken = createAction('Select token')
reducer.on(selectToken, (state: TokensState, payload?: string) => {
  return {
    ...state,
github tsirlucas / soundplace / src / core / player / player.reducer.ts View on Github external
import {combineReducers} from 'redux';
import {createReducer} from 'redux-act';

import {IndexedTracks} from 'models';

import {actions} from './player.actions';

export const initialState = {
  list: null as IndexedTracks,
  isPlaying: false,
  currentTime: null as number,
  duration: null as number,
  currentId: null as string,
};

const currentId = createReducer({}, initialState.currentId).on(
  actions.playMusic,
  (_state, payload) => payload,
);

const isPlaying = createReducer({}, initialState.isPlaying)
  .on(actions.playMusic, () => true)
  .on(actions.toggle, (state) => !state);

const currentTime = createReducer({}, initialState.currentTime).on(
  actions.updateTime,
  (_state, {currentTime}) => currentTime,
);

const duration = createReducer({}, initialState.duration)
  .on(actions.updateTime, (_state, {duration}) => duration)
  .on(actions.playMusic, () => null);
github nick121212 / fx-schema-form / packages / fx-schema-form-react / libs / reducers / schema.form.js View on Github external
get reducer() {
        return createReducer({
            [this.createForm]: this.createFormHandle.bind(this),
            [this.updateItemData]: this.updateItemDataHandle.bind(this),
            [this.updateItemMeta]: this.updateItemMetaHandle.bind(this),
            [this.addItem]: this.addItemDataHandle.bind(this),
            [this.removeItem]: this.removeItemHandle.bind(this),
            [this.moveToItem]: this.moveItemHandle.bind(this),
            [this.removeItemData]: this.removeItemDataMetaHandle.bind(this),
            [this.combineActions]: this.combineActionsHandle.bind(this),
            [this.removeForm]: this.removeFormHandle.bind(this),
            [this.removeMetaKeys]: this.removeMetaKeysHandle.bind(this),
        }, this.initialState);
    }
    removeFormHandle(state, parentKeys) {
github nick121212 / fx-schema-form / packages / fx-schema-form-react / libs / reducer / form.js View on Github external
get reducer() {
        return createReducer({
            [this.updateItem]: this.updateItemHandle.bind(this),
            [this.toggleItem]: this.toggleItemHandle.bind(this),
            [this.addItem]: this.addItemHandle.bind(this),
            [this.removeItem]: this.removeItemHandle.bind(this),
            [this.switchItem]: this.switchItemHandle.bind(this),
            [this.updateMetaState]: this.updateMetaStateHandle.bind(this),
            [this.updateItemMeta]: this.updateMetaHandle.bind(this),
            [this.updateData]: this.updateDataHandle.bind(this),
            [this.removeItemMap]: this.removeItemMapHandle.bind(this)
        }, this.initialState);
    }
    updateDataHandle(state, data) {
github nick121212 / fx-schema-form / packages / fx-schema-form-react / dist / dts / reducers / schema.form.js View on Github external
get reducer() {
        return createReducer({
            [this.createForm]: this.createFormHandle.bind(this),
            [this.updateItemData]: this.updateItemDataHandle.bind(this),
            [this.updateItemMeta]: this.updateItemMetaHandle.bind(this),
            [this.addItem]: this.addItemDataHandle.bind(this),
            [this.removeItem]: this.removeItemDataHandle.bind(this),
            [this.switchItem]: this.switchItemHandle.bind(this),
            [this.moveToItem]: this.moveItemHandle.bind(this),
        }, this.initialState);
    }
    resolveKeys(state, keys) {
github nick121212 / fx-schema-form / packages / fx-schema-form-react / dts / reducers / schema.form.js View on Github external
get reducer() {
        return createReducer({
            [this.createForm]: this.createFormHandle.bind(this),
            [this.updateItemData]: this.updateItemDataHandle.bind(this),
            [this.updateItemMeta]: this.updateItemMetaHandle.bind(this),
            [this.addItem]: this.addItemDataHandle.bind(this),
            [this.removeItem]: this.removeItemDataHandle.bind(this),
            [this.switchItem]: this.switchItemHandle.bind(this),
            [this.moveToItem]: this.moveItemHandle.bind(this),
        }, this.initialState);
    }
    resolveKeys(state, keys) {

redux-act

An opinionated lib to create actions and reducers for Redux

Apache-2.0
Latest version published 5 years ago

Package Health Score

53 / 100
Full package analysis