How to use the immutadot/core/update.update function in immutadot

To help you get started, we’ve selected a few immutadot 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 Zenika / marcel / backoffice / src / dashboard / reducer.js View on Github external
const removeChilds = (pluginInstances, instanceId) => {
        const plugin = pluginInstances[instanceId]
        if (!plugin) return pluginInstances

        const pluginListProps = pickBy(plugin.props, { type: 'pluginList' })
        const pluginsToRemove = flatten(map(values(pluginListProps), 'value'))

        if (!pluginsToRemove.lenght) return pluginInstances

        const cleanedPluginInstances = omit(pluginInstances, pluginsToRemove)
        return reduce(pluginsToRemove, removeChilds, cleanedPluginInstances)
      }

      return flow(
        update(`pluginInstances`, pluginInstances => removeChilds(pluginInstances, instanceId)),
        unset(`pluginInstances.${instanceId}`),
        pull(
          parent
            ? `pluginInstances.${parent.plugin}.props.${parent.prop}.value`
            : `dashboards.${selectedDashboard}.plugins`,
          instanceId,
        ),
        set(`selectedPlugin`, parent && parent.plugin),
      )(state)
    }
    case actions.CHANGE_PROP: {
      const { instanceId, prop, value } = action.payload
      return set(state, `pluginInstances.${instanceId}.props.${prop.name}.value`, value)
    }
    case actions.SAVE_LAYOUT: {
      const { layout } = action.payload
github Zenika / marcel / backoffice / src / dashboard / reducer.js View on Github external
parent
            ? `pluginInstances.${parent.plugin}.props.${parent.prop}.value`
            : `dashboards.${selectedDashboard}.plugins`,
          instanceId,
        ),
        set(`selectedPlugin`, parent && parent.plugin),
      )(state)
    }
    case actions.CHANGE_PROP: {
      const { instanceId, prop, value } = action.payload
      return set(state, `pluginInstances.${instanceId}.props.${prop.name}.value`, value)
    }
    case actions.SAVE_LAYOUT: {
      const { layout } = action.payload
      const { selectedDashboard } = state
      return selectedDashboard ? update(state, `pluginInstances`, updatePlugins(layout)) : state
    }
    case actions.UPDATE_CONFIG: {
      const { selectedDashboard } = state
      const { property, value } = action.payload
      const parsedValue = parseFloat(value)
      return selectedDashboard
        ? set(
            state,
            `dashboards.${selectedDashboard}.${property}`,
            isNaN(parsedValue) ? value : parsedValue,
          )
        : state
    }
    case loadActions.LOAD_DASHBOARDS_SUCCESSED: {
      const { dashboards, user } = action.payload
      const plugins = _chain(dashboards)
github Zenika / marcel / backoffice / src / dashboard / selectors.js View on Github external
(dashboards, pluginInstances, selectedName) => {
    if (!selectedName || !dashboards[selectedName]) return null
    return flow(
      map('plugins', mapPluginInstancesToProps(pluginInstances)),
      update('plugins', keyBy('instanceId')),
    )(dashboards[selectedName])
  },
)