Module hdk_crud::example[][src]

Expand description

Take a look at this module to get a concrete example of what you need to pass the crud! macro, as well as what you’ll get back out of it. Anything that says “NOT GENERATED” is not generated by the crud! macro call, and the rest is It will generate 4 public Zome functions, as well as some inner functions called by those that you can refer to and call elsewhere. The 4 Zome functions in this example would be: create_example, fetch_examples, update_example, and archive_example.

Structs

NOT GENERATED This is our example hdk_entry entry type definition.

This will be used to send data events as signals to the UI. All signals relating to the entry type will share this high level structure, creating consistency. The data field should use the variant (Create/Update/Delete) that matches the variant for action. So if action is variant ActionType::Create then data should be ExampleSignalData::Create.

This is what is expected by a call to update_example or inner_update_example

This data structure will be very broadly useful and represents how an entry should be serialized along with what metadata to form a consistent pattern that the UI or client can expect. It is called ExampleWireEntry because it is how data looks passed ‘over the wire’ or network.

This is what will be returned by a call to fetch_examples or inner_fetch_examples It is just a list/vec of ExampleWireEntry. It is defined for the purposes of serialization.

Enums

Distinguishes between what data structures should be passed to the UI based on different action types, like create/update/delete this will be used to send these data structures as signals to the UI When Create/Update, we will pass the actual new Entry but when doing Delete we will naturally only pass the HeaderHash

NOT GENERATED A high level signal type to unify all the entry type specific signal types

Constants

This is the &str that can be passed into Path to find all the entries created using these create functions which are linked off of this Path.

Functions

This is the exposed/public Zome function for archiving an entry of this type. This will mark the entry at address as “deleted”. It will no longer be returned by fetch_examples. It will send a signal of this event to all peers returned by the get_peers call given during the macro call to crud! This just calls inner_archive_example with send_signal as true.

NOT GENERATED This handles the conversion from its predefined type to some slightly modified type that it should be sent over the wire as. It is sort of like a pre-signal-fire hook presenting the chance to do type conversion

This is the exposed/public Zome function for creating an entry of this type. This will create an entry and link it off the main Path. It will send a signal of this event to all peers returned by the get_peers call given during the macro call to crud! This just calls inner_create_example with send_signal as true.

This is the exposed/public Zome function for fetching ALL the entries of the type. No signals will be sent as a result of calling this. Notice that it pluralizes the value of $i, the second argument to the crud! macro call. This just calls inner_fetch_examples.

Retrieve the Path for these entry types to which all entries are linked

NOT GENERATED This handles the fetching of a list of peers to which to send signals. In this example it’s an empty list. Your function signature should match this function signature.

This will mark the entry at address as “deleted”. It will no longer be returned by fetch_examples. It can also optionally send a signal of this event (by passing send_signal value true) to all peers returned by the get_peers call given during the macro call to crud! This will be called with send_signal as true by archive_example

This will create an entry and link it off the main Path. It can also optionally send a signal of this event (by passing send_signal value true) to all peers returned by the get_peers call given during the macro call to crud! This will be called with send_signal as true by create_example

This is the exposed/public Zome function for fetching ALL the entries of the type.

This will add an update to an entry. It can also optionally send a signal of this event (by passing send_signal value true) to all peers returned by the get_peers call given during the macro call to crud!

NOT GENERATED Signal Receiver (forwards signals to the UI) would be handling a

This is the exposed/public Zome function for creating an entry of this type. This will add an update to an entry. It will send a signal of this event to all peers returned by the get_peers call given during the macro call to crud! This just calls inner_update_example with send_signal as true.