Skip to content

Commit 8c2e395

Browse files
authored
fix(vue-gtag.d.ts): typescript types & deduping utils.js (#315)
closes #314
1 parent 8788664 commit 8c2e395

File tree

5 files changed

+15
-38
lines changed

5 files changed

+15
-38
lines changed

src/add-routes-tracker.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { nextTick } from "vue";
2-
import { isFn } from "@/utils";
2+
import { isFunction } from "@vue/shared";
33
import { getRouter } from "@/router";
44
import { getOptions } from "@/options";
55
import addConfiguration from "@/add-configuration";
@@ -33,13 +33,13 @@ export default () => {
3333
return;
3434
}
3535

36-
if (isFn(onBeforeTrack)) {
36+
if (isFunction(onBeforeTrack)) {
3737
onBeforeTrack(to, from);
3838
}
3939

4040
track(to, from);
4141

42-
if (isFn(onAfterTrack)) {
42+
if (isFunction(onAfterTrack)) {
4343
onAfterTrack(to, from);
4444
}
4545
});

src/track.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { isFunction } from "@vue/shared";
12
import { getOptions } from "@/options";
2-
import { validateScreenviewShape, isFn } from "@/utils";
3+
import { validateScreenviewShape } from "@/utils";
34
import * as api from "@/api";
45

56
export default (to = {}, from = {}) => {
@@ -16,7 +17,7 @@ export default (to = {}, from = {}) => {
1617

1718
let template = to;
1819

19-
if (isFn(proxy)) {
20+
if (isFunction(proxy)) {
2021
template = proxy(to, from);
2122
} else if (useScreenview) {
2223
template = validateScreenviewShape({

src/utils.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { isPlainObject } from "@vue/shared";
2+
13
export const load = (url, options = {}) => {
24
return new Promise((resolve, reject) => {
35
if (typeof document === "undefined") {
@@ -27,25 +29,19 @@ export const load = (url, options = {}) => {
2729
});
2830
};
2931

30-
export const isFn = (fn) => typeof fn === "function";
31-
32-
export const isObject = (item) => {
33-
return item && typeof item === "object" && !Array.isArray(item);
34-
};
35-
3632
export const mergeDeep = (target, ...sources) => {
3733
if (!sources.length) {
3834
return target;
3935
}
4036

4137
const source = sources.shift();
4238

43-
if (!isObject(target) || !isObject(source)) {
39+
if (!isPlainObject(target) || !isPlainObject(source)) {
4440
return;
4541
}
4642

4743
for (const key in source) {
48-
if (isObject(source[key])) {
44+
if (isPlainObject(source[key])) {
4945
if (!target[key]) {
5046
Object.assign(target, { [key]: {} });
5147
}

test/utils.spec.js

-20
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,3 @@ describe("warn", () => {
7474
expect(console.warn).toHaveBeenCalledWith("[vue-gtag] foo");
7575
});
7676
});
77-
78-
describe("isFn", () => {
79-
it("should return true", () => {
80-
expect(util.isFn(() => {})).toBe(true);
81-
});
82-
83-
it("should return false", () => {
84-
expect(util.isFn("hello")).toBe(false);
85-
});
86-
});
87-
88-
describe("isObject", () => {
89-
it("should return true", () => {
90-
expect(util.isObject({})).toBe(true);
91-
});
92-
it("should return false", () => {
93-
expect(util.isObject([])).toBe(false);
94-
expect(util.isObject("aa")).toBe(false);
95-
});
96-
});

vue-gtag.d.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
declare module "vue-gtag" {
2-
import VueRouter from "vue-router";
3-
import _Vue from "vue";
2+
import type { App } from "vue";
3+
import type { Router } from "vue-router";
44

55
/**
66
* Types copied from @types/gtag.js.
@@ -12,7 +12,7 @@ declare module "vue-gtag" {
1212
(command: 'config', targetId: string, config?: ControlParams | EventParams | CustomParams): void;
1313
(command: 'set', config: CustomParams): void;
1414
(command: 'js', config: Date): void;
15-
(command: 'event', eventName: EventNames | string, eventParams?: ControlParams | EventParams | CustomParams): void;
15+
(command: 'event', eventName: EventNames | string, eventParams?: ControlParams | EventParams | CustomParams): void;
1616
}
1717

1818
interface CustomParams {
@@ -284,9 +284,9 @@ declare module "vue-gtag" {
284284

285285
export class VueGtagPlugin {
286286
static install(
287-
Vue: typeof _Vue,
287+
app: App,
288288
options: PluginOptions,
289-
router?: VueRouter
289+
router?: Router
290290
): void;
291291
}
292292

0 commit comments

Comments
 (0)