summaryrefslogtreecommitdiff
path: root/src/Store
diff options
context:
space:
mode:
Diffstat (limited to 'src/Store')
-rw-r--r--src/Store/store.ts50
1 files changed, 42 insertions, 8 deletions
diff --git a/src/Store/store.ts b/src/Store/store.ts
index b8f4169..581f14b 100644
--- a/src/Store/store.ts
+++ b/src/Store/store.ts
@@ -19,13 +19,12 @@ const reducers = {
'portalsSet': (store: any, action: { portals: Portal }) => {
const portals = store.portals
Object.keys(action.portals).forEach(guid => {
- const portal: Portal = portals[guid]
- const newPortal: Portal = action.portals[guid]
- if (!portal) {
- portals[guid] = newPortal
- return
+ if (portals[guid]) {
+ portals[guid] = { ...portals[guid], fraction: action.portals[guid].fraction, level: action.portals[guid].level }
+ } else {
+ portals[guid] = action.portals[guid]
}
- portals[guid] = extend(portal, newPortal)
+
})
return { ...store, portals }
},
@@ -35,8 +34,43 @@ const reducers = {
({ ...store, fields: { ...store.fields, ...action.fields } }),
'setLoad': (store: any, action: { queue: string[][] }) =>
({ ...store, loadQueue: [...action.queue] }),
-
- }, { portals: {}, fields: {}, links: {}, loadQueue: [] })
+ 'linksGC': (store: any, action: { links: { [tile: string]: string[] } }) => {
+ let linksCache = store.linksCache
+ let links = store.links
+ Object.keys(action.links).forEach(tileId => {
+ const oldLinks = linksCache[tileId]
+ if (oldLinks != undefined) {
+ oldLinks.forEach((guid: string) => {
+ delete links[guid]
+ })
+ }
+ linksCache[tileId] = action.links[tileId]
+ })
+ return ({ ...store, links: { ...links }, linksCache })
+ },
+ 'fieldsGC': (store: any, action: { fields: { [tile: string]: string[] } }) => {
+ let fieldsCache = store.fieldsCache
+ let fields = store.fields
+ Object.keys(action.fields).forEach(tileId => {
+ const oldFields = fieldsCache[tileId]
+ if (oldFields != undefined) {
+ oldFields.forEach((guid: string) => {
+ delete fields[guid]
+ })
+ }
+ fieldsCache[tileId] = action.fields[tileId]
+ })
+ return ({ ...store, fields: { ...fields }, fieldsCache })
+ },
+ }, { portals: {}, fields: {}, links: {}, loadQueue: [], linksCache: {}, fieldsCache: {} }),
+ 'settings': createReducer({
+ 'setLevelFrom': (store: any, action: { level: number }) => ({
+ ...store, filterLevel: [action.level, store.filterLevel[1]]
+ }),
+ 'setLevelTo': (store: any, action: { level: number }) => ({
+ ...store, filterLevel: [store.filterLevel[0], action.level]
+ })
+ }, { filterLevel: [0, 8] })
}
function extend(obj: any, src: any) {