Skip to content

Commit

Permalink
Fixed all fixable eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
saikumarrs committed Aug 22, 2021
1 parent 8afaa1a commit 0737a02
Showing 1 changed file with 38 additions and 36 deletions.
74 changes: 38 additions & 36 deletions analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
transformToServerNames,
checkReservedKeywords,
getReferrer,
getReferringDomain
getReferringDomain,
} from "./utils/utils";
import {
CONFIG_URL,
Expand All @@ -45,7 +45,7 @@ import { configToIntNames } from "./config_to_integration_names.js";

const queryDefaults = {
trait: "ajs_trait_",
prop: "ajs_prop_"
prop: "ajs_prop_",
};

// https://unpkg.com/[email protected]/dist/browser.js
Expand Down Expand Up @@ -93,7 +93,7 @@ class Analytics {
this.readyCallback = () => {};
this.executeReadyCallback = undefined;
this.methodToCallbackMapping = {
syncPixel: "syncPixelCallback"
syncPixel: "syncPixelCallback",
};
this.loaded = false;
this.loadIntegration = true;
Expand Down Expand Up @@ -170,7 +170,6 @@ class Analytics {
});
}


/**
* Process the response from control plane and
* call initialize for integrations
Expand Down Expand Up @@ -200,7 +199,7 @@ class Analytics {
if (destination.enabled) {
this.clientIntegrations.push({
name: destination.destinationDefinition.name,
config: destination.config
config: destination.config,
});
}
}, this);
Expand All @@ -212,7 +211,7 @@ class Analytics {
this.loadOnlyIntegrations,
this.clientIntegrations
);

logger.debug("this.clientIntegrations: ", this.clientIntegrations);
// Load all the client integrations dynamically
this.clientIntegrations.forEach((intg) => {
Expand Down Expand Up @@ -276,7 +275,8 @@ class Analytics {
// remove from the list which don't have support yet in SDK
object.clientIntegrations = object.clientIntegrations.filter((intg) => {
return (
object.dynamicallyLoadedIntegrations[configToIntNames[intg.name]] != undefined
object.dynamicallyLoadedIntegrations[configToIntNames[intg.name]] !=
undefined
);
});
const intgArray = object.clientIntegrations;
Expand Down Expand Up @@ -356,7 +356,7 @@ class Analytics {
logger.debug("==registering ready callback===");
object.on("ready", object.executeReadyCallback);

object.clientIntegrationObjects.forEach(intg => {
object.clientIntegrationObjects.forEach((intg) => {
logger.debug("===looping over each successful integration====");
if (!intg.isReady || intg.isReady()) {
logger.debug("===letting know I am ready=====", intg.name);
Expand All @@ -366,7 +366,7 @@ class Analytics {

if (object.toBeProcessedByIntegrationArray.length > 0) {
// send the queued events to the fetched integration
object.toBeProcessedByIntegrationArray.forEach(event => {
object.toBeProcessedByIntegrationArray.forEach((event) => {
const methodName = event[0];
event.shift();

Expand All @@ -380,10 +380,11 @@ class Analytics {

// get intersection between config plane native enabled destinations
// (which were able to successfully load on the page) vs user supplied integrations
const succesfulLoadedIntersectClientSuppliedIntegrations = findAllEnabledDestinations(
clientSuppliedIntegrations,
object.clientIntegrationObjects
);
const succesfulLoadedIntersectClientSuppliedIntegrations =
findAllEnabledDestinations(
clientSuppliedIntegrations,
object.clientIntegrationObjects
);

// send to all integrations now from the 'toBeProcessedByIntegrationArray' replay queue
for (
Expand Down Expand Up @@ -421,13 +422,13 @@ class Analytics {
}

pause(time) {
return new Promise(resolve => {
return new Promise((resolve) => {
setTimeout(resolve, time);
});
}

isInitialized(instance, time = 0) {
return new Promise(resolve => {
return new Promise((resolve) => {
if (instance.isLoaded()) {
logger.debug("===integration loaded successfully====", instance.name);
this.successfullyLoadedIntegration.push(instance);
Expand Down Expand Up @@ -684,7 +685,7 @@ class Analytics {
rudderElement.message.context.traits
) {
this.userTraits = {
...rudderElement.message.context.traits
...rudderElement.message.context.traits,
};
this.storage.setUserTraits(this.userTraits);
}
Expand Down Expand Up @@ -747,7 +748,7 @@ class Analytics {
// rudderElement.message.context.page = getDefaultPageProperties();

rudderElement.message.context.traits = {
...this.userTraits
...this.userTraits,
};

logger.debug("anonymousId: ", this.anonymousId);
Expand All @@ -762,7 +763,7 @@ class Analytics {
}
if (this.groupTraits) {
rudderElement.message.traits = {
...this.groupTraits
...this.groupTraits,
};
}
}
Expand All @@ -783,14 +784,15 @@ class Analytics {

// get intersection between config plane native enabled destinations
// (which were able to successfully load on the page) vs user supplied integrations
const succesfulLoadedIntersectClientSuppliedIntegrations = findAllEnabledDestinations(
clientSuppliedIntegrations,
this.clientIntegrationObjects
);
const succesfulLoadedIntersectClientSuppliedIntegrations =
findAllEnabledDestinations(
clientSuppliedIntegrations,
this.clientIntegrationObjects
);

// try to first send to all integrations, if list populated from BE
try {
succesfulLoadedIntersectClientSuppliedIntegrations.forEach(obj => {
succesfulLoadedIntersectClientSuppliedIntegrations.forEach((obj) => {
if (!obj.isFailed || !obj.isFailed()) {
if (obj[type]) {
obj[type](rudderElement);
Expand Down Expand Up @@ -863,18 +865,18 @@ class Analytics {
const toplevelElements = [
"integrations",
"anonymousId",
"originalTimestamp"
"originalTimestamp",
];
for (const key in options) {
if (toplevelElements.includes(key)) {
rudderElement.message[key] = options[key];
} else if (key !== "context") {
rudderElement.message.context = merge(rudderElement.message.context, {
[key]: options[key]
[key]: options[key],
});
} else if (typeof options[key] === "object" && options[key] != null) {
rudderElement.message.context = merge(rudderElement.message.context, {
...options[key]
...options[key],
});
} else {
logger.error(
Expand Down Expand Up @@ -996,7 +998,7 @@ class Analytics {
if (!this.isValidWriteKey(writeKey) || !this.isValidServerUrl(serverUrl)) {
handleError({
message:
"[Analytics] load:: Unable to load due to wrong writeKey or serverUrl"
"[Analytics] load:: Unable to load due to wrong writeKey or serverUrl",
});
throw Error("failed to initialize");
}
Expand Down Expand Up @@ -1024,7 +1026,7 @@ class Analytics {
if (options && options.clientSuppliedCallbacks) {
// convert to rudder recognised method names
const tranformedCallbackMapping = {};
Object.keys(this.methodToCallbackMapping).forEach(methodName => {
Object.keys(this.methodToCallbackMapping).forEach((methodName) => {
if (this.methodToCallbackMapping.hasOwnProperty(methodName)) {
if (
options.clientSuppliedCallbacks[
Expand Down Expand Up @@ -1097,7 +1099,7 @@ class Analytics {
const res = options.getSourceConfig();

if (res instanceof Promise) {
res.then(res => this.processResponse(200, res)).catch(errorHandler);
res.then((res) => this.processResponse(200, res)).catch(errorHandler);
} else {
this.processResponse(200, res);
}
Expand Down Expand Up @@ -1125,7 +1127,7 @@ class Analytics {
}

initializeCallbacks() {
Object.keys(this.methodToCallbackMapping).forEach(methodName => {
Object.keys(this.methodToCallbackMapping).forEach((methodName) => {
if (this.methodToCallbackMapping.hasOwnProperty(methodName)) {
this.on(methodName, () => {});
}
Expand All @@ -1134,7 +1136,7 @@ class Analytics {

registerCallbacks(calledFromLoad) {
if (!calledFromLoad) {
Object.keys(this.methodToCallbackMapping).forEach(methodName => {
Object.keys(this.methodToCallbackMapping).forEach((methodName) => {
if (this.methodToCallbackMapping.hasOwnProperty(methodName)) {
if (window.rudderanalytics) {
if (
Expand Down Expand Up @@ -1163,7 +1165,7 @@ class Analytics {
});
}

Object.keys(this.clientSuppliedCallbacks).forEach(methodName => {
Object.keys(this.clientSuppliedCallbacks).forEach((methodName) => {
if (this.clientSuppliedCallbacks.hasOwnProperty(methodName)) {
logger.debug(
"registerCallbacks",
Expand All @@ -1189,7 +1191,7 @@ class Analytics {
parseQueryString(query) {
function getTraitsFromQueryObject(qObj) {
const traits = {};
Object.keys(qObj).forEach(key => {
Object.keys(qObj).forEach((key) => {
if (key.substr(0, queryDefaults.trait.length) == queryDefaults.trait) {
traits[key.substr(queryDefaults.trait.length)] = qObj[key];
}
Expand All @@ -1200,7 +1202,7 @@ class Analytics {

function getEventPropertiesFromQueryObject(qObj) {
const props = {};
Object.keys(qObj).forEach(key => {
Object.keys(qObj).forEach((key) => {
if (key.substr(0, queryDefaults.prop.length) == queryDefaults.prop) {
props[key.substr(queryDefaults.prop.length)] = qObj[key];
}
Expand Down Expand Up @@ -1268,7 +1270,7 @@ Emitter(instance);

window.addEventListener(
"error",
e => {
(e) => {
handleError(e, instance);
},
true
Expand Down Expand Up @@ -1344,5 +1346,5 @@ export {
group,
getUserTraits,
getAnonymousId,
setAnonymousId
setAnonymousId,
};

0 comments on commit 0737a02

Please sign in to comment.