How to use dot-prop-immutable - 10 common examples

To help you get started, we’ve selected a few dot-prop-immutable 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 ealgis / ealgis / frontend / src / redux / modules / databrowser.tsx View on Github external
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}`
github spaceuptech / automate-redux / index.js View on Github external
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]);
github eden-js / cli / lib / bundles / user / helpers / acl.js View on Github external
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
github spaceuptech / automate-redux / index.js View on Github external
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
github ealgis / ealgis / frontend / src / redux / modules / snackbars.tsx View on Github external
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
    }
}
github webiny / webiny-js / packages / webiny-app-page-builder / src / editor / actions / actions.js View on Github external
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 });
    }
});
github webiny / webiny-js / packages / app-page-builder / src / editor / actions / actions.js View on Github external
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 });
    }
});
github webiny / webiny-js / packages / app-page-builder / src / editor / plugins / elementSettings / advanced / AdvancedSettings.js View on Github external
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()
github webiny / webiny-js / packages / webiny-app-cms / src / editor / plugins / elementSettings / advanced / AdvancedSettings.js View on Github external
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()
github webiny / webiny-js / packages / app-page-builder / src / editor / plugins / elementSettings / components / PMSettings.js View on Github external
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
            });
        };
    });

dot-prop-immutable

Immutable version of dot-prop with some extensions

MIT
Latest version published 3 years ago

Package Health Score

57 / 100
Full package analysis