From 0586b57bfa108449f5f94fa3b6ccabe964f131bb Mon Sep 17 00:00:00 2001 From: Louis <6653109+artonge@users.noreply.github.com> Date: Wed, 7 Jul 2021 16:38:17 +0200 Subject: [PATCH] Add modern way of loading initial-state Signed-off-by: Louis Chemineau --- developer_manual/basics/front-end/js.rst | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/developer_manual/basics/front-end/js.rst b/developer_manual/basics/front-end/js.rst index 794be5b04..60432698a 100644 --- a/developer_manual/basics/front-end/js.rst +++ b/developer_manual/basics/front-end/js.rst @@ -109,7 +109,7 @@ and a JS part (that fetches and parses the state). Providing the initial state with PHP ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Providing state in PHP is done via the ``\OCP\IInitialStateService``. This service +Providing state in PHP is done via the ``OCP\AppFramework\Services\IInitialState``. This service has two methods you can use to provide the initial state. * ``provideInitialState(string $appName, string $key, $data)``: @@ -130,6 +130,19 @@ Obtaining the initial state in JavaScript To obtain the initial state in your JavaScript you have to only call one function +- Vue way with `@nextcloud/initial-state `_: + +.. code-block:: js + + import { loadState } from '@nextcloud/initial-state' + + const val = loadState('myapp', 'user_preference') + + // Provide a fallback value to return when the state is not found + const valWithFallback = loadState('myapp', 'user_preference', 'no_preference') + +- Legacy way: + .. code-block:: js const state = OCP.InitialState.loadState('MyApp', 'MyState');