Skip to content

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.

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.

ReturnsSignatureSummary
UIStore()Creates a store, for a subclass.

ReturnsSignatureSummary
voidsave()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.
UIStoreDatagetData()The @UIStoreData annotation of the store.
ReturnsSignatureSummary
voidinit() hookFills the store with its starting values.
voiddestroy() hookReleases what the store holds when its scope ends: JOID calls it for a LOCAL store when the UI that holds it closes.
voidfromJson(Map<String,Object> json) hookRestores the values that toJson() saved, right after init().

UIStore()

Creates a store, for a subclass.

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. A toJson() that throws prints a warning, and the other stores are saved anyway.

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.

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.

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

Report a problem with this page