How to use the @shopgate/pwa-core/classes/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 / subscriptions / app.js View on Github external
registerEvents([
      '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',
    ]);

    // Add event callbacks
    event.addCallback('pageContext', pageContext);
    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) {
        new ParsedLink(data.redirectTo).open();
      }

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

    /**
     * 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('viewDidAppear', () => {});
    event.addCallback('viewDidDisappear', () => {});
    event.addCallback('pageInsetsChanged', () => {});
  });
}
github shopgate / pwa / libraries / engage / core / actions / grantPermissions.js View on Github external
}

    /**
     * Handler for the app event.
     */
    const handler = async () => {
      event.removeCallback(APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND, handler);
      [{ status }] = await getAppPermissions([permissionId]);
      resolve(status === STATUS_GRANTED);
    };

    /**
     * Register an event handler, so that we can perform the permissions check again,
     * when the user comes back from the settings.
     */
    event.addCallback(APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND, handler);

    // Open the settings (protected by a timeout, so that the modal closes before the app is left).
    setTimeout(() => {
      openAppSettings();
    }, 0);
  }
});
github shopgate / pwa / subscriptions / app.js View on Github external
subscribe(appDidStart$, ({ getState }) => {
    // Register for custom events
    registerEvents([
      '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',
    ]);

    // Add event callbacks
    event.addCallback('pageContext', pageContext);
    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) {
        new ParsedLink(data.redirectTo).open();
      }

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

    /**
     * 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.
github shopgate / pwa / actions / app / registerLinkEvents.js View on Github external
const registerLinkEvents = location => (dispatch) => {
  dispatch(willRegisterLinkEvents());

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

  event.addCallback('openLink', handler =>
    dispatch(openLink(handler.action, handler.options))
  );
  event.addCallback('openPushNotification', payload =>
    dispatch(handlePushNotification(payload))
  );
  event.addCallback('openDeepLink', payload =>
    dispatch(handleDeepLink(payload))
  );

  window.push = (payload) => dispatch(handlePushNotification(payload));
  window.deeplink = (payload) => dispatch(handleDeepLink(payload));


  dispatch(didRegisterLinkEvents());

  // ??

  dispatch(openLink('reactRouter', {
    url: location.pathname,
github shopgate / pwa / libraries / commerce / cart / subscriptions / index.js View on Github external
// Push (deeplink) with coupon concurrent to get cart on app start
    pipelineDependencies.set(pipelines.SHOPGATE_CART_ADD_COUPONS, [
      pipelines.SHOPGATE_CART_ADD_PRODUCTS,
      pipelines.SHOPGATE_CART_GET_CART,
    ]);
    pipelineDependencies.set(pipelines.SHOPGATE_CART_DELETE_COUPONS, [
      pipelines.SHOPGATE_CART_ADD_PRODUCTS,
      pipelines.SHOPGATE_CART_GET_CART,
    ]);

    /**
     * Reload the cart whenever the WebView becomes visible.
     * This is needed, for example, when the cart is modified from another inAppBrowser tab like a
     * web-checkout and the user closes the said tab before reaching the success page.
     */
    event.addCallback('viewWillAppear', () => {
      dispatch(fetchCart());
    });

    // Reset the productPendingCount on app start to avoid a wrong value in the cart badge.
    dispatch(setCartProductPendingCount(0));
  });
github shopgate / pwa / actions / app / registerLinkEvents.js View on Github external
const registerLinkEvents = location => (dispatch) => {
  dispatch(willRegisterLinkEvents());

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

  event.addCallback('openLink', handler =>
    dispatch(openLink(handler.action, handler.options))
  );
  event.addCallback('openPushNotification', payload =>
    dispatch(handlePushNotification(payload))
  );
  event.addCallback('openDeepLink', payload =>
    dispatch(handleDeepLink(payload))
  );

  window.push = (payload) => dispatch(handlePushNotification(payload));
  window.deeplink = (payload) => dispatch(handleDeepLink(payload));


  dispatch(didRegisterLinkEvents());

  // ??
github shopgate / pwa / subscriptions / app.js View on Github external
*/
    event.addCallback('closeInAppBrowser', (data = {}) => {
      if (data.redirectTo) {
        new ParsedLink(data.redirectTo).open();
      }

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

    /**
     * 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('viewDidAppear', () => {});
    event.addCallback('viewDidDisappear', () => {});
    event.addCallback('pageInsetsChanged', () => {});
  });
}
github shopgate / pwa / libraries / engage / core / providers / AppProvider.jsx View on Github external
constructor(props) {
    super(props);

    this.state = {
      isVisible: true,
    };

    event.addCallback(APP_EVENT_VIEW_WILL_APPEAR, this.setVisible);
    event.addCallback(APP_EVENT_VIEW_WILL_DISAPPEAR, this.setHidden);
  }
github shopgate / pwa / components / Router / helpers / link-events / index.js View on Github external
const attachLinkEvents = () => {
  registerEvents(['openPushNotification', 'openDeepLink']);
  event.addCallback('openPushNotification', handleOpenPushNotification);
  event.addCallback('openDeepLink', handleOpenDeepLink);
};
github shopgate / pwa / themes / theme-gmd / pages / Product / components / VariantSelects / index.jsx View on Github external
componentDidMount() {
    event.addCallback(EVENT_ADD_TO_CART_MISSING_VARIANT, this.handleMissingVariant);
  }