Add API Reference
40
API-Reference.md
Normal file
40
API-Reference.md
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# API Reference
|
||||||
|
|
||||||
|
This page summarizes the key classes in **Conflux**.
|
||||||
|
|
||||||
|
## Ctx
|
||||||
|
|
||||||
|
- `put(Key<T>, T value)` — store or update a value for a key
|
||||||
|
- `get(Key<T>)` — retrieve a value
|
||||||
|
- `contains(Key<?>)` — check if a key is present
|
||||||
|
- `remove(Key<?>)` — remove a key and its listeners
|
||||||
|
- `clear()` — remove everything
|
||||||
|
- `addListener(Key<T>, Listener<T>)` — register a weakly referenced listener
|
||||||
|
- `removeListener(Key<T>, Listener<T>)` — remove a listener
|
||||||
|
|
||||||
|
## Key
|
||||||
|
|
||||||
|
A strongly typed key:
|
||||||
|
|
||||||
|
```java
|
||||||
|
Key<String> nameKey = new Key<>("name", String.class);
|
||||||
|
````
|
||||||
|
|
||||||
|
* `name()` returns the key name
|
||||||
|
* `type()` returns the key type
|
||||||
|
|
||||||
|
## Listener
|
||||||
|
|
||||||
|
An interface for change notifications:
|
||||||
|
|
||||||
|
```java
|
||||||
|
public interface Listener<T> {
|
||||||
|
void valueChanged(T newValue);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Registered listeners will be weakly referenced and called on value change.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
\[\[Home]] | \[\[Programming Guide]] | \[\[Design and Architecture]]
|
||||||
Reference in New Issue
Block a user