Skip to content

Commit 75e9d87

Browse files
committed
ts-webpack done
1 parent 9ab3ee4 commit 75e9d87

File tree

10 files changed

+146
-2
lines changed

10 files changed

+146
-2
lines changed

xhr-and-dom-append/ts-webpack/.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ module.exports = {
1717
],
1818
rules: {
1919
"@typescript-eslint/no-explicit-any": "off", // any は許可でまずやってみよ
20+
"no-debugger": "warn",
2021
},
2122
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../plain-js/kaizen-web-api

xhr-and-dom-append/ts-webpack/package-lock.json

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

xhr-and-dom-append/ts-webpack/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@types/mocha": "^7.0.2",
2626
"@typescript-eslint/eslint-plugin": "^3.10.1",
2727
"@typescript-eslint/parser": "^3.10.1",
28+
"axios": "^0.20.0",
2829
"babel-loader": "^8.1.0",
2930
"chai": "^4.2.0",
3031
"core-js": "^3.6.5",
@@ -43,5 +44,6 @@
4344
"webpack-cli": "^3.3.12",
4445
"webpack-dev-server": "^3.11.0",
4546
"webpack-merge": "^5.1.4"
46-
}
47+
},
48+
"dependencies": {}
4749
}
+20-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
1-
console.log("hellox");
1+
import { loadPlaces } from "./placesProvider";
2+
import { render } from "./view";
3+
import { sendViewLog } from "./logger";
4+
5+
// main scope logic
6+
const run = async (): Promise<void> => {
7+
try {
8+
console.log("kaizen.js run");
9+
10+
const ps = await loadPlaces();
11+
render(ps);
12+
sendViewLog(ps.length);
13+
14+
console.log("kaizen.js done");
15+
} catch (e) {
16+
console.error(e);
17+
}
18+
};
19+
20+
run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const sendViewLog = (placesCount: number): void => {
2+
console.log(`sendLog: ${placesCount} items displayed`);
3+
// 実際の計測ログ送信 code は省略。code image は以下:
4+
// kzs("trackCustomEvent", { action:"places-ui-displayed", items: placesCount });
5+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import axios from "axios";
2+
3+
export interface ApiRes {
4+
success: boolean;
5+
error?: string;
6+
places?: Places;
7+
}
8+
9+
export type Places = Place[];
10+
11+
interface Place {
12+
id: string;
13+
name: string;
14+
country: string;
15+
image: string;
16+
googleMap: string;
17+
}
18+
19+
const urls = {
20+
hit:
21+
"https://storage.googleapis.com/kaizen-cse-public/cse-examples/xhr-and-dom-append/plain-js/kaizen-web-api/places.json?20200910",
22+
// API response 0 件パターン
23+
zeroHit:
24+
"https://storage.googleapis.com/kaizen-cse-public/cse-examples/xhr-and-dom-append/plain-js/kaizen-web-api/places-zero.json?20200910",
25+
// API error response パターン
26+
error:
27+
"https://storage.googleapis.com/kaizen-cse-public/cse-examples/xhr-and-dom-append/plain-js/kaizen-web-api/places-fail.json?20200910",
28+
};
29+
30+
// Kaizen Web API からコンテンツを取得
31+
export const loadPlaces = async (): Promise<Places> => {
32+
const r: ApiRes = (await axios.get(urls.hit)).data; // or urls.zeroHit or urls.error
33+
console.log("xhr done", r);
34+
35+
if (!r.success) throw new Error(r.error);
36+
return r.places || [];
37+
};
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
.s01 form .inner-form.kz {
2+
margin-top: 20px;
3+
}
4+
5+
.kz-item {
6+
width: 100%;
7+
clear: both;
8+
color: white;
9+
}
10+
11+
.kz-name a {
12+
font-size: 1.2em;
13+
font-weight: bold;
14+
color: white;
15+
}
16+
17+
.kz-image {
18+
float: left;
19+
}
20+
21+
.kz-image img {
22+
width: 100px;
23+
}
24+
25+
.kz-desc {
26+
float: left;
27+
margin-left: 10px;
28+
font-size: 0.9em;
29+
}
30+
31+
@media screen and (max-width: 767px) {
32+
.s01 form .inner-form.kz {
33+
padding-bottom: 10px;
34+
}
35+
36+
.kz-item {
37+
margin-bottom: 10px;
38+
}
39+
40+
.kz-image img {
41+
width: 60px;
42+
}
43+
}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Places } from "./placesProvider";
2+
import "./view.css";
3+
4+
export const render = (places: Places): boolean => {
5+
if (places.length === 0) return false;
6+
7+
const $w = $(`<div class="inner-form kz"></div>`).insertAfter(".inner-form");
8+
9+
$.each(places, function (i, p) {
10+
$(`
11+
<div class="kz-item">
12+
<div class="kz-image">
13+
<img src=${p.image} />
14+
</div>
15+
<div class="kz-desc">
16+
<div class="kz-name">
17+
<a href="${p.googleMap}" target="_blank">${p.name}</a>
18+
</div>
19+
<div class="kz-country">${p.country}</div>
20+
</div>
21+
</div>
22+
`).appendTo($w);
23+
});
24+
25+
return true;
26+
};

xhr-and-dom-append/ts-webpack/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"compilerOptions": {
55
// project options
66
"module": "es6",
7+
"moduleResolution": "node",
78
"removeComments": false,
89
"sourceMap": true,
910
"target": "es6",

0 commit comments

Comments
 (0)