diff options
author | Alexander NeonXP Kiryukhin <a.kiryukhin@mail.ru> | 2019-06-10 03:15:51 +0300 |
---|---|---|
committer | Alexander NeonXP Kiryukhin <a.kiryukhin@mail.ru> | 2019-06-10 03:15:51 +0300 |
commit | 06645cdac4184f5c1cf50f2a4b94be3d72d634f0 (patch) | |
tree | 1eb62ec1d2275ae6feb90cfceedb7b93257005b0 /src/Store | |
parent | 4b01d81d3daed894bc93f77dbbbe5501a4552447 (diff) |
More improvements
Diffstat (limited to 'src/Store')
-rw-r--r-- | src/Store/store.ts | 50 |
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) { |