All Downloads are FREE. Search and download functionalities are using the official Maven repository.

typescript-fetch.ApiEntitiesReducer.mustache Maven / Gradle / Ivy

The newest version!
import {ApiEntitiesRecord} from "./ApiEntitiesRecord.js";
import {ReducerBuilder} from "redux-ts-simple";
import {normalizedEntities} from "./runtimeSagasAndRecords.js";

export const ApiEntitiesReducer = new ReducerBuilder(ApiEntitiesRecord())
    .on(normalizedEntities, (state, action): ApiEntitiesRecord => {
        const {entities} = action.payload;
        return state.withMutations(mutableState => {
            for (const entityKey in entities) {
                const entityMap = entities[entityKey];
                const currentEntityMap = mutableState.get(entityKey as any);
                if (currentEntityMap) {
                    let mergedEntityMap = currentEntityMap.mergeDeep(entityMap);
                    if (!mergedEntityMap.equals(currentEntityMap)) {
                        mutableState.set(entityKey as any, mergedEntityMap);
                    }
                }
            }
        });
    })
    .build();




© 2015 - 2024 Weber Informatics LLC | Privacy Policy