Skip to content
Snippets Groups Projects
Commit 36159251 authored by Michele Alberti's avatar Michele Alberti
Browse files

[ivette] Rework doc for frama-c/states module.

parent e1553a45
No related branches found
No related tags found
No related merge requests found
...@@ -3,10 +3,9 @@ ...@@ -3,10 +3,9 @@
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
@packageDocumentation * Manage the current Frama-C project and projectified state values.
@module frama-c/states * @packageDocumentation
@decsription * @module frama-c/states
Manage the current Frama-C project and projectified state values.
*/ */
import React from 'react'; import React from 'react';
...@@ -59,7 +58,8 @@ Server.onShutdown(() => { ...@@ -59,7 +58,8 @@ Server.onShutdown(() => {
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
Current Project (Custom React Hook). * Current Project (Custom React Hook).
* @return The current project.
*/ */
export function useProject() { export function useProject() {
Dome.useUpdate(PROJECT); Dome.useUpdate(PROJECT);
...@@ -67,10 +67,12 @@ export function useProject() { ...@@ -67,10 +67,12 @@ export function useProject() {
} }
/** /**
Update Current Project. * Update Current Project.
Make all states switching to their projectified value. *
Emits `PROJECT`. * Make all states switching to their projectified value.
@param project - the project identifier *
* Emits `PROJECT`.
* @param project The project identifier.
*/ */
export async function setProject(project: string) { export async function setProject(project: string) {
if (Server.isRunning()) { if (Server.isRunning()) {
...@@ -101,12 +103,12 @@ export interface UseRequestOptions<A> { ...@@ -101,12 +103,12 @@ export interface UseRequestOptions<A> {
} }
/** /**
Cached GET request (Custom React Hook). * Cached GET request (Custom React Hook).
*
Sends the specified GET request and returns its result. * Sends the specified GET request and returns its result. The request is send
The request is send asynchronously and cached until any change. * asynchronously and cached until any change.
*
Null values in options mean that the last obtained value is kept. * Null values in options mean that the last obtained value is kept.
*/ */
export function useRequest<In, Out>( export function useRequest<In, Out>(
rq: Server.GetRequest<In, Out>, rq: Server.GetRequest<In, Out>,
...@@ -251,7 +253,7 @@ class SyncState<A> { ...@@ -251,7 +253,7 @@ class SyncState<A> {
Dome.emit(this.UPDATE); Dome.emit(this.UPDATE);
} catch (error) { } catch (error) {
PP.error( PP.error(
`Fail to set value of syncState '${this.handler.name}'.`, `Fail to set value of SyncState '${this.handler.name}'.`,
`${error.toString()}`, `${error.toString()}`,
); );
} }
...@@ -265,7 +267,7 @@ class SyncState<A> { ...@@ -265,7 +267,7 @@ class SyncState<A> {
Dome.emit(this.UPDATE); Dome.emit(this.UPDATE);
} catch (error) { } catch (error) {
PP.error( PP.error(
`Fail to update syncState '${this.handler.name}'.`, `Fail to update SyncState '${this.handler.name}'.`,
`${error.toString()}`, `${error.toString()}`,
); );
} }
...@@ -294,9 +296,7 @@ Server.onShutdown(() => syncStates.clear()); ...@@ -294,9 +296,7 @@ Server.onShutdown(() => syncStates.clear());
// --- Synchronized State Hooks // --- Synchronized State Hooks
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /** Synchronization with a (projectified) server state. */
Synchronization with a (projectified) server state.
*/
export function useSyncState<A>( export function useSyncState<A>(
st: State<A>, st: State<A>,
): [A | undefined, (value: A) => void] { ): [A | undefined, (value: A) => void] {
...@@ -306,9 +306,7 @@ export function useSyncState<A>( ...@@ -306,9 +306,7 @@ export function useSyncState<A>(
return [s.getValue(), s.setValue]; return [s.getValue(), s.setValue];
} }
/** /** Synchronization with a (projectified) server value. */
Synchronization with a (projectified) server value.
*/
export function useSyncValue<A>(va: Value<A>): A | undefined { export function useSyncValue<A>(va: Value<A>): A | undefined {
const s = getSyncState(va); const s = getSyncState(va);
Dome.useUpdate(s.update); Dome.useUpdate(s.update);
...@@ -413,9 +411,7 @@ Server.onShutdown(() => syncArrays.clear()); ...@@ -413,9 +411,7 @@ Server.onShutdown(() => syncArrays.clear());
// --- Synchronized Array Hooks // --- Synchronized Array Hooks
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /** Force a Synchronized Array to reload. */
Force a Synchronized Array to Reload.
*/
export function reloadArray<K, A>(arr: Array<K, A>) { export function reloadArray<K, A>(arr: Array<K, A>) {
getSyncArray(arr).reload(); getSyncArray(arr).reload();
} }
...@@ -423,11 +419,11 @@ export function reloadArray<K, A>(arr: Array<K, A>) { ...@@ -423,11 +419,11 @@ export function reloadArray<K, A>(arr: Array<K, A>) {
/** /**
Use Synchronized Array (Custom React Hook). Use Synchronized Array (Custom React Hook).
Unless specified, the hook makes the component re-rendering on every Unless specified, the hook makes the component re-render on every
updates. Disabling this automatic re-renderer can be an option when update. Disabling this automatic re-rendering can be an option when
you only use the model to make a table view, using the model to make a table view, which automatically synchronizes on
which automatically synchronizes on model updates. model updates.
@param sync - whether the component re-render on updates (default is `true`) @param sync Whether the component re-renders on updates (default is `true`).
*/ */
export function useSyncArray<K, A>( export function useSyncArray<K, A>(
arr: Array<K, A>, arr: Array<K, A>,
...@@ -475,7 +471,7 @@ export interface HistorySelection { ...@@ -475,7 +471,7 @@ export interface HistorySelection {
* - `HISTORY_NEXT` jumps to next history location * - `HISTORY_NEXT` jumps to next history location
* (first in [[nextSelections]]). * (first in [[nextSelections]]).
*/ */
type HistorySelectActions = 'HISTORY_PREV' | 'HISTORY_NEXT'; export type HistorySelectActions = 'HISTORY_PREV' | 'HISTORY_NEXT';
/** A selection of multiple locations. */ /** A selection of multiple locations. */
export interface MultipleSelection { export interface MultipleSelection {
...@@ -502,7 +498,7 @@ export interface NthSelect { ...@@ -502,7 +498,7 @@ export interface NthSelect {
* - `MULTIPLE_PREV` jumps to previous location of the multiple selections. * - `MULTIPLE_PREV` jumps to previous location of the multiple selections.
* - `MULTIPLE_NEXT` jumps to next location of the multiple selections. * - `MULTIPLE_NEXT` jumps to next location of the multiple selections.
*/ */
type MultipleSelectActions = export type MultipleSelectActions =
MultipleSelect | NthSelect MultipleSelect | NthSelect
| 'MULTIPLE_PREV' | 'MULTIPLE_NEXT' | 'MULTIPLE_CLEAR'; | 'MULTIPLE_PREV' | 'MULTIPLE_NEXT' | 'MULTIPLE_CLEAR';
...@@ -683,9 +679,7 @@ const emptySelection = { ...@@ -683,9 +679,7 @@ const emptySelection = {
const GlobalSelection = new GlobalStates.State<Selection>(emptySelection); const GlobalSelection = new GlobalStates.State<Selection>(emptySelection);
Server.onShutdown(() => GlobalSelection.setValue(emptySelection)); Server.onShutdown(() => GlobalSelection.setValue(emptySelection));
/** /** Current selection. */
Current selection.
*/
export function useSelection(): [Selection, (a: SelectionActions) => void] { export function useSelection(): [Selection, (a: SelectionActions) => void] {
const [selection, setSelection] = GlobalStates.useState(GlobalSelection); const [selection, setSelection] = GlobalStates.useState(GlobalSelection);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment