UIStore
abstract class UIStore
Package: dev.joid.lib.ui.core.hook.store · Module: core · Source: UIStore.java
Base class of a store, a container of values that lives as long as its scope and that several UIs can share.
Description
Section titled “Description”Annotate the subclass with UIStoreData and get it with UI.useStore or Node.useStore.
A PERMANENT store is read from the data folder when it is created and written back when a UI closes and when the JVM stops.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
| UIStore() | Creates a store, for a subclass. |
Methods
Section titled “Methods”| Returns | Signature | Summary |
|---|---|---|
void | save() | Writes a PERMANENT store to its file now; a store of another scope ignores it. |
Map<String,Object> | toJson() | Returns the values to save for a PERMANENT store, as a map that JOID writes as JSON: numbers, texts, booleans, maps, lists and arrays, and any other object field by field. |
UIStoreData | getData() | The @UIStoreData annotation of the store. |
For subclasses
Section titled “For subclasses”| Returns | Signature | Summary |
|---|---|---|
void | init() hook | Fills the store with its starting values. |
void | destroy() hook | Releases what the store holds when its scope ends: JOID calls it for a LOCAL store when the UI that holds it closes. |
void | fromJson(Map<String,Object> json) hook | Restores the values that toJson() saved, right after init(). |
Creation details
Section titled “Creation details”UIStore
Section titled “UIStore”UIStore()
Creates a store, for a subclass.
Method details
Section titled “Method details”void save()
Writes a PERMANENT store to its file now; a store of another scope ignores it.
toJson
Section titled “toJson”Map<String,Object> toJson()
Returns the values to save for a PERMANENT store, as a map that JOID writes as JSON: numbers, texts, booleans, maps, lists and arrays, and any other object field by field.
A toJson() that throws prints a warning, and the other stores are saved anyway.
getData
Section titled “getData”UIStoreData getData()
The @UIStoreData annotation of the store.
Throws an IllegalStateException when the class has none.
void init() hook
Fills the store with its starting values.
JOID calls it once, right after the factory creates the store and before fromJson.
destroy
Section titled “destroy”void destroy() hook
Releases what the store holds when its scope ends: JOID calls it for a LOCAL store when the UI that holds it closes.
A destroy() that throws prints a warning, and the store is forgotten anyway.
fromJson
Section titled “fromJson”void fromJson(Map<String,Object> json) hook
Restores the values that toJson() saved, right after init().
The map holds the types of JSON: Long and Double for the numbers, Boolean, String, List<Object> and Map<String, Object>.
A fromJson() that throws prints a warning, keeps a copy of the file aside, and the store starts again from init().
fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses
