Skip to main content

Module items

Module items 

Source
Expand description

Actions on the items of a collection, offered on the items themselves.

An action whose first parameter is an item Id — “mark this todo done”, “delete this card” — acts on one element of a Collection. Asking the user (or an agent) to type that id is the wrong interface: the palette and context menus should offer the action on the item, with the id already bound. So #[resource] publishes every item of the record’s collections as a child resource whose actions are the item actions for it, their remaining parameters still typed. The action stays published on the record too, with its id parameter, for scripts that address items by id.

The collection an action acts on is the field its item parameter is named after, or the record’s only collection; #[action(item = field)] names it otherwise. #[resource] refuses to compile an item action whose collection is neither.

use tilo_resource::{Collection, Id, Model, resource};

#[derive(Model, Default)]
pub struct Shelf { pub books: Collection<String>, pub loans: Collection<String> }

#[resource(kind = "doc.shelf")]
impl Shelf {
    /// Lend a book.
    #[action(item = books)]
    pub fn lend(&mut self, book: &Id) { self.books.remove(book); }

    /// Return a loan: the parameter names its collection.
    #[action]
    pub fn loans(&mut self, loans: &Id) { self.loans.remove(loans); }
}

With two collections and neither named, it does not compile:

ⓘ
use tilo_resource::{Collection, Id, Model, resource};

#[derive(Model, Default)]
pub struct Shelf { pub books: Collection<String>, pub loans: Collection<String> }

#[resource(kind = "doc.shelf")]
impl Shelf {
    /// Lend a book.
    #[action]
    pub fn lend(&mut self, book: &Id) { self.books.remove(book); }
}

nor does naming a collection the record does not have:

ⓘ
use tilo_resource::{Collection, Id, Model, resource};

#[derive(Model, Default)]
pub struct Shelf { pub books: Collection<String> }

#[resource(kind = "doc.shelf")]
impl Shelf {
    /// Lend a book.
    #[action(item = loans)]
    pub fn lend(&mut self, book: &Id) { self.books.remove(book); }
}

or naming one for an action that takes no item:

ⓘ
use tilo_resource::{Collection, Model, resource};

#[derive(Model, Default)]
pub struct Shelf { pub books: Collection<String> }

#[resource(kind = "doc.shelf")]
impl Shelf {
    /// Clear the shelf.
    #[action(item = books)]
    pub fn clear(&mut self, everything: bool) { if everything { self.books = Collection::new(); } }
}

A label joined from several fields names each of them once: naming one twice would label an item by a field that is not there.

ⓘ
use tilo_resource::Model;

#[derive(Model, Default)]
#[model(label = "first first")]
pub struct Person { pub first: String, pub last: String }

Structs§

ChildrenParts
Resource::children in the parts a publisher can keep between versions (Resource::children_parts): children built afresh, children kept while they are unchanged, then one per item of items carrying item_actions (item_children).
ItemAction
One action whose first parameter is an item id, as #[resource] records it.
ItemCollection
The items of one collection field, as #[derive(Model)] lists them.
ItemText
One labelled item of a collection, as search indexes it.
Ref
A reference to one item of a collection, as an action that names an item of its own record takes it.

Constants§

ITEM_PAGE
How many items of one collection a published tree carries; the rest are resolved one by one when addressed (item_child).
RENAME
The id of the prompt that renames an item.

Traits§

ItemSource
A collection field’s items as #[derive(Model)] publishes them: written with plain loops, once per item type, so a record’s derived code calls these rather than repeating iterator chains per field.

Functions§

bound
decl offered on the item it acts on, with values bound to their parameters: what a published child carries (“remove this photograph”, “rename this album”). The other parameters stay typed; the action is built, checked and undone exactly as the declaration is. Published on a child, the declaration stays on the resource for scripts that name the item, out of the palette’s way.
fingerprint
What a published resource is, as text: its identity, its actions with their parameters and contract, and its children, for telling two publications of the same thing apart.
for_each_item_child
item_children one item at a time, for a publisher that keeps the children it built for an earlier version: each(collection, id, label, build) is called for every item child in order, and build() makes that child exactly as item_children does. A child is a function of its collection (field and the items it sits in), its id and its label, and the locale its actions’ labels are in.
item_child
The item resources of the collections fields of R that actions act on: what a publication would carry for item resource_id, built on its own, or for a resource nested in an item (<kind>/pages/<page>/body, crate::child::NestedResource). label_of(field, id) names an item, or says it is not there.
item_child_id
The id of the resource the item id of collection is published as.
item_children
The item resources of a record: one per item of each collection, carrying the item actions that act on that collection with the item bound.
item_kind
The kind an item published under resource_id has, <kind>.<field>, read from its id, <kind>/<field>/<item>; None for an id naming no item of a top-level collection.
item_of_resource
The item an item resource id names, if it is one of R’s.
item_of_resource_in
item_of_resource of a resource of the kind kind.
item_resource_id
The id of the child resource an item is published as.
item_resource_id_in
item_resource_id of an item of a resource of kind kind: compiled once in the shared runtime rather than once per resource type in every app.
nested_resource_id
The id of the child resource an item of a nested collection is published as: <kind>/slides/<slide>/elements/<element>.
offered_bound
Whether some resource in children, at any depth, offers decl with arguments bound (bound).
offered_on_items
Resource::children_offer_bound of a record whose children are others, its derived resources, then its item_children: the declarations offered bound on others, on a derived resource or on the items of a collection, known from how many items each collection holds (sizes, by field) without building a child per item.

Type Aliases§

ItemChildVisitor
What for_each_item_child calls per item child: the collection it is an item of, its id and label, and how to build it.