chore: Refactor widget (#5621)
This commit is contained in:
parent
e310230f62
commit
a6960dc2d3
18 changed files with 31 additions and 55 deletions
|
@ -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, '')),
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue