mirror of
https://github.com/nextcloud/documentation.git
synced 2026-01-02 17:59:36 +07:00
Add modern way of loading initial-state
Signed-off-by: Louis Chemineau <louis@chmn.me>
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user