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§
- Children
Parts Resource::childrenin the parts a publisher can keep between versions (Resource::children_parts): children built afresh, children kept while they are unchanged, then one per item ofitemscarryingitem_actions(item_children).- Item
Action - One action whose first parameter is an item id, as
#[resource]records it. - Item
Collection - The items of one collection field, as
#[derive(Model)]lists them. - Item
Text - 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§
- Item
Source - 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
decloffered on the item it acts on, withvaluesbound 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_childrenone 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, andbuild()makes that child exactly asitem_childrendoes. 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
fieldsofRthatactionsact on: what a publication would carry for itemresource_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
idofcollectionis 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_idhas,<kind>.<field>, read from its id,<kind>/<field>/<item>;Nonefor 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_resourceof a resource of the kindkind.- item_
resource_ id - The id of the child resource an item is published as.
- item_
resource_ id_ in item_resource_idof an item of a resource of kindkind: 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, offersdeclwith arguments bound (bound). - offered_
on_ items Resource::children_offer_boundof a record whose children areothers, itsderivedresources, then itsitem_children: the declarations offered bound onothers, 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§
- Item
Child Visitor - What
for_each_item_childcalls per item child: the collection it is an item of, its id and label, and how to build it.