From 0836d935dfaf8bca2d8dca5e808bfee5c7eb7606 Mon Sep 17 00:00:00 2001 From: Leo Galambos Date: Tue, 8 Jul 2025 21:25:56 +0200 Subject: [PATCH] Update API Reference --- API-Reference.md | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/API-Reference.md b/API-Reference.md index f585f6f..a7bf175 100644 --- a/API-Reference.md +++ b/API-Reference.md @@ -4,17 +4,28 @@ This page summarizes the key classes in **Conflux**. ## Ctx -- `put(Key, T value)` — store or update a value for a key -- `get(Key)` — retrieve a value -- `contains(Key)` — check if a key is present -- `remove(Key)` — remove a key and its listeners -- `clear()` — remove everything -- `addListener(Key, Listener)` — register a weakly referenced listener -- `removeListener(Key, Listener)` — remove a listener +`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. + +### Default Context Operations + +- `put(Key, T value)` — store or update a value for a key in the default context +- `get(Key)` — retrieve a value from the default context +- `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, Listener)` — register a weakly referenced listener in the default context +- `removeListener(Key, Listener)` — 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 -A strongly typed key: +A strongly typed key used to identify context entries: ```java Key nameKey = new Key<>("name", String.class); @@ -23,9 +34,11 @@ Key nameKey = new Key<>("name", String.class); * `name()` returns the key name * `type()` returns the key type +Keys ensure type consistency and prevent accidental type mismatches. + ## Listener -An interface for change notifications: +An interface for receiving notifications on value changes: ```java public interface Listener { @@ -33,7 +46,7 @@ public interface Listener { } ``` -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]] \ No newline at end of file +[[Home]] | [[Programming Guide]] | [[Design and Architecture]] | [[FAQ]] | [[Contributing]]