Skip to content

Commit 4099544

Browse files
author
Hugues Signamarcheix
committed
update front & morning push
1 parent 99f4964 commit 4099544

File tree

8 files changed

+55
-16
lines changed

8 files changed

+55
-16
lines changed

2019-12-05/hugues.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Je suis présent

front/index.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010
<h1>Javascript workers in action</h1>
1111
<div class="container">
1212
<button id="refresh" class="btn">Génerer de nouvelles données</button>
13-
<div id="text-placeholder" class="is-empty"></div>
13+
<div id="text-placeholder" class="is-empty">
14+
<div>Nom : <span class="name"></span></div>
15+
<div>Age : <span class="age"></span></div>
16+
<div>Ville : <span class="city"></span></div>
17+
<div>Biographie : <span class="bio"></span></div>
18+
</div>
1419
<div class="loader">
1520
<div class="lds-ring"><div></div><div></div><div></div><div></div></div>
1621
</div>
1722
</div>
1823
<script src="javascript/script.js"></script>
1924
</body>
20-
</html>
25+
</html>

front/javascript/dist/worker-bundled.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
22
const axios = require('axios');
33

4+
const apiMaxId = 54;
5+
46
onmessage = (e) => {
5-
axios.get('https://baconipsum.com/api/?type=meat-and-filler')
6-
.then(response => (postMessage(response.data)))
7+
console.log('here')
8+
let id = (Math.floor(Math.random() * Math.floor(apiMaxId))) + 1
9+
postMessage('a')
10+
//axios.get('http://js-worker.local/' + id)
11+
// .then(response => (postMessage(response.data)))
712
}
813
},{"axios":2}],2:[function(require,module,exports){
914
module.exports = require('./lib/axios');

front/javascript/script.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,40 @@
1+
const fields = ['name', 'age', 'city', 'bio']
2+
13
document.addEventListener("DOMContentLoaded",() => {
24
if (window.Worker) {
35
let worker = new Worker('./javascript/dist/worker-bundled.js');
46

57
let btnRefresh = document.getElementById("refresh");
6-
let textPlaceholder = document.getElementById("text-placeholder");
78
let container = document.getElementsByClassName("container")[0];
89

910
btnRefresh.addEventListener("click",() => {
10-
textPlaceholder.innerHTML = '';
11-
textPlaceholder.classList.add('is-empty');
11+
cleanEntries();
1212
container.classList.add('is-loading');
1313
worker.postMessage('test');
1414
});
1515

1616
worker.onmessage = function(e) {
17-
let textContent = e.data;
18-
textPlaceholder.innerHTML = textContent;
17+
let jsonTest = {
18+
'id': '50',
19+
'name': 'Kamren Carter',
20+
'age': '74',
21+
'city': '525 Hand Loop',
22+
'bio': 'Eos voluptatibus neque et qui aperiam. Fuga et nostrum expedita commodi maxime porro.'
23+
}
24+
//let textContent = e.data;
25+
//textPlaceholder.innerHTML = textContent;
26+
for(let fieldName of fields) {
27+
document.getElementsByClassName(fieldName)[0].innerHTML = jsonTest[fieldName];
28+
}
1929
container.classList.remove('is-loading');
20-
textPlaceholder.classList.remove('is-empty');
2130
}
2231
}
2332
})
33+
34+
function cleanEntries() {
35+
for(let fieldName of fields) {
36+
document.getElementsByClassName(fieldName)[0].innerHTML = '';
37+
}
38+
}
39+
40+

front/javascript/worker.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
const axios = require('axios');
22

3+
const apiMaxId = 54;
4+
35
onmessage = (e) => {
4-
axios.get('https://baconipsum.com/api/?type=meat-and-filler')
5-
.then(response => (postMessage(response.data)))
6+
console.log('here')
7+
let id = (Math.floor(Math.random() * Math.floor(apiMaxId))) + 1
8+
postMessage('a')
9+
//axios.get('http://js-worker.local/' + id)
10+
// .then(response => (postMessage(response.data)))
611
}

front/scss/pages/index.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ h1 {
1717
margin-bottom: 20px;
1818
}
1919
#text-placeholder {
20-
&.is-empty { padding: 100px 20px; }
2120
background-color: lightgray;
2221
padding: 20px 20px;
2322
line-height: 20px;
2423
letter-spacing: 1px;
2524
font-family: sans-serif;
2625
border-radius: 5px;
2726
width: 96%;
27+
> div {
28+
font-weight: bold;
29+
span { font-weight: normal; }
30+
}
2831
}
2932
.loader {
3033
position: absolute;

front/style.css

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

front/style.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)