From 620cbe4a90b8d83de961bab357b7b8e820660c5f Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Thu, 9 Apr 2020 17:46:45 +0200 Subject: [PATCH] Document the new js network events Signed-off-by: Christoph Wurst --- developer_manual/app/javascript-apis.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/developer_manual/app/javascript-apis.rst b/developer_manual/app/javascript-apis.rst index f6a86eb31..9fd67497f 100644 --- a/developer_manual/app/javascript-apis.rst +++ b/developer_manual/app/javascript-apis.rst @@ -107,6 +107,27 @@ This package provides helpers to generate URLs, e.g. to access assets and REST A This package provides lots of nextcloud components allowing you to quickly build UIs. Documentation: https://nextcloud-vue-components.netlify.com/ +Events +------ + +Network state changes +^^^^^^^^^^^^^^^^^^^^^ + +Your app can react to lost network connectivity, e.g. to gracefully handle this state where no server interaction is possible. Since the communication with the server mostly requires a valid CSRF token, you might not want to send any request before the token was udpated. Nextcloud can notify you when this has happened. Use the ``@nextcloud/event-bus`` to listen for the ``networkOnline`` and ``networkOffline`` events: + +.. code-block:: js + + import { subscribe } from '@nextcloud/event-bus' + + subscribe('networkOffline', () => console.info("we're offline")) + subscribe('networkOnline', (event) => { + if (event.successful) { + console.info("we're back online, the token was updated") + } else { + console.info("we're back online, but the token might not be up to date") + } + }) + Global variables ----------------