A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/markerikson/project-minimek/commit/1d5ccae612a97c59782df42680cc3282df31c861 below:

Add a "entity feature reducer" and a generic "entity update reducer" · markerikson/project-minimek@1d5ccae · GitHub

File tree Expand file treeCollapse file tree 4 files changed

+48

-0

lines changed

Filter options

Expand file treeCollapse file tree 4 files changed

+48

-0

lines changed Original file line number Diff line number Diff line change

@@ -8,6 +8,8 @@ import unitInfoReducer from "features/unitInfo/unitInfoReducer";

8 8

import pilotsReducer from "features/pilots/pilotsReducer";

9 9

import mechsReducer from "features/mechs/mechsReducer";

10 10 11 +

import entityCrudReducer from "features/entities/entityReducer";

12 + 11 13 12 14

const combinedReducer = combineReducers({

13 15

entities : entitiesReducer,

@@ -20,6 +22,7 @@ const combinedReducer = combineReducers({

20 22 21 23

const rootReducer = reduceReducers(

22 24

combinedReducer,

25 +

entityCrudReducer,

23 26

);

24 27 25 28

export default rootReducer;

Original file line number Diff line number Diff line change

@@ -0,0 +1,12 @@

1 +

import {ENTITY_UPDATE} from "./entityConstants";

2 + 3 +

export function updateEntity(itemType, itemID, newItemAttributes) {

4 +

return {

5 +

type : ENTITY_UPDATE,

6 +

payload : {

7 +

itemType,

8 +

itemID,

9 +

newItemAttributes,

10 +

},

11 +

};

12 +

}

Original file line number Diff line number Diff line change

@@ -0,0 +1 @@

1 +

export const ENTITY_UPDATE = "ENTITY_UPDATE";

Original file line number Diff line number Diff line change

@@ -0,0 +1,32 @@

1 +

import {ENTITY_UPDATE} from "./entityConstants";

2 + 3 +

import {createConditionalSliceReducer} from "common/utils/reducerUtils";

4 + 5 +

import schema from "app/schema";

6 + 7 +

export function updateEntity(state, payload) {

8 +

const {itemType, itemID, newItemAttributes} = payload;

9 + 10 +

const session = schema.from(state);

11 +

const ModelClass = session[itemType];

12 + 13 +

let newState = state;

14 + 15 +

if(ModelClass.hasId(itemID)) {

16 +

const modelInstance = ModelClass.withId(itemID);

17 + 18 +

modelInstance.update(newItemAttributes);

19 + 20 +

newState = session.reduce();

21 +

}

22 + 23 +

return newState;

24 +

}

25 + 26 +

const entityHandlers = {

27 +

[ENTITY_UPDATE] : updateEntity,

28 +

};

29 + 30 +

const entityCrudFeatureReducer = createConditionalSliceReducer("entities", entityHandlers);

31 + 32 +

export default entityCrudFeatureReducer;

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4