Update API Reference

2025-07-08 21:25:56 +02:00
parent 9e0c11a4bc
commit 0836d935df

@@ -4,17 +4,28 @@ This page summarizes the key classes in **Conflux**.
## Ctx ## Ctx
- `put(Key<T>, T value)` — store or update a value for a key `Ctx` is a singleton enum that serves as the primary access point for the default application-wide context. It also supports managing multiple independent named contexts.
- `get(Key<T>)` — retrieve a value
- `contains(Key<?>)` — check if a key is present ### Default Context Operations
- `remove(Key<?>)` — remove a key and its listeners
- `clear()` — remove everything - `put(Key<T>, T value)` — store or update a value for a key in the default context
- `addListener(Key<T>, Listener<T>)` — register a weakly referenced listener - `get(Key<T>)` — retrieve a value from the default context
- `removeListener(Key<T>, Listener<T>)` — remove a listener - `contains(Key<?>)` — check if a key is present in the default context
- `remove(Key<?>)` — remove a key and its listeners from the default context
- `clear()` — clear all keys and listeners from the default context
- `addListener(Key<T>, Listener<T>)` — register a weakly referenced listener in the default context
- `removeListener(Key<T>, Listener<T>)` — remove a listener from the default context
### Managing Multiple Named Contexts
- `getContext(String name)` — retrieve or create a named independent context implementing `CtxInterface`
- `contextNames()` — returns the set of existing named context keys
Each named context functions independently with its own keys, values, and listeners, allowing isolated storage scopes within the same application.
## Key ## Key
A strongly typed key: A strongly typed key used to identify context entries:
```java ```java
Key<String> nameKey = new Key<>("name", String.class); Key<String> nameKey = new Key<>("name", String.class);
@@ -23,9 +34,11 @@ Key<String> nameKey = new Key<>("name", String.class);
* `name()` returns the key name * `name()` returns the key name
* `type()` returns the key type * `type()` returns the key type
Keys ensure type consistency and prevent accidental type mismatches.
## Listener ## Listener
An interface for change notifications: An interface for receiving notifications on value changes:
```java ```java
public interface Listener<T> { public interface Listener<T> {
@@ -33,7 +46,7 @@ public interface Listener<T> {
} }
``` ```
Registered listeners will be weakly referenced and called on value change. Listeners are weakly referenced to avoid memory leaks and invoked whenever the corresponding key's value changes.
--- ---
[[Home]] | [[Programming Guide]] | [[Design and Architecture]] | [[FAQ]] | [[Contributing]] [[Home]] | [[Programming Guide]] | [[Design and Architecture]] | [[FAQ]] | [[Contributing]]