How to use the redux-rails.apiReducer function in redux-rails

To help you get started, we’ve selected a few redux-rails 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 instacart / redux-rails / demo / index.js View on Github external
const reduxRailsConfig = combineConfigs(
  defaultConfig,
  apiConfig,
  commentsConfig,
  photosConfig
)


// redux store
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const siteApp = window.siteApp = createStore(
  combineReducers({
    counter: counterReducer,
    models: apiReducer(apiConfig),
    resources: apiReducer(resourcesConfig)
  }),
  {},
  composeEnhancers(
    applyMiddleware(middleWare(reduxRailsConfig)),
  )
);

window.setTimeout(() => {
  console.log('starting state', siteApp.getState())

  siteApp.dispatch({
    type: 'increment'
  })
  siteApp.dispatch({
    type: 'increment'
  })
github instacart / redux-rails / demo / index.js View on Github external
)

const reduxRailsConfig = combineConfigs(
  defaultConfig,
  apiConfig,
  commentsConfig,
  photosConfig
)


// redux store
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const siteApp = window.siteApp = createStore(
  combineReducers({
    counter: counterReducer,
    models: apiReducer(apiConfig),
    resources: apiReducer(resourcesConfig)
  }),
  {},
  composeEnhancers(
    applyMiddleware(middleWare(reduxRailsConfig)),
  )
);

window.setTimeout(() => {
  console.log('starting state', siteApp.getState())

  siteApp.dispatch({
    type: 'increment'
  })
  siteApp.dispatch({
    type: 'increment'
github instacart / redux-rails / test / apiReducer.spec.js View on Github external
describe('SHOW actions with custom idAttribute', () => {
      const customIdConfig = {
        domain: 'http://localhost:3000/',
        resources: {
          Posts: {
            controller: 'posts',
            idAttribute: '@@_id_'
          }
        }
      }

      const customIdReducer = apiReducer(customIdConfig)
      let customIdReducerState = {}

      it('should create the member and set the loading state on the member after SHOW action', () => {
        customIdReducerState = customIdReducer(customIdReducerState, railsActions.show({
          resource: 'Posts',
          id: 4135
        }))

        expect(customIdReducerState).toEqual(
          {
            Posts: {
              loading: false,
              loadingError: undefined,
              models: [{
                '@@_id_': 4135,
                loading: true,
github instacart / redux-rails / test / apiReducer.spec.js View on Github external
describe('CREATE actions with custom idAttribute', () => {
      const customIdConfig = {
        domain: 'http://localhost:3000/',
        resources: {
          Posts: {
            controller: 'posts',
            idAttribute: '@@_id_'
          }
        }
      }
      const createReducer = apiReducer(customIdConfig)
      let createReducerState = {}

      it('should set the attributes of the member in the collection on success of CREATE call with custom id attribute', () => {
        const response = {
          '@@_id_': 4135,
          title: 'Three weird tricks for testing Redux Rails',
          body: '1: use Jest. 2: profit. 3: maybe this should only be 2 weird tricks...'
        }

        const cId = getUniqueClientId()

        createReducerState = createReducer({}, {
          type: 'Posts.ASSIGN_CID', cId
        })

        createReducerState = createReducer(createReducerState, {
github instacart / redux-rails / test / apiReducer.spec.js View on Github external
describe('apiReducer', () => {

  const standardReducer = apiReducer(standardConfig)

  it('should return correct intial state', () => {
    expect(
      standardReducer(undefined, {})
    ).toEqual(
      {
        Posts: {
          loading: false,
          loadingError: undefined
        },
        User: {
          loading: false,
          loadingError: undefined
        }
      }
    )
github instacart / redux-rails / test / apiReducer.spec.js View on Github external
describe('SHOW actions', () => {
    const showReducer = apiReducer(standardConfig)
    let showReducerState = {}

    it('should create member and set a loading state on the member within a collection', () => {
      showReducerState = showReducer(showReducerState, railsActions.show({
        resource: 'Posts',
        id: 123
      }))
      expect(showReducerState).toEqual(
        {
          Posts: {
            loading: false,
            loadingError: undefined,
            models: [{
              id: 123,
              loading: true,
              loadingError: undefined
github instacart / redux-rails / test / apiReducer.spec.js View on Github external
describe('CREATE actions', () => {
    const createReducer = apiReducer(standardConfig)
    let createReducerState = {}


    it('should create a new member and assign it a cId', () => {
      const cId = getUniqueClientId()

      createReducerState = createReducer(createReducerState, {
        type: 'Posts.ASSIGN_CID', cId
      })

      expect(createReducerState).toEqual(
        {
          Posts: {
            loading: false,
            loadingError: undefined,
            models: [
github instacart / redux-rails / test / apiReducer.spec.js View on Github external
describe('INDEX actions', () => {
    const indexReducer = apiReducer(standardConfig)
    let indexReducerState = {}

    it('should set a loading state on the collection', () => {
      indexReducerState = indexReducer(indexReducerState, railsActions.index({ resource: 'Posts' }))

      expect(indexReducerState).toEqual(
        {
          Posts: {
            loading: true,
            loadingError: undefined
          },
          User: {
            loading: false,
            loadingError: undefined
          }
        }

redux-rails

Redux and your server talking without fuss.

Apache-2.0
Latest version published 3 years ago

Package Health Score

51 / 100
Full package analysis