Introduction
warning
WIP docs!
A State holds Information we need to remember at a later point in time.
It is the foundation of AgileTs. Nearly everything is based or depends on the functionality of States.
For instance, a Collection is a set of States.
We instantiate a State with help of an existing Agile Instance often called App
.
By doing so, the State is automatically bound to the Agile Instance it was created from.
The first property of createState()
is the initial value of the State.
After a successful instantiation,
we can start working with it.
If you want to find out more about specific methods of the State, checkout the Methods docs. Most methods we use to modify, mutate and access the State are chainable.
#
๐จ UsageWe might use a State, if we want to remember the active theme of our application, or the userId of the current logged-in User.
In the above example, we create a THEME_TYPE
State with the initial value "dark".
After toggling the theme switch, we update the THEME_TYPE
to "light".
#
โณ๏ธ SandboxTest the State yourself. It's only one click away. Just select your preferred Framework below.
- React
- Vue (coming soon)
- Angular (coming soon)
#
๐ญ PropsinitialValue
#
The first Value which gets assigned to our State.
config
#
Our State
takes, beside the initial value an optional configuration object.
Here is a Typescript Interface for quick reference. However, each property is explained in more detail below.
key
#
The key/name is an optional property that serves to identify a State later.
A key is pretty useful during debug sessions or if we persist our State.
Then, it automatically uses the key
as persist-key, and we don't have to pass it separately.
We recommend giving each State an unique key
. It has only advantages.
dependents
#
info
It gets mainly used internally and has properly no use for you.
It defines which States depend on our State. This means if our State gets mutated and ingested into the runtime, the depending States gets also ingested into the runtime.
isPlaceholder
#
info
It gets mainly used internally and has properly no use for you.
With isPlaceholder
we define our State as a placeholder.
A State is often a placeholder if AgileTs holds a reference to it, althought it hasn't been instantiated yet.
#
๐ฆ TypescriptThe State Class
is almost 100% typesafe and takes an optional generic type for type safety of its value
.
Javascript users can also get rudimentary type safety with the type
function.
Be aware that the type
function currently only supports primitive types and does its type check at runtime.