How to use the immutability-helper/index.js function in immutability-helper

To help you get started, we’ve selected a few immutability-helper 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 NERDDISCO / luminave / src / reducers / index.js View on Github external
return update(state, { controllers: { [controllerIndex]: { mapping: { [mappingIndex]: { active: { $set: active } } } } } })
    case constants.ADD_SCENE_TO_MIDI:
      return update(state, { controllers: { [controllerIndex]: { mapping: { [mappingIndex]: { scenes: { $push: [sceneId] } } } } } })
    case constants.ADD_SCENES_TO_MIDI: {
      // Get the current scenes to merge them with the new scenes
      const oldSceneIds = state.controllers[controllerIndex].mapping[mappingIndex].scenes

      // Only add scenes that are not part of the MIDI element yet
      const newSceneIds = sceneIds.filter(sceneId => !oldSceneIds.includes(sceneId))

      return update(state, { controllers: { [controllerIndex]: { mapping: { [mappingIndex]: { scenes: { $push: newSceneIds } } } } } })
    }

    case constants.REMOVE_SCENE_FROM_MIDI: {
      sceneIndex = state.controllers[controllerIndex].mapping[mappingIndex].scenes.indexOf(sceneId)
      return update(state, { controllers: { [controllerIndex]: { mapping: { [mappingIndex]: { scenes: { $splice: [[sceneIndex, 1]] } } } } } })
    }

    case constants.LEARN_MIDI:
      return update(state, { learning: { $set: mappingIndex } })
    case constants.REMOVE_MIDI:
      return update(state, { controllers: { $splice: [[controllerIndex, 1]] } })
    default:
      return state
  }
}
github NERDDISCO / luminave / src / reducers / index.js View on Github external
return state.map((fixture, i) => {

        // fixtureBatch contains properties for the fixture in state
        if (fixtureBatch[fixture.id] !== undefined) {
          return update(state[i], { properties: { $merge: fixtureBatch[fixture.id].properties } })
        } else {
          return state[i]
        }

      })
github NERDDISCO / luminave / src / reducers / luminave-server.js View on Github external
const luminaveServer = (state = {
  reconnect: false,
  connected: false,
  url: 'ws://localhost:4000/graphql',
  thorium: {
    scenes: []
  }
}, {
  type,
  data
}) => {

  switch (type) {

    case SET_LUMINAVE_SERVER: {
      return update(state, { $merge: { ...data } })
    }

    default:
      return state
  }
}
github NERDDISCO / luminave / src / reducers / venue.js View on Github external
}

    case ADD_VENUE_SLOT: {
      return update(state, { [venueIndex]: { slots: { $push: [slot] } } })
    }

    case SET_VENUE_SLOT: {
      const slotIndex = state[venueIndex].slots.findIndex(_slot => _slot.id === slot.id)

      return update(state, { [venueIndex]: { slots: { [slotIndex]: { $merge: slot } } } })
    }

    case REMOVE_VENUE_SLOT: {
      const slotIndex = state[venueIndex].slots.findIndex(_slot => _slot.id === slot.id)

      return update(state, { [venueIndex]: { slots: { $splice: [[slotIndex, 1]] } } })
    }

    default:
      return state
  }
}
github NERDDISCO / luminave / src / reducers / modv.js View on Github external
const modvManager = (state = {
  reconnect: false,
  connected: false,
  url: 'ws://localhost:3006/luminave'
}, {
  type,
  data
}) => {

  switch (type) {

    case SET_MODV: {
      return update(state, { $merge: { ...data } })
    }

    default:
      return state
  }
}
github NERDDISCO / luminave / src / reducers / index.js View on Github external
export const live = (state = false, { type, value }) => {
  switch (type) {
    case constants.SET_LIVE:
      return update(state, { $set: value })
    default:
      return state
  }
}
github NERDDISCO / luminave / src / reducers / timeline.js View on Github external
scenes: [],
  playing: false,
  progress: 0
}, { type, sceneId, scene, sceneIndex, playing, progress }) => {

  if (scene !== undefined && scene.sceneId !== undefined) {
    sceneIndex = state.scenes.findIndex(_scene => _scene.sceneId === scene.sceneId)
  }

  if (sceneId !== undefined) {
    sceneIndex = state.scenes.findIndex(scene => scene.sceneId === sceneId)
  }

  switch (type) {
    case PLAY_TIMELINE:
      return update(state, { playing: { $set: playing } })

    case ADD_SCENE_TO_TIMELINE: {
      return update(state, { scenes: { $push: [scene] } })
    }

    case SET_SCENE_ON_TIMELINE: {
      return sceneIndex === -1 
        ? state 
        : update(state, { scenes: { [sceneIndex]: { $merge: scene } } })
    }
      
    case REMOVE_SCENE_FROM_TIMELINE: {
      return sceneIndex === -1 
        ? state 
        : update(state, { scenes: { $splice: [[sceneIndex, 1]] } })
    }

immutability-helper

mutate a copy of data without changing the original source

MIT
Latest version published 4 years ago

Package Health Score

74 / 100
Full package analysis