-
-
Notifications
You must be signed in to change notification settings - Fork 32
Events
Shobhit Sharma edited this page Nov 16, 2017
·
8 revisions
Embedo has internal event listeners implemented which emits following events:
These events are always attached to each embedo .load()
call instance. They act much like promises for .done()
to resolve or .fail()
to catch error in chain.
embedo.load(arguments).done(Function).fail(Function)
Event | Dispatchers | Description |
---|---|---|
watch |
on/once/off | When an element has loaded or size is modified in DOM |
refresh |
on/once/off | When a refresh event is finished |
destroy |
on/once/off | When embedo instance(s) are destroyed |
error |
on/once/off | Exception handler happened during embed |
During lifecycle of Embedo class, all instances are stored in memory to emit and handle necessary events for DOM. They listen to any change in size, destroyed or refreshed instances all in once place. The arguments contain meta data which helps to log and understand which particular instance has been called.
embedo.on('watch', (request) => {});
embedo.on('refresh', (request, data) => {});
embedo.on('destroy', (request) => {});
embedo.on('error', (error) => {});
window.postMessage Listener (⚠️ deprecated v1.7.3 onwards)
To listen to each time embedo renders an element successfully, it can also be decoded through:
window.addEventListener('message', function (event) {
if (event.data && Array.isArray(event.data) && event.data.indexOf('embedo') !== -1) {
var decoded_message = JSON.parse(event.data[2]);
console.log(event, decoded_message);
}
}, false);