Пример #1
0
const mapDispatchToProps = (dispatch, {block, song}) => ({

  onClickAdd() {
    const index = song.blocks.indexOf(block.id)
    dispatch(songs.actions.createBlockAt(song.id, index + 1))
  },

  onClickDupe() {
    const index = song.blocks.indexOf(block.id)
    const blockId = dispatch(blocks.actions.deepCopy(block.id)).payload.copy.id
    dispatch(songs.actions.addBlockAt(song.id, blockId, index + 1))
  },

  onClickDestroy() {
    if (!song.blocks.includes(block.id))
      return
    const prevBlock = before(song.blocks, block.id)
    const nextBlock = after(song.blocks, block.id)
    if (!isNil(prevBlock)) {
      dispatch(url.actions.setBrowserUrl(
        '/blocks/' + prevBlock , {replaceState: true}
      ))
    } else if (!isNil(nextBlock)) {
      dispatch(url.actions.setBrowserUrl(
        '/blocks/' + nextBlock, {replaceState: true}
      ))
    } else {
      dispatch(url.actions.setBrowserUrl(
        '/songs/' + song.id, {replaceState: true}
      ))
    }
    dispatch(blocks.actions.destroy(block.id))
  },

})
Пример #2
0
 it("Deep copies a block.", () => {
   const store = createStore(
     combineReducers({
       id: id.reducer,
       channels: channels.reducer,
       blocks: blocks.reducer,
     }),
     {
       id: '0',
       blocks: {
         0: {id: '0', channels: ['10', '11']},
       },
       channels: {
         10: {id: '10', blips: []},
         11: {id: '11', blips: []},
       },
     },
     applyMiddleware(thunk)
   )
   store.dispatch(blocks.actions.deepCopy('0'))
   expect(store.getState()).toEqual({
     id: '3',
     blocks: {
       0: {id: '0', channels: ['10', '11']},
       1: {id: '1', channels: ['2', '3']},
     },
     channels: {
       2: {id: '2', blips: []},
       3: {id: '3', blips: []},
       10: {id: '10', blips: []},
       11: {id: '11', blips: []},
     },
   })
 })
Пример #3
0
 it("Adds a channel to a block.", () => {
   const stateBefore = {
     b: {channels: []}
   }
   const action = blocks.actions.addChannel('b', 'c')
   const stateAfter = {
     b: {channels: ['c']}
   }
   expect(
     blocks.reducer(stateBefore, action)
   ).toEqual(stateAfter)
 })
Пример #4
0
 it("Destroys a block.", () => {
   const stateBefore = {
     1: {id: 1},
     2: {id: 2}
   }
   const action = blocks.actions.destroy(1)
   const stateAfter = {
     2: {id: 2}
   }
   expect(
     blocks.reducer(stateBefore, action)
   ).toEqual(stateAfter)
 })
Пример #5
0
 it("Creates a block.", () => {
   const store = createStore(
     combineReducers({
       id: id.reducer,
       blocks: blocks.reducer,
     }),
     applyMiddleware(thunk)
   )
   const stateBefore = undefined
   store.dispatch(
     blocks.actions.create({id: 'foo'})
   )
   const stateAfter = {
     foo: {
       ...blockInitialState,
       id: 'foo',
     }
   }
   expect(
     store.getState().blocks
   ).toEqual(stateAfter)
 })