Skip to content

Commit

Permalink
Merge branch 'main' into feat/guide/app-structure-zome-functions
Browse files Browse the repository at this point in the history
  • Loading branch information
pdaoust authored Jan 30, 2025
2 parents a35aab4 + 0ed865a commit 27ac11c
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 35 deletions.
1 change: 1 addition & 0 deletions .cspell/custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ builtins
Brisebois
Burmeister
Cachix
cdylib
CRDT
d'Aoust
fixt
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/spellcheck.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: 'Check spelling'
on: # rebuild any PRs and main branch changes
pull_request:
push:
branches:
- main

jobs:
spellcheck: # run the action
Expand All @@ -16,4 +18,15 @@ jobs:
with:
root: 'src'
files: '**/*.{json5,njk,md}'
incremental_files_only: false
incremental_files_only: false

ci_pass:
if: ${{ always() }}
runs-on: "ubuntu-latest"
needs:
- spellcheck
steps:
- name: check status
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@ styles-compiled/

# A place to put a local scaffolded DNA so you can test code for the build guide
# without having to have two projects/folderss open in your editor.
code_test/
code_test*/
42 changes: 21 additions & 21 deletions src/pages/_data/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ const footerLinks = loadJson5("./navigation/footerLinks.json5");
const mainNav = loadJson5("./navigation/mainNav.json5");
const headerNav = loadJson5("./navigation/headerNav.json5");

function findTopLinkRecordFor(url) {
return mainNav.links.find((l) => {
if (l.url === url) { return true; }
function findTopLinkRecordFor(nav, url) {
function urlInNodeOrChildren(item) {
if (item.url === url) { return true; }
return item.hasChildren && item.children.some(urlInNodeOrChildren);
};

return l?.children?.some((cl) => cl.url === url);
});
return nav.children.find(urlInNodeOrChildren);
}

const mainNavObj = {
...mainNav,
links: mainNav.links.map((l) => ({
...l,
hasChildren: (l.children && l.children.length > 0)
})),
getActiveParentLink(pageUrlRendering) {
return findTopLinkRecordFor(pageUrlRendering);
}
};
// Iteratively add the `hasChildren` property and `getActiveParentLink` method
// to a nav node.
function mapNavChildren(item) {
return {
...item,
children: item.children && item.children.length > 0 && item.children.map(mapNavChildren),
hasChildren: item.children && item.children.length > 0,
getActiveParentLink(pageUrlRendering) {
return findTopLinkRecordFor(this, pageUrlRendering);
},
};
}

const headerNavObj = {
...headerNav,
getActiveParentLink(pageUrlRendering) {
return findTopLinkRecordFor(pageUrlRendering);
}
};
const mainNavObj = mapNavChildren(mainNav);

const headerNavObj = mapNavChildren(headerNav);

export default {
footerNav: {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/_data/navigation/headerNav.json5
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
links: [
children: [
{ title: "Get Started", url: "/get-started/", class:"" },
{ title: "Learn", url: "/concepts/1_the_basics/", class:"" },
{ title: "Build", url: "/build", class:"" },
Expand Down
2 changes: 1 addition & 1 deletion src/pages/_data/navigation/mainNav.json5
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
links: [
children: [
{ title: "Get Started", url: "/get-started/", children: [
{ title: "1. Install Holochain Development Environment", url: "/get-started/#2-installing-holochain-development-environment" },
{ title: "2. Hello World", url: "/get-started/2-hello-world/" },
Expand Down
4 changes: 2 additions & 2 deletions src/pages/_includes/widgets/navigation.njk
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<li id="mobile-search">
<a href="/search" title="Search the site">{{ mdiSearch() }}</a>
</li>
{% for topLink in mainNavData.links %}
{% for topLink in mainNavData.children %}
{% set isCurrentParent = topLink.url == activeParent.url %}
<li {% if isCurrentParent %} data-is-current-parent="true" {% endif %}
{% if topLink.url == page.url %} aria-current="page" {% endif %} >
Expand All @@ -51,7 +51,7 @@
{% set activeParent = headerNavData.getActiveParentLink(page.url) %}
<nav id="header-nav">
<ul>
{% for link in headerNavData.links %}
{% for link in headerNavData.children %}
<li {% if link.url == activeParent.url %} data-is-current-parent="true" {% endif %} >
<a href="{{ link.url }}">{{ link.title }}</a>
</li>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/build/identifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ use hdi::prelude::*;

#[hdk_entry_helper]
pub struct MovieLoan {
movie_hash: EntryHash,
lent_to: AgentPubKey,
loan_duration_seconds: i64,
pub movie_hash: EntryHash,
pub lent_to: AgentPubKey,
pub loan_duration_seconds: i64,
}

// Remember to create a variant in your `EntryTypes` enum for this new type!
Expand Down
2 changes: 1 addition & 1 deletion src/pages/build/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Holochain Build Guide
---

!!! note In progress
This guide is under construction. Expect more content to be rapidly published in the second half of 2024.
This guide is under construction. Expect more content to be rapidly published in the first half of 2025.
!!!

::: intro
Expand Down
1 change: 1 addition & 0 deletions src/pages/build/links-paths-and-anchors.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ let links_to_movies_starting_with_g = get_links(
path_to_movies_starting_with_g.path_entry_hash()?,
LinkTypes::MovieByFirstLetter
)?
.build()
)?;
```

Expand Down
17 changes: 15 additions & 2 deletions src/pages/build/zomes.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,17 @@ If you want to create a zome without the scaffolding tool, first make sure you h
cargo new my_integrity_zome --lib
```

Then add some necessary dependencies to your new `Cargo.toml` file:
Then add some necessary bits to your new `Cargo.toml` file:

```diff:toml
[package]
name = "my_integrity_zome"
version = "0.1.0"
edition = "2021"
+[lib]
+crate-type = ["cdylib"]
[dependencies]
+hdi = "=0.5.0-rc.1"
+serde = "1.0"
Expand All @@ -68,19 +76,24 @@ When you've written some code, compile your zome using `cargo`:
cargo build --release --target wasm32-unknown-unknown
```

Your zome will be in `target/wasm32-unknown-unknown/release/my_integrity_zome.wasm`.

### Coordinator

Coordinator zomes hold your back-end logic --- the functions that read and write data or communicate with peers. In addition to some optional lifecycle hooks [lifecycle hooks](/build/callbacks-and-lifecycle-hooks/#coordinator-zomes), you'll also write your own **zome functions** that serve as your zome's API.

#### Create a coordinator zome

Again, **the easiest way to create a coordinator zome** is to let the scaffolding tool do it for you. But if you want to do it yourself, it's the same as an integrity zome, with one exception. Your `Cargo.toml`'s dependencies should be modified like this:
Again, **the easiest way to create a coordinator zome** is to let the scaffolding tool do it for you. But if you want to do it yourself, it's the same as an integrity zome, with one exception. Use the above additions to the integrity zome's `Cargo.toml` as a template, but change the dependencies like this:

```diff:toml
[dependencies]
-hdi = "=0.5.0-rc.1"
+hdk = "=0.4.0-rc.1"
serde = "1.0"
+# If you want to work with the types you defined in your integrity zome,
+# specify a dependency on it here.
+my_integrity_zome = { path = "../my_integrity_zome" }
```

## Define a function
Expand Down
16 changes: 14 additions & 2 deletions src/pages/resources/upgrade/upgrade-holochain-0.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,20 @@ The biggest change for 0.4 is that some features are marked `unstable` and aren'

**If your DNA needs to call a host function that depends on an unstable feature**, you'll need to do two things:
1. Build a custom Holochain binary with both the specific feature you need (see the list above) and `unstable-functions` enabled.
2. Enable the `unstable-functions` flag for the `hdi` and `hdk` dependencies in your zomes' `Cargo.toml` (see the section after the next).
1. [Build a custom Holochain binary](https://github.com/holochain/holonix?tab=readme-ov-file#customized-holochain-build) with both the specific feature you need (see the list above) and `unstable-functions` enabled.
2. Enable the `unstable-functions` flag for the `hdi` and `hdk` dependencies in your zomes' `Cargo.toml` files, and enable the `unstable-countersigning` flag for the `hdk` dependency if you need it:

```diff:toml
[dependencies]
-hdi = { workspace = true }
+hdi = { workspace = true, features = ["unstable-functions"] }
```
```diff:toml
[dependencies]
-hdk = { workspace = true }
+hdk = { workspace = true, features = ["unstable-functions", "unstable-countersigning"] }
```
Note that you'll need to make sure your users are running your custom conductor binary. If you compile your zomes without `unstable-functions` enabled for `hdi` or `hdk`, users with the flag enabled in Holochain will still be able to use your hApp, but if you compile your zomes _with_ `unstable-functions`, users with the flag(s) disabled won't be able to use your hApp.
Expand Down

0 comments on commit 27ac11c

Please sign in to comment.