TLDR
- The first block on a page must be a
contextcategory block. - A page can have multiple
contextblocks. - Every
contexthas a singlestateobject. - All input blocks write their value to
state, with the theiridas the key in thestateobject. - Input blocks which are not visible are removed from
state. - The
SetStateaction can also modify thestateobject.
A Lowdefy block with category context provides the environment for a part of a Lowdefy app to run in. More than one context can be placed on a page, but generally only one is needed. The first block on a page must be a context category block.
The standard page blocks like PageHeaderMenu or PageSiderMenu are all context category blocks, and the Context block is a simple container that also provides a context.
Each context provides encapsulation to the blocks inside it. It has it's own state object as well as requests.
Every input category block inside the context will have a value in the state object, with the their id as the key in the state object, unless the block is not visible, in which case the input value is removed the state object.
The only other way to modify the state object is to use a SetState action. See SetState and events-and-actions for more details.
Contexts remain even as users navigate to new pages, so if a user returns to a page, the state as they left it will remain.
Url queries
A new context is created for each distinct URL query parameters seen by the app. This means that if a page is open with two different URL queries, two different contexts, with separate state objects will be created.
Context IDs
Each context created has a identifier with the following structure:
{pageId}:{blockId}:{JSON stringified urlQuery object}Context data objects
A Lowdefy context makes some additional data object accessible via operators. These include:
_global: Theglobalobject is a single app level data object defined in the Lowdefy config root. This object is the same for everycontext, it is also passed between the client and server. If theSetGlobalaction is called, it is not consistent between clients, like different users, or a single user with multiple tabs open._state: Astateobject is unique to acontextand everyinputblock maintains a value in it's parentstateobject. Thisstateobject is passed to the server when requests are called. TheSetStateaction can be used to modify the value of astateobject in the samecontextfrom whichSetStateis called._url_query: TheurlQueryobject is used to access variables set in the url. Url query parameters can be set using theurlQueryfield in theLinkaction. It can be useful to create sharable links containing some additional information other than the page route. For example setting a document id in the url so that the document can be retrieved when the link is opened during the pageonEnterevent. Note that any variables set tourlQuerywill be publicly visible._input: Theinputobject is unique to a page, and works similar to theurlQueryobject. Theinputobject is used to pass information between page transitions. This variable set to theinputobject are not written to the url, so they are not visible publicly but also cannot be used to share the data in a link since ainputobject is only consistent between onecontextand the next to which it links. Ainputobject is set to theinputfield of theLinkaction when linking from one pagecontextto the next._media: Themediaobject contains some information about the client screen size etc. This is useful in order to add additional responsive logic to a page._user: Theuserobject contains the data in the user idToken if OpenID Connect authentication is configured and a user is logged in.
