Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "dot-prop-immutable in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'dot-prop-immutable' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

export default function reducer(state = initialState, action: IAction) {
    switch (action.type) {
        case START:
            state = dotProp.set(state, "active", true)
            state = dotProp.set(state, "tables", [])
            state = dotProp.set(state, "columns", [])
            state = dotProp.set(state, "selectedColumns", action.selectedColumns)
            state = dotProp.set(state, "component", action.component)
            state = dotProp.set(state, "config", { ...state.config, ...action.config })
            return dotProp.set(state, "message", action.message)
        case FINISH:
            return dotProp.set(state, "active", false)
        case ADD_TABLES:
            return dotProp.set(state, "tables", action.tables)
        case ADD_COLUMNS:
            return dotProp.set(state, "columns", action.columns)
        case SELECT_COLUMN:
            if (action.column) {
                const columns: Array = xorBy(
                    state.selectedColumns,
                    [action.column],
                    // @ts-ignore
                    (column: IColumn) => `${column.schema_name}.${column.id}`
return (state = initialState, action) => {
    switch (action.type) {
      case "SET":
        return dotProp.set(state, action.path, action.value);

      case "RESET":
        // Reset the entire state
        if (action.path === undefined) {
          return initialState;
        }

        // Reset specific state
        return dotProp.set(
          state,
          action.path,
          dotProp.get(initialState, action.path)
        );

      case "PUSH":
        return dotProp.merge(state, action.path, [action.value]);
async validate (User, tests) {
    // Get list
    let obj  = {};
    let list = await this.list(User);

    // Check is array
    if (Array.isArray(list)) {
      // Set list
      for (let item of list) {
        // Set value
        obj = dotProp.set(obj, item, true);
      }
    }

    // Set array if not
    if (!Array.isArray(tests)) tests = [tests];

    // Find failed test
    return !(tests.filter((test) => {
      // Check if true/false
      if (test.toString() === 'true' && !User) return true;
      if (test.toString() === 'false' && User) return true;

      // Check list
      if (list === true) return false;

      // Loop props
return (state = initialState, action) => {
    switch (action.type) {
      case "SET":
        return dotProp.set(state, action.path, action.value);

      case "RESET":
        // Reset the entire state
        if (action.path === undefined) {
          return initialState;
        }

        // Reset specific state
        return dotProp.set(
          state,
          action.path,
          dotProp.get(initialState, action.path)
        );

      case "PUSH":
        return dotProp.merge(state, action.path, [action.value]);

      case "INCREMENT":
        var initialValue = Number(dotProp.get(state, action.path, 0))
        var newValue = initialValue + action.value
        return dotProp.set(state, action.path, newValue)

      case "DECREMENT":
          var initialValue = Number(dotProp.get(state, action.path, 0))
          var newValue = initialValue - action.value
state.messages.push(action.message!)
            return dotProp.set(state, `messages`, state.messages)
        case START:
            if (state.open === false && state.messages.length > 0) {
                // Pop the first message off the front of the queue
                const message = state.messages.shift()
                state = dotProp.set(state, `messages`, state.messages)
                state = dotProp.set(state, `active`, message)
                state = dotProp.set(state, `open`, true)
            }
            return state
        case NEXT:
            if (state.messages.length > 0) {
                // Pop the first message off the front of the queue
                const message = state.messages.shift()
                state = dotProp.set(state, `messages`, state.messages)
                state = dotProp.set(state, `active`, message)
                return dotProp.set(state, `open`, true)
            } else {
                state = dotProp.set(state, `active`, { message: "" })
                return dotProp.set(state, `open`, false)
            }
        default:
            return state
    }
}
next(action);

    store.dispatch(deactivateElement());
    const state = store.getState();

    let { element } = action.payload;
    let parent = getParentElementWithChildren(state, element.id);

    // Remove child from parent
    // $FlowFixMe
    if (!parent) {
        return;
    }

    const index = parent.elements.findIndex(el => el.id === element.id);
    parent = dotProp.delete(parent, "elements." + index);
    store.dispatch(updateElement({ element: parent }));

    // Execute `onChildDeleted` if defined
    const plugin = getPlugin(parent.type);
    if (!plugin) {
        return;
    }

    if (typeof plugin.onChildDeleted === "function") {
        plugin.onChildDeleted({ element: parent, child: element });
    }
});
next(action);

    store.dispatch(deactivateElement());
    const state = store.getState();

    let { element } = action.payload;
    let parent = getParentElementWithChildren(state, element.id);

    // Remove child from parent
    // $FlowFixMe
    if (!parent) {
        return;
    }

    const index = parent.elements.findIndex(el => el.id === element.id);
    parent = dotProp.delete(parent, "elements." + index);
    store.dispatch(updateElement({ element: parent }));

    // Execute `onChildDeleted` if defined
    const plugin = getPlugin(parent.type);
    if (!plugin) {
        return;
    }

    if (typeof plugin.onChildDeleted === "function") {
        plugin.onChildDeleted({ element: parent, child: element });
    }
});
onSubmit: ({ element, updateElement, closeDialog }) => (formData: Object) => {
            // Get element settings plugins
            const plugins = getPlugins("pb-page-element-advanced-settings").filter(
                pl => pl.elementType === element.type
            );
            formData = plugins.reduce((formData, pl) => {
                if (pl.onSave) {
                    return pl.onSave(formData);
                }
                return formData;
            }, formData);

            updateElement({
                element: merge(element, "data", formData)
            });
            closeDialog();
        },
        onClose: ({ closeDialog }) => () => closeDialog()
onSubmit: ({ element, updateElement, closeDialog }) => (formData: Object) => {
            // Get element settings plugins
            const plugins = getPlugins("cms-element-advanced-settings").filter(
                pl => pl.element === element.type
            );
            formData = plugins.reduce((formData, pl) => {
                if (pl.onSave) {
                    return pl.onSave(formData);
                }
                return formData;
            }, formData);

            updateElement({
                element: merge(element, "data", formData)
            });
            closeDialog();
        },
        onClose: ({ closeDialog }) => () => closeDialog()
return (name: string, newValue: mixed, history = false) => {
            const propName = `${valueKey}.${name}`;

            if (name !== "advanced") {
                newValue = parseInt(newValue) || 0;
            }

            let newElement = set(element, propName, newValue);

            // Update all values in advanced settings
            if (propName.endsWith(".all")) {
                const prefix = propName.includes("desktop") ? "desktop" : "mobile";
                newElement = merge(newElement, `${valueKey}.${prefix}`, {
                    top: newValue,
                    right: newValue,
                    bottom: newValue,
                    left: newValue
                });
            }

            updateElement({
                element: newElement,
                history,
                merge: true
            });
        };
    });

Is your System Free of Underlying Vulnerabilities?
Find Out Now