chore: Refactor widget (#5621)

This commit is contained in:
David Kubeš 2022-10-14 05:43:11 +02:00 committed by GitHub
parent e310230f62
commit a6960dc2d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 31 additions and 55 deletions

View file

@ -3,13 +3,6 @@ import { WOOT_PREFIX } from './constants';
export const isEmptyObject = obj =>
Object.keys(obj).length === 0 && obj.constructor === Object;
export const arrayToHashById = array =>
array.reduce((map, obj) => {
const newMap = map;
newMap[obj.id] = obj;
return newMap;
}, {});
export const sendMessage = msg => {
window.parent.postMessage(
`chatwoot-widget:${JSON.stringify({ ...msg })}`,
@ -22,9 +15,7 @@ export const IFrameHelper = {
sendMessage,
isAValidEvent: e => {
const isDataAString = typeof e.data === 'string';
const isAValidWootEvent =
isDataAString && e.data.indexOf(WOOT_PREFIX) === 0;
return isAValidWootEvent;
return isDataAString && e.data.indexOf(WOOT_PREFIX) === 0;
},
getMessage: e => JSON.parse(e.data.replace(WOOT_PREFIX, '')),
};