Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'
})
)
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'
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,
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, {
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
}
}
)
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
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: [
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
}
}