// OLTA.JS
/**
* initializes and sets up communication with olta dashboard
* @example
* // add Olta globally
*
*
* @example
* // initialize
* const olta = Olta()
*/
function Olta() {
// overridable handlers
let onUpdateHandler = (update) => {
console.log("olta: UPDATE", update);
};
let onErrorHandler = (error) => {
console.error("olta: ERROR", error);
};
const state = { projectState: {} };
window.addEventListener("message", (e) => {
const { state: newState, type } = e.data ?? {};
if (type !== "state") {
return;
}
state.projectState = newState?.projectState ?? {};
// initiate update handler/ callback
onUpdateHandler(state);
});
/**
* Get all documents from a given collection
* @param {string} collectionId
* @returns {Array