Publish Perspective as Neighbourhood
The back-bone of a Neighbourhood is a LinkLanguage - a Language that enables the sharing and thus synchronizing of links (see LinksAdapter). While there can and will be many different implementations with different trade-offs and features (like membranes etc.), there currently is one fully implemented and Holochain based LinkLanguage with the name Perspective Diff Sync (opens in a new tab).
It is deployed on the current test network (Language Language v0.0.15, included in current network seed (opens in a new tab)) under the address:
QmeBD9n9Z5yZsegxArToww5zmwtPpojXN6zXJsi7WwMUa8
.
Creating our unique LinkLanguage clone through templating
But we should not just use this publicly known Language as the back-bone for our new Neighbourhood, if we don't want to have everybody following this guide end up in the same network.
So what we want is to use this existing Language as a template and create a new copy with the same code but different UUID and/name in order to create a fresh space for our new Neighbourhood.
What parameters can we adjust when using it as template? Let's have a look at the Language's meta information:
const socialContextMeta = await ad4m.languages.meta(
"QmeBD9n9Z5yZsegxArToww5zmwtPpojXN6zXJsi7WwMUa8"
);
console.log(socialContextMeta);
Which should yield something like this:
{
name: 'Perspective Diff Sync',
address: 'QmeBD9n9Z5yZsegxArToww5zmwtPpojXN6zXJsi7WwMUa8',
description: 'Holochain based LinkLanguage. First full implementation of a LinkLanguage, for collaborative Neighbourhoods where every agent can add links. No membrane. Basic template for all custom Neighbourhoods in this first iteration of the Perspect3vism test network.',
author: 'did:key:zQ3shkkuZLvqeFgHdgZgFMUx8VGkgVWsLA83w2oekhZxoCW2n',
templated: false,
templateSourceLanguageAddress: null,
templateAppliedParams: null,
possibleTemplateParams: [ 'uuid', 'name', 'description' ],
sourceCodeLink: 'https://github.com/perspect3vism/perspective-diff-sync'
}
The field possibleTemplateParams
tells us that we can set a UUID
and override name
and description
.
Let's leave description but change the name.
The function languages.applyTemplateAndPublish()
takes an object as JSON as second parameter like so:
const uniqueLinkLanguage = await ad4m.languages.applyTemplateAndPublish(
"QmeBD9n9Z5yZsegxArToww5zmwtPpojXN6zXJsi7WwMUa8",
JSON.stringify({
uuid: "84a329-77384c-1510fb",
name: "Perspective Diff Sync clone for demo Neighbourhood",
})
);
This function call has done a lot for us:
- It took the source language (first parameter) and made sure we got the code, i.e. potentially downloading it from the Language of Languages.
- The provided template parameters have been applied. In the case of a Language using Holochain, it has unpacked the Holochain DNA, changed the DNA variables according to the values given as template parameters and packed the DNA again (not touching the WASM code)
- The resulting Language was published with meta information showing that it was templated, providing the source hash and template parameters.
So the new templated Language is ready to be used.
Creating the Neighbourhood
With that new LinkLanguage, actually creating the Neighbourhood is simple. We just have to provide the id of the perspective we want to upgrade to a Neighbourhood and the address of the LinkLanguage used for that:
const meta = new Perspective();
const neighbourhoodUrl = await ad4m.neighbourhood.publishFromPerspective(
myPerspective.uuid,
uniqueLinkLanguage.address,
meta
);
console.log(neighbourhoodUrl); // => neighbourhood://Qm123456789abcdef
The meta
field a (static/snapshotted) Perspective that is immutably stored with
the Neighbourhood. It can hold arbitrary/semantic meta information about the
Neighbourhood but can technically stay empty, just like we did here.