Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lam-station-visualization
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
data-analysis-and-ai
lam-station-visualization
Commits
19943a28
Commit
19943a28
authored
6 years ago
by
Janne Alatalo
Browse files
Options
Downloads
Patches
Plain Diff
Fix race condition in data fetching
parent
f970b5e9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#3976
passed
6 years ago
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/App.js
+2
-9
2 additions, 9 deletions
src/App.js
src/utils/api-client.js
+7
-3
7 additions, 3 deletions
src/utils/api-client.js
with
9 additions
and
12 deletions
src/App.js
+
2
−
9
View file @
19943a28
...
@@ -3,16 +3,10 @@ import { Map } from 'immutable';
...
@@ -3,16 +3,10 @@ import { Map } from 'immutable';
import
PointMap
from
'
./PointMap.js
'
;
import
PointMap
from
'
./PointMap.js
'
;
import
'
./App.css
'
;
import
'
./App.css
'
;
import
{
get_lam_points
,
connect_lam_ws
,
get_lam_station_data
}
from
'
./utils/api-client.js
'
;
import
{
get_lam_points
,
connect_lam_ws
}
from
'
./utils/api-client.js
'
;
class
App
extends
Component
{
class
App
extends
Component
{
set_lam_points
(
lam_points
)
{
this
.
setState
((
prevState
)
=>
{
return
{
...
prevState
,
lam_points
};
});
}
update_state
(
fn
)
{
update_state
(
fn
)
{
this
.
setState
((
prevState
)
=>
{
this
.
setState
((
prevState
)
=>
{
return
fn
(
prevState
);
return
fn
(
prevState
);
...
@@ -33,8 +27,7 @@ class App extends Component {
...
@@ -33,8 +27,7 @@ class App extends Component {
let
width
=
window
.
innerWidth
;
let
width
=
window
.
innerWidth
;
let
height
=
window
.
innerHeight
;
let
height
=
window
.
innerHeight
;
this
.
state
=
{
lam_points
:
Map
(),
mapSize
:
{
width
,
height
}
};
this
.
state
=
{
lam_points
:
Map
(),
mapSize
:
{
width
,
height
}
};
get_lam_points
(
"
http://tie.digitraffic.fi
"
,
this
.
set_lam_points
.
bind
(
this
));
get_lam_points
(
"
http://tie.digitraffic.fi
"
,
this
.
update_state
.
bind
(
this
));
get_lam_station_data
(
"
http://tie.digitraffic.fi
"
,
this
.
update_state
.
bind
(
this
));
connect_lam_ws
(
"
ws://tie.digitraffic.fi
"
,
this
.
update_state
.
bind
(
this
));
connect_lam_ws
(
"
ws://tie.digitraffic.fi
"
,
this
.
update_state
.
bind
(
this
));
this
.
handleResize
=
this
.
handleResize
.
bind
(
this
);
this
.
handleResize
=
this
.
handleResize
.
bind
(
this
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/utils/api-client.js
+
7
−
3
View file @
19943a28
...
@@ -3,7 +3,7 @@ import { Map } from 'immutable';
...
@@ -3,7 +3,7 @@ import { Map } from 'immutable';
import
LamStation
from
'
./lam-station.js
'
;
import
LamStation
from
'
./lam-station.js
'
;
export
function
get_lam_points
(
api_url
,
set_state
)
{
export
function
get_lam_points
(
api_url
,
set_state
)
{
fetch
(
`
${
api_url
}
/api/v1/metadata/tms-stations`
)
return
fetch
(
`
${
api_url
}
/api/v1/metadata/tms-stations`
)
.
then
((
res
)
=>
res
.
json
())
.
then
((
res
)
=>
res
.
json
())
.
then
((
json
)
=>
{
.
then
((
json
)
=>
{
let
stations
=
Map
();
let
stations
=
Map
();
...
@@ -13,13 +13,17 @@ export function get_lam_points(api_url, set_state) {
...
@@ -13,13 +13,17 @@ export function get_lam_points(api_url, set_state) {
let
station
=
new
LamStation
(
id
,
coordinates
,
0
,
0
);
let
station
=
new
LamStation
(
id
,
coordinates
,
0
,
0
);
stations
=
stations
.
set
(
id
,
station
);
stations
=
stations
.
set
(
id
,
station
);
}
}
set_state
(
stations
);
set_state
((
prevState
)
=>
{
const
lam_points
=
stations
;
return
{
...
prevState
,
lam_points
};
});
})
})
.
then
(()
=>
get_lam_station_data
(
api_url
,
set_state
))
.
catch
(
e
=>
(
console
.
error
(
e
)));
.
catch
(
e
=>
(
console
.
error
(
e
)));
}
}
export
function
get_lam_station_data
(
api_url
,
set_state
)
{
export
function
get_lam_station_data
(
api_url
,
set_state
)
{
fetch
(
`
${
api_url
}
/api/v1/data/tms-data`
)
return
fetch
(
`
${
api_url
}
/api/v1/data/tms-data`
)
.
then
((
res
)
=>
res
.
json
())
.
then
((
res
)
=>
res
.
json
())
.
then
((
json
)
=>
{
.
then
((
json
)
=>
{
set_state
((
prevState
)
=>
{
set_state
((
prevState
)
=>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment