peryl 1.4.49 → 1.4.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/google-analytics.d.ts +13 -2
- package/dist/google-analytics.js +30 -4
- package/dist/google-analytics.js.map +1 -1
- package/dist/hash.d.ts +4 -4
- package/dist/hash.js +11 -11
- package/dist/hash.js.map +1 -1
- package/dist/hsml-app.d.ts +2 -1
- package/dist/hsml-app.js +3 -3
- package/dist/hsml-app.js.map +1 -1
- package/dist/umd/google-analytics.js +1 -1
- package/dist/umd/google-analytics.js.map +1 -1
- package/dist/umd/hash.js +1 -1
- package/dist/umd/hash.js.map +1 -1
- package/dist/umd/hsml-app.js +1 -1
- package/dist/umd/hsml-app.js.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +1 -1
- package/src/google-analytics.ts +36 -4
- package/src/hash.ts +10 -10
- package/src/hsml-app.ts +6 -4
package/package.json
CHANGED
package/src/google-analytics.ts
CHANGED
|
@@ -3,6 +3,28 @@ export class GA {
|
|
|
3
3
|
|
|
4
4
|
static ga: GA;
|
|
5
5
|
|
|
6
|
+
static init(trackingId: string, dimensions?: Object) {
|
|
7
|
+
GA.ga = new GA(trackingId, dimensions);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
static pageview(path: string, title?: string): void {
|
|
11
|
+
if (GA.ga) {
|
|
12
|
+
GA.ga.pageview(path, title);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static event(name: string, parameters?: { [k: string]: string }): void {
|
|
17
|
+
if (GA.ga) {
|
|
18
|
+
GA.ga.event(name, parameters);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static set(parameters: { [k: string]: string }): void {
|
|
23
|
+
if (GA.ga) {
|
|
24
|
+
GA.ga.set(parameters);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
6
28
|
private _trackingId: string;
|
|
7
29
|
|
|
8
30
|
constructor(trackingId: string, dimensions?: Object) {
|
|
@@ -10,15 +32,25 @@ export class GA {
|
|
|
10
32
|
this._load();
|
|
11
33
|
}
|
|
12
34
|
|
|
13
|
-
pageview(path: string): void {
|
|
35
|
+
pageview(path: string, title?: string): void {
|
|
36
|
+
if (this._trackingId) {
|
|
37
|
+
(self as any).gtag("config", this._trackingId,
|
|
38
|
+
{
|
|
39
|
+
page_path: path,
|
|
40
|
+
page_title: title
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
event(name: string, parameters?: { [k: string]: string }): void {
|
|
14
46
|
if (this._trackingId) {
|
|
15
|
-
(self as any).gtag("
|
|
47
|
+
(self as any).gtag("event", name, parameters);
|
|
16
48
|
}
|
|
17
49
|
}
|
|
18
50
|
|
|
19
|
-
|
|
51
|
+
set(parameters: { [k: string]: string }): void {
|
|
20
52
|
if (this._trackingId) {
|
|
21
|
-
(self as any).gtag("
|
|
53
|
+
(self as any).gtag("set", parameters);
|
|
22
54
|
}
|
|
23
55
|
}
|
|
24
56
|
|
package/src/hash.ts
CHANGED
|
@@ -6,17 +6,17 @@ export interface HashUrlData {
|
|
|
6
6
|
};
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export const
|
|
10
|
-
export const
|
|
9
|
+
export const hashJsonEncode = (data: any) => data ? encodeURIComponent(JSON.stringify(data)) : "";
|
|
10
|
+
export const hashJsonDecode = (str: string) => str ? JSON.parse(decodeURIComponent(str)) : undefined;
|
|
11
11
|
|
|
12
|
-
export const
|
|
12
|
+
export const hashUrlEncode = (data: HashUrlData): string => {
|
|
13
13
|
// console.log(data);
|
|
14
14
|
const d = typeof data === "string"
|
|
15
|
-
?
|
|
15
|
+
? hashUrlDecode(data)
|
|
16
16
|
: data as HashUrlData;
|
|
17
17
|
const dpath = d.path || [];
|
|
18
18
|
const dquery = d.query || {};
|
|
19
|
-
const path = dpath.join("/");
|
|
19
|
+
const path = dpath.map(p => encodeURIComponent(p)).join("/");
|
|
20
20
|
// const params = new URLSearchParams();
|
|
21
21
|
const query = Object.entries(dquery)
|
|
22
22
|
.reduce(
|
|
@@ -30,16 +30,16 @@ export const hashUrlEncoder = (data: HashUrlData): string => {
|
|
|
30
30
|
},
|
|
31
31
|
new URLSearchParams())
|
|
32
32
|
.toString();
|
|
33
|
-
const str = `${path}
|
|
33
|
+
const str = `${path}${query ? "?" : ""}${query}`;
|
|
34
34
|
// console.log(str);
|
|
35
35
|
return str;
|
|
36
36
|
};
|
|
37
|
-
export const
|
|
37
|
+
export const hashUrlDecode = (str: string): HashUrlData => {
|
|
38
38
|
// console.log(str);
|
|
39
39
|
const [pathStr, queryStr] = str.split("?");
|
|
40
40
|
// const pathStr = str.substring(0, str.indexOf("?"));
|
|
41
41
|
// const queryStr = str.substring(str.indexOf("?") + 1);
|
|
42
|
-
const path = pathStr.split("/");
|
|
42
|
+
const path = pathStr.split("/").map(p => decodeURIComponent(p));
|
|
43
43
|
const query = {} as any;
|
|
44
44
|
for (const e of new URLSearchParams(queryStr).entries()) {
|
|
45
45
|
const [k, v] = e;
|
|
@@ -121,11 +121,11 @@ export class Hash<T = string> {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
read(): T {
|
|
124
|
-
return this._decode(
|
|
124
|
+
return this._decode(location.hash.slice(1));
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
write(data: T): this {
|
|
128
|
-
location.hash = "#" +
|
|
128
|
+
location.hash = "#" + this._encode(data);
|
|
129
129
|
// location.hash = "#" + this._encode(data);
|
|
130
130
|
if (!this._emitWritten) {
|
|
131
131
|
this._writtenDataJson = JSON.stringify(data);
|
package/src/hsml-app.ts
CHANGED
|
@@ -19,7 +19,9 @@ export type HDispatch = (type: HAction["type"],
|
|
|
19
19
|
|
|
20
20
|
export type HUpdate = () => void;
|
|
21
21
|
|
|
22
|
-
export type
|
|
22
|
+
export type HRefs<STATE> = HApp<STATE>["refs"];
|
|
23
|
+
|
|
24
|
+
export type HDispatcher<STATE> = (this: HApp<any>, action: HAction, state: STATE, dispatch: HDispatch, refs: HRefs<STATE>) => Promise<void>;
|
|
23
25
|
|
|
24
26
|
// export type Class<T = object> = new (...args: any[]) => T;
|
|
25
27
|
|
|
@@ -74,7 +76,7 @@ export class HApp<STATE> implements HHandlerCtx {
|
|
|
74
76
|
this.state = state;
|
|
75
77
|
this.view = view;
|
|
76
78
|
this.dispatcher = dispatcher || (async (a) => log(msgAction, a.type, a.data));
|
|
77
|
-
this.dispatch(HAppAction._init).then(() => this.mount(e));
|
|
79
|
+
this.dispatch(HAppAction._init, this).then(() => this.mount(e));
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
dispatch: HDispatch = async (type: string, data?: any, event?: Event): Promise<void> => {
|
|
@@ -82,7 +84,7 @@ export class HApp<STATE> implements HHandlerCtx {
|
|
|
82
84
|
log(msgAction, { type, data, event });
|
|
83
85
|
const t0 = performance.now();
|
|
84
86
|
try {
|
|
85
|
-
await this.dispatcher({ type, data, event }, this.state, this.dispatch);
|
|
87
|
+
await this.dispatcher({ type, data, event }, this.state, this.dispatch, this.refs);
|
|
86
88
|
this.update();
|
|
87
89
|
} catch (e) {
|
|
88
90
|
err(msgDispatch, e);
|
|
@@ -91,7 +93,7 @@ export class HApp<STATE> implements HHandlerCtx {
|
|
|
91
93
|
log(msgDispatch, `${t1 - t0} ms`, this.state);
|
|
92
94
|
} else {
|
|
93
95
|
try {
|
|
94
|
-
await this.dispatcher({ type, data, event }, this.state, this.dispatch);
|
|
96
|
+
await this.dispatcher({ type, data, event }, this.state, this.dispatch, this.refs);
|
|
95
97
|
this.update();
|
|
96
98
|
} catch (e) {
|
|
97
99
|
err(msgDispatch, e);
|