summaryrefslogtreecommitdiff
path: root/src/Actions/entity.ts
diff options
context:
space:
mode:
authorAlexander NeonXP Kiryukhin <a.kiryukhin@mail.ru>2019-05-15 03:32:55 +0300
committerAlexander NeonXP Kiryukhin <a.kiryukhin@mail.ru>2019-05-15 03:32:55 +0300
commit491a92f71cf13bc8ef84db3b7fb24361013afb8e (patch)
treef4d45203428dcafa0b865e3604f5e9479d2c150b /src/Actions/entity.ts
parent0c9db775302d15483385f0621611583e3a2407cd (diff)
Many fixes
Diffstat (limited to 'src/Actions/entity.ts')
-rw-r--r--src/Actions/entity.ts79
1 files changed, 30 insertions, 49 deletions
diff --git a/src/Actions/entity.ts b/src/Actions/entity.ts
index 632b505..f2161fc 100644
--- a/src/Actions/entity.ts
+++ b/src/Actions/entity.ts
@@ -9,55 +9,40 @@ import { decodePortal } from '../Api/entityDecoder';
const entity = {
'update': (region: Region, width: number, refresh: boolean) => async (dispatch, getStore) => {
const store = getStore()
- let tiles = getTilesToLoad(region, width)
- if (!refresh) {
- const loadedAlready = Object.keys(store.entities.portals)
- tiles = tiles.filter(t => loadedAlready.indexOf(t) == -1)
- }
- const display = store.entities.display
- dispatch(entity.loadTiles(tiles, display))
+ const queue = store.entities.loadQueue
+ const loadedAlready = refresh ?
+ [
+ ...Object.keys(store.entities.portals),
+ ...queue,
+ ] : []
+ const tiles = getTilesToLoad(region, width).filter(t => loadedAlready.indexOf(t) == -1)
+ dispatch(entity.setLoadQueue([...queue, ...tiles]))
+ setImmediate(() => dispatch(entity.loadRutine()))
},
- 'loadTiles': (tiles: string[], display: any) => async (dispatch, getStore) => {
+ 'loadRutine': () => async (dispatch, getStore) => {
const store = getStore()
+ const queue = store.entities.loadQueue
+ console.log('1', queue.length)
+ const chunk = queue.splice(0, 25)
+ console.log('2', chunk.length, queue.length)
const { v, csrf } = store.auth
const params = { v, csrf }
- dispatch(entity.entitiesLoad(tiles.length))
- setImmediate(() => loadTiles(tiles, params)
- .then((loadedData: LoadedResult) => dispatch(entity.receiveTiles(loadedData, display))))
- },
- 'receiveTiles': (loadedData: LoadedResult, display: any) => async (dispatch) => {
- dispatch(entity.portalsSet(loadedData.portals))
- dispatch(entity.linksSet(loadedData.links))
- dispatch(entity.fieldsSet(loadedData.fields))
- Object.keys(loadedData.portalsByTile).forEach(tile => {
- loadedData.portalsByTile[tile].forEach(p => {
- if (display.portals.indexOf(p) == -1) {
- display.portals.push(p)
+ loadTiles(chunk, params)
+ .then(({ result, failed }) => {
+ const queue = store.entities.loadQueue
+ dispatch(entity.portalsSet(result.portals))
+ dispatch(entity.linksSet(result.links))
+ dispatch(entity.fieldsSet(result.fields))
+ let newQueue = queue
+ if (failed.length > 0) {
+ newQueue = [...queue, ...failed]
}
- })
- })
- Object.keys(loadedData.linksByTile).forEach(tile => {
- loadedData.linksByTile[tile].forEach(p => {
- if (display.links.indexOf(p) == -1) {
- display.links.push(p)
- }
- })
- })
- Object.keys(loadedData.fieldsByTile).forEach(tile => {
- loadedData.fieldsByTile[tile].forEach(p => {
- if (display.fields.indexOf(p) == -1) {
- display.fields.push(p)
+ dispatch(entity.setLoadQueue([...newQueue]))
+ if (newQueue.length > 0) {
+ setImmediate(() => dispatch(entity.loadRutine()))
}
})
- })
- dispatch(entity.entitiesDisplay(display))
- if (loadedData.failedTiles.length > 0) {
- setImmediate(() => {
- dispatch(entity.loadTiles(loadedData.failedTiles, display))
- })
- } else {
- dispatch(entity.entitiesLoad(0))
- }
+
},
'getPortalDetails': (guid: string) => async (dispatch, getStore) => {
const store = getStore()
@@ -69,13 +54,9 @@ const entity = {
dispatch(entity.portalSet(guid, portal))
})
},
- 'entitiesDisplay': (display: any) => ({
- type: 'entitiesDisplay',
- display
- }),
- 'entitiesLoad': (loading: number) => ({
- type: 'entitiesLoad',
- loading
+ 'setLoadQueue': (queue: string[][]) => ({
+ type: 'setLoad',
+ queue
}),
'portalsSet': (portals: { [guid: string]: Portal }) => ({
type: 'portalsSet',