How to use the @shopgate/pwa-core.event.addCallback function in @shopgate/pwa-core

To help you get started, we’ve selected a few @shopgate/pwa-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shopgate / pwa / libraries / common / subscriptions / app.js View on Github external
// Suppress errors globally
    pipelineManager.addSuppressedErrors([
      errorCodes.EACCESS,
      errorCodes.ENOTFOUND,
      errorCodes.EVALIDATION,
    ]);

    // Map the error events into the Observable streams.
    errorEmitter.addListener(SOURCE_APP, error => dispatch(appError(error)));
    errorEmitter.addListener(SOURCE_PIPELINE, error => dispatch(pipelineError(error)));

    /** @returns {*} */
    const viewVisibility = () => events.emit(UI_VISIBILITY_CHANGE);

    event.addCallback('routeDidChange', viewVisibility);

    event.addCallback(APP_EVENT_VIEW_DID_DISAPPEAR, () => {
      dispatch(pwaDidDisappear());
      viewVisibility();
    });

    event.addCallback(APP_EVENT_VIEW_DID_APPEAR, () => {
      dispatch(pwaDidAppear());
      clearUpInAppBrowser(isAndroid(getState()));
    });
  });
github shopgate / pwa / libraries / common / subscriptions / app.js View on Github external
pipelineManager.addSuppressedErrors([
      errorCodes.EACCESS,
      errorCodes.ENOTFOUND,
      errorCodes.EVALIDATION,
    ]);

    // Map the error events into the Observable streams.
    errorEmitter.addListener(SOURCE_APP, error => dispatch(appError(error)));
    errorEmitter.addListener(SOURCE_PIPELINE, error => dispatch(pipelineError(error)));

    /** @returns {*} */
    const viewVisibility = () => events.emit(UI_VISIBILITY_CHANGE);

    event.addCallback('routeDidChange', viewVisibility);

    event.addCallback(APP_EVENT_VIEW_DID_DISAPPEAR, () => {
      dispatch(pwaDidDisappear());
      viewVisibility();
    });

    event.addCallback(APP_EVENT_VIEW_DID_APPEAR, () => {
      dispatch(pwaDidAppear());
      clearUpInAppBrowser(isAndroid(getState()));
    });
  });
github shopgate / pwa / libraries / common / subscriptions / app.js View on Github external
closeInAppBrowser(isAndroid(getState()));
    });

    event.addCallback('connectivityDidChange', (data) => {
      dispatch(receiveClientConnectivity(data));
    });

    /**
     * The following events are sometimes sent by the app, but don't need to be handled right now.
     * To avoid console warnings from the event system, empty handlers are registered here.
     */
    event.addCallback(APP_EVENT_VIEW_WILL_DISAPPEAR, () => {
      // Stop all playing video
      embeddedMedia.stop();
    });
    event.addCallback('pageInsetsChanged', () => {});

    /*
     * Onload must be send AFTER app did start.
     * Interjections events (like openPushMessage) would not work if this command is sent
     * before registering to interjections.
     */
    onload();
  });
github shopgate / pwa / libraries / common / subscriptions / app.js View on Github external
pathname: data.redirectTo,
        }));
      }

      closeInAppBrowser(isAndroid(getState()));
    });

    event.addCallback('connectivityDidChange', (data) => {
      dispatch(receiveClientConnectivity(data));
    });

    /**
     * The following events are sometimes sent by the app, but don't need to be handled right now.
     * To avoid console warnings from the event system, empty handlers are registered here.
     */
    event.addCallback(APP_EVENT_VIEW_WILL_DISAPPEAR, () => {
      // Stop all playing video
      embeddedMedia.stop();
    });
    event.addCallback('pageInsetsChanged', () => {});

    /*
     * Onload must be send AFTER app did start.
     * Interjections events (like openPushMessage) would not work if this command is sent
     * before registering to interjections.
     */
    onload();
  });
github shopgate / pwa / libraries / common / subscriptions / app.js View on Github external
// Register for custom events
    registerEvents([
      EVENT_KEYBOARD_WILL_CHANGE,
      'showPreviousTab',
      'closeInAppBrowser',
      // TODO The iOS apps don't emit the event to the webviews without registration till Lib 15.2.
      // This needs to be removed, when IOS-1886 is done and the the iOS apps are updated.
      'httpResponse',
      'connectivityDidChange',
    ]);

    // Add event callbacks
    event.addCallback('pageContext', pageContext);
    // Handle native/legacy navigation bar
    event.addCallback(APP_EVENT_VIEW_WILL_APPEAR, prepareLegacyNavigation);
    event.addCallback('showPreviousTab', showPreviousTab);
    /**
     * This event is triggered form the desktop shop in the inAppBrowser.
     * We have to close the inAppBrowser and redirect the user to the given url.
     */
    event.addCallback('closeInAppBrowser', (data = {}) => {
      if (data.redirectTo) {
        dispatch(historyPush({
          pathname: data.redirectTo,
        }));
      }

      closeInAppBrowser(isAndroid(getState()));
    });

    event.addCallback('connectivityDidChange', (data) => {
      dispatch(receiveClientConnectivity(data));
github shopgate / pwa / libraries / common / subscriptions / app.js View on Github external
subscribe(appDidStart$, ({ dispatch, getState }) => {
    // Register for custom events
    registerEvents([
      EVENT_KEYBOARD_WILL_CHANGE,
      'showPreviousTab',
      'closeInAppBrowser',
      // TODO The iOS apps don't emit the event to the webviews without registration till Lib 15.2.
      // This needs to be removed, when IOS-1886 is done and the the iOS apps are updated.
      'httpResponse',
      'connectivityDidChange',
    ]);

    // Add event callbacks
    event.addCallback('pageContext', pageContext);
    // Handle native/legacy navigation bar
    event.addCallback(APP_EVENT_VIEW_WILL_APPEAR, prepareLegacyNavigation);
    event.addCallback('showPreviousTab', showPreviousTab);
    /**
     * This event is triggered form the desktop shop in the inAppBrowser.
     * We have to close the inAppBrowser and redirect the user to the given url.
     */
    event.addCallback('closeInAppBrowser', (data = {}) => {
      if (data.redirectTo) {
        dispatch(historyPush({
          pathname: data.redirectTo,
        }));
      }

      closeInAppBrowser(isAndroid(getState()));
    });
github shopgate / pwa / libraries / common / subscriptions / app.js View on Github external
event.addCallback('showPreviousTab', showPreviousTab);
    /**
     * This event is triggered form the desktop shop in the inAppBrowser.
     * We have to close the inAppBrowser and redirect the user to the given url.
     */
    event.addCallback('closeInAppBrowser', (data = {}) => {
      if (data.redirectTo) {
        dispatch(historyPush({
          pathname: data.redirectTo,
        }));
      }

      closeInAppBrowser(isAndroid(getState()));
    });

    event.addCallback('connectivityDidChange', (data) => {
      dispatch(receiveClientConnectivity(data));
    });

    /**
     * The following events are sometimes sent by the app, but don't need to be handled right now.
     * To avoid console warnings from the event system, empty handlers are registered here.
     */
    event.addCallback(APP_EVENT_VIEW_WILL_DISAPPEAR, () => {
      // Stop all playing video
      embeddedMedia.stop();
    });
    event.addCallback('pageInsetsChanged', () => {});

    /*
     * Onload must be send AFTER app did start.
     * Interjections events (like openPushMessage) would not work if this command is sent
github shopgate / pwa / libraries / common / subscriptions / app.js View on Github external
subscribe(appDidStart$, ({ dispatch, getState }) => {
    // Register for custom events
    registerEvents([
      EVENT_KEYBOARD_WILL_CHANGE,
      'showPreviousTab',
      'closeInAppBrowser',
      // TODO The iOS apps don't emit the event to the webviews without registration till Lib 15.2.
      // This needs to be removed, when IOS-1886 is done and the the iOS apps are updated.
      'httpResponse',
      'connectivityDidChange',
    ]);

    // Add event callbacks
    event.addCallback('pageContext', pageContext);
    // Handle native/legacy navigation bar
    event.addCallback(APP_EVENT_VIEW_WILL_APPEAR, prepareLegacyNavigation);
    event.addCallback('showPreviousTab', showPreviousTab);
    /**
     * This event is triggered form the desktop shop in the inAppBrowser.
     * We have to close the inAppBrowser and redirect the user to the given url.
     */
    event.addCallback('closeInAppBrowser', (data = {}) => {
      if (data.redirectTo) {
        dispatch(historyPush({
          pathname: data.redirectTo,
        }));
      }

      closeInAppBrowser(isAndroid(getState()));
    });

    event.addCallback('connectivityDidChange', (data) => {
github shopgate / pwa / libraries / common / actions / app / registerLinkEvents.js View on Github external
registerEvents([
      'openPushNotification',
      'openDeepLink',
      'openUniversalLink',
    ]);

    event.addCallback('openPushNotification', payload => (
      dispatch(handlePushNotification(payload))
    ));

    event.addCallback('openDeepLink', payload => (
      dispatch(handleDeepLink(payload))
    ));

    event.addCallback('openUniversalLink', payload => (
      dispatch(handleUniversalLink(payload))
    ));

    dispatch(didRegisterLinkEvents());
  };
}
github shopgate / pwa / libraries / common / actions / app / registerLinkEvents.js View on Github external
return (dispatch) => {
    dispatch(willRegisterLinkEvents());

    registerEvents([
      'openPushNotification',
      'openDeepLink',
      'openUniversalLink',
    ]);

    event.addCallback('openPushNotification', payload => (
      dispatch(handlePushNotification(payload))
    ));

    event.addCallback('openDeepLink', payload => (
      dispatch(handleDeepLink(payload))
    ));

    event.addCallback('openUniversalLink', payload => (
      dispatch(handleUniversalLink(payload))
    ));

    dispatch(didRegisterLinkEvents());
  };
}