Add modern way of loading initial-state

Signed-off-by: Louis Chemineau <louis@chmn.me>
This commit is contained in:
Louis
2021-07-07 16:38:17 +02:00
committed by Louis Chemineau
parent f08ed6c02e
commit 0586b57bfa

View File

@@ -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 <https://github.com/nextcloud/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');