aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-16 02:48:20 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-16 02:48:20 +0800
commit2e61050a223a52b4b984034463887b0d579ce9b8 (patch)
tree506e3b914ac3be1c82e9f4496778832d86364896 /packages/instant
parent61f227e123218ba76a7fdf7fc2ee89171c2bf16c (diff)
downloaddexon-sol-tools-2e61050a223a52b4b984034463887b0d579ce9b8.tar
dexon-sol-tools-2e61050a223a52b4b984034463887b0d579ce9b8.tar.gz
dexon-sol-tools-2e61050a223a52b4b984034463887b0d579ce9b8.tar.bz2
dexon-sol-tools-2e61050a223a52b4b984034463887b0d579ce9b8.tar.lz
dexon-sol-tools-2e61050a223a52b4b984034463887b0d579ce9b8.tar.xz
dexon-sol-tools-2e61050a223a52b4b984034463887b0d579ce9b8.tar.zst
dexon-sol-tools-2e61050a223a52b4b984034463887b0d579ce9b8.zip
Use pure functions instead of class
Diffstat (limited to 'packages/instant')
-rw-r--r--packages/instant/src/util/analytics.ts51
1 files changed, 24 insertions, 27 deletions
diff --git a/packages/instant/src/util/analytics.ts b/packages/instant/src/util/analytics.ts
index 4de3e5eff..3e2a996cf 100644
--- a/packages/instant/src/util/analytics.ts
+++ b/packages/instant/src/util/analytics.ts
@@ -3,33 +3,30 @@ import { logUtils } from '@0x/utils';
import { HeapAnalytics, heapUtil } from './heap';
-export class Analytics {
- public static init(): Analytics {
- return new Analytics();
- }
- public track(eventName: string, eventProperties?: ObjectMap<string | number>): void {
- console.log('HEAP: tracking', eventName, eventProperties);
- this._evaluteHeapCall(heap => heap.track(eventName, eventProperties));
- }
- public addUserProperties(properties: ObjectMap<string | number>): void {
- console.log('HEAP: adding user properties', properties);
- this._evaluteHeapCall(heap => heap.addUserProperties(properties));
- }
- public addEventProperties(properties: ObjectMap<string | number>): void {
- this._evaluteHeapCall(heap => heap.addEventProperties(properties));
- }
- private _evaluteHeapCall(heapFunctionCall: (heap: HeapAnalytics) => void): void {
- const curHeap = heapUtil.getHeap();
- if (curHeap) {
- try {
- heapFunctionCall(curHeap);
- } catch (e) {
- // We never want analytics to crash our React component
- // TODO: error reporter here
- logUtils.log('Analytics error', e);
- }
+const evaluteHeapCall = (heapFunctionCall: (heap: HeapAnalytics) => void): void => {
+ const curHeap = heapUtil.getHeap();
+ if (curHeap) {
+ try {
+ heapFunctionCall(curHeap);
+ } catch (e) {
+ // We never want analytics to crash our React component
+ // TODO: error reporter here
+ logUtils.log('Analytics error', e);
}
}
-}
+};
-export const analytics = Analytics.init();
+export const analytics = {
+ addUserProperties: (properties: ObjectMap<string | number>): void => {
+ console.log('HEAP: adding user properties', properties);
+ evaluteHeapCall(heap => heap.addUserProperties(properties));
+ },
+ addEventProperties: (properties: ObjectMap<string | number>): void => {
+ console.log('HEAP: adding user properties', properties);
+ evaluteHeapCall(heap => heap.addEventProperties(properties));
+ },
+ track: (eventName: string, eventProperties?: ObjectMap<string | number>): void => {
+ console.log('HEAP: tracking', eventName, eventProperties);
+ evaluteHeapCall(heap => heap.track(eventName, eventProperties));
+ },
+};