Button
handler() {
Wix.Dashboard.bla(
() => console.log('got callback'));
}
My Awesome App
post
messages
handler
post
messages
handler
let addListener = () => {
if (!isListening) {
$window.addEventListener('message', handlePostMessage);
isListening = true;
}
};
handlePostMessage(event) {
msg = JSON.parse(event.data);
if (shouldHandleMessage(msg)) {
messageHandlers[msg.type](msg.data, generateResponseFunction(event, msg));
}
}
function shouldHandleMessage(msg) {
if (msg && msg.intent === INTENTS.TPA_MESSAGE) {
return doesHandlerExist(msg.type) && isCorrectCompId(msg.compId);
}
return false;
}
.config(dashboardSdkProvider => {
dashboardSdkProvider.registerHandler('pmName', 'service', 'method', 'namespace');
dashboardSdkProvider.registerHandler('openMediaDialogRaw', 'sdkMediaGallery', 'openAndReturnRawData', 'Dashboard');
dashboardSdkProvider.registerHandler('echo', 'dashboardSdkEchoHandler');
dashboardSdkProvider.registerHandler('scrollTo', 'dashboardSdkScrollToHandler');
});
this.registerHandler = function (eventName, handlerServiceName, methodName, namespace) {
handlers[eventName] = function () {
if (instanceInjector.has(handlerServiceName)) {
var handlerFunc = instanceInjector.get(handlerServiceName);
if (methodName) {
handlerFunc = handlerFunc[methodName].bind(handlerFunc);
}
handlerFunc.apply(this, arguments);
}
};
};
private getContacts(query) {
return this.Wix.Contacts.search({search: query})
.then((response) => response.items);
}
Wix apps often have special requirements
No need for fancy specs
Can be for a very specific use case
Faster dev time to production
Wix.SuperApps.Features.isSupported(experimentName, callback);
(App as a service demo)
Thanks