Wrangler
- 1 Overview
- 2 Pico life cycle
- 3 Pico Channels
- 3.1 Creating a new channel
- 3.1.1 Synchronous creation
- 3.1.2 Asynchronous creation
- 3.2 Finding channels
- 3.3 Deleting a channel
- 3.3.1 Synchronous deletion
- 3.3.2 Asynchronous deletion
- 3.4 Rotating a channel
- 3.1 Creating a new channel
- 4 Pico Rulesets
- 5 picoQuery
- 5.1 Parameters
- 5.2 Returns
- 5.3 Example
Note: Since the pico-engine NEXT changes the major version number from 0 to 1, the KRL language will experience breaking changes. Code that ran in 0.52.4 will have to be changed to run correctly in 1.0.0.
Overview
The rulesets which make up Wrangler are a kind of operating system for picos. Every pico that is created within a pico-engine has these three rulesets installed:
io.picolabs.wrangler
for managing pico life cycle, rulesets, and channelsio.picolabs.subscription
for managing subscriptions between arbitrary picosio.picolabs.pico-engine-ui
for holding information needed by the developer UI
This page documents the wrangler ruleset, and deals with parent/child relationships, rulesets within a pico, and creation and deletion of channels.
Pico life cycle
The engine creates the first pico, the root pico, when it starts for the first time. Any pico can create a child pico. A pico can have one of its children deleted. It is not possible to delete the root pico.
Creating a child pico
This always begins with a pre-existing pico which will become the parent of the new pico, its new child pico. Somehow, the wrangler:new_child_request
event needs to be sent to, or raised within, the parent pico.
The process is fairly involved, and is diagrammed below. This illustrates the case where the developer using the developer UI provides a name and background color in the About tab of the parent-to-be. Notice that the UI sends the engine_ui:new
event to the pico. That event checks the event attributes, supplying defaults as needed, and raises the wrangler:new_child_request
event (with required attribute name
), to which a rule in the wrangler ruleset reacts as shown here:
The rule creates the new child pico (shown by a green arrow), and sends it a sequence of events:
the
engine_ui:setup
event, fielded by the engine-ui ruleset which creates a new channel suitable for use by the UI, and returns that channel’s ID which is bound to the namenewUiECI
the
wrangler:pico_created
event, fielded by a wrangler rule, which saves the name, and installs the subscription ruleset (shown by a green arrow)the
engine_ui:box
event, fielded by the engine-ui ruleset which stores away the name and background color so that the new pico can be correctly rendered in the developer UI
Finally that rule raises a wrangler:new_child_created
event for the parent pico. And, the child pico, after it has finished with its work, sends a wrangler:child_initialized
event back to the parent pico.
Note that in the diagram, these are “received” in the parent pico with a big “X” meaning that there are no rules in the wrangler ruleset which select on this events. Developer-supplied KRL rulesets which initiate a child creation are free to include rules which react to one or both of these events.
While a pico exists
Between the time a pico is created and the time it is deleted, we may need to get information about it, its parent, and its children. Wrangler includes functions which produce this information. In KRL terms, wrangler both provides
(when used as a module) and shares
(with the outside world) these functions.
Finding parent pico
Wrangler has a function, parent_eci
, which returns the ECI that the pico can use to reach its parent pico.
Finding child picos
Wrangler has a function, children
, which returns an array of maps. Each map has information about the pico’s child picos.
For example, from the Section Collection pico, this array looks like this: