Skip to content

Commit

Permalink
update to syn 0.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zippy committed Dec 19, 2023
1 parent 3cc6d6a commit a375088
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 122 deletions.
141 changes: 73 additions & 68 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dnas/kando/zomes/coordinator/syn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ name = "syn"
#derive_more = "0"
#serde = { workspace = true }

hc_zome_syn_coordinator = {git = "https://github.com/holochain/syn", branch = "develop"}
hc_zome_syn_coordinator = {git = "https://github.com/holochain/syn", branch = "main"}
2 changes: 1 addition & 1 deletion dnas/kando/zomes/integrity/syn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ name = "syn_integrity"
#derive_more = "0"
#serde = { workspace = true }

hc_zome_syn_integrity = {git = "https://github.com/holochain/syn", branch = "develop"}
hc_zome_syn_integrity = {git = "https://github.com/holochain/syn", branch = "main"}
45 changes: 28 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@holochain-open-dev/profiles": "^0.17.3",
"@holochain-open-dev/stores": "^0.8.5",
"@holochain-open-dev/utils": "^0.16.3",
"@holochain-syn/core": "^0.10.0",
"@holochain-syn/core": "^0.12.0",
"@holochain/client": "^0.16.7",
"@lightningrodlabs/we-applet": "^0.12.2",
"@mdi/js": "^7.1.96",
Expand Down
6 changes: 3 additions & 3 deletions ui/src/AboutDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import type { KanDoStore } from "./store";
import {asyncDerived, toPromise} from '@holochain-open-dev/stores'
import { BoardType } from "./boardList";
import { boardGrammar, Board, type BoardState } from "./board";
import type { Board, BoardState } from "./board";
import { deserializeExport, exportBoards } from "./export";
import { DocumentStore, WorkspaceStore } from "@holochain-syn/core";
import { encodeHashToBase64 } from "@holochain/client";
Expand Down Expand Up @@ -51,7 +51,7 @@
exporting = true
const hashes = await toPromise(asyncDerived(store.synStore.documentsByTag.get(BoardType.active),x=>Array.from(x.keys())))
const docs = hashes.map(hash=>new DocumentStore(store.synStore, boardGrammar, hash))
const docs = hashes.map(hash=>new DocumentStore(store.synStore, hash))
for (const docStore of docs) {
try {
const workspaces = await toPromise(docStore.allWorkspaces)
Expand All @@ -69,7 +69,7 @@
</script>


<sl-dialog label="KanDo!: UI v0.6.6 for DNA v0.5.1" bind:this={dialog} width={600} >
<sl-dialog label="KanDo!: UI v0.7.0 for DNA v0.6.0" bind:this={dialog} width={600} >
<div class="about">
<p>KanDo! is a demonstration Holochain app built by the Holochain Foundation.</p>
<p> <b>Developers:</b>
Expand Down
52 changes: 28 additions & 24 deletions ui/src/board.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DocumentStore, type SessionStore, type SynGrammar, WorkspaceStore, type SynStore } from "@holochain-syn/core";
import type { DocumentStore, SessionStore, WorkspaceStore, SynStore } from "@holochain-syn/core";
import { get, type Readable } from "svelte/store";
import { v1 as uuidv1 } from "uuid";
import { type AgentPubKey, type EntryHash, type EntryHashB64, encodeHashToBase64, type AgentPubKeyB64, type Timestamp } from "@holochain/client";
Expand Down Expand Up @@ -67,6 +67,8 @@ export type BoardProps = {
bgUrl: string,
}

export type BoardEphemeralState = { [key: string]: string };

export interface BoardState {
status: string;
name: string;
Expand Down Expand Up @@ -167,11 +169,6 @@ export interface BoardState {
id: string;
};

export type BoardGrammar = SynGrammar<
BoardDelta,
BoardState
>;

const _removeCardFromGroups = (state: BoardState, cardId: uuidv1) => {
_initGrouping(state)
// remove the item from the group it's in
Expand Down Expand Up @@ -233,16 +230,19 @@ export interface BoardState {
})
}

export const boardGrammar: BoardGrammar = {
initState(state) {
state.status = ""
state.name = "untitled"
state.groups = [{id:UngroupedId, name:""}]
state.cards = []
state.labelDefs = []
state.categoryDefs = []
state.props = {bgUrl:""}
export const boardGrammar = {
initialState() {
const state = {
status: "",
name: "untitled",
groups: [{id:UngroupedId, name:""}],
cards: [],
labelDefs: [],
categoryDefs: [],
props: {bgUrl:""},
}
_initGrouping(state)
return state
},
applyDelta(
delta: BoardDelta,
Expand Down Expand Up @@ -383,24 +383,24 @@ export type BoardStateData = {
}

export class Board {
public session: SessionStore<BoardGrammar> | undefined
public session: SessionStore<BoardState,BoardEphemeralState> | undefined
public hashB64: EntryHashB64

constructor(public document: DocumentStore<BoardGrammar>, public workspace: WorkspaceStore<BoardGrammar>) {
constructor(public document: DocumentStore<BoardState, BoardEphemeralState>, public workspace: WorkspaceStore<BoardState,BoardEphemeralState>) {
this.hashB64 = encodeHashToBase64(this.document.documentHash)
}

public static async Create(synStore: SynStore) {
const {documentHash, firstCommitHash} = await synStore.createDocument(boardGrammar)
const initState = boardGrammar.initialState()
console.log("creating", initState)
const documentStore = await synStore.createDocument(initState,{})

const documentStore = new DocumentStore(synStore, boardGrammar, documentHash)
await synStore.client.tagDocument(documentHash, BoardType.active)
await synStore.client.tagDocument(documentStore.documentHash, BoardType.active)

const workspaceHash = await documentStore.createWorkspace(
const workspaceStore = await documentStore.createWorkspace(
`${new Date}`,
firstCommitHash
undefined
);
const workspaceStore = new WorkspaceStore(documentStore, workspaceHash)

const me = new Board(documentStore, workspaceStore);
await me.join()
Expand Down Expand Up @@ -443,7 +443,11 @@ export class Board {

requestChanges(deltas: Array<BoardDelta>) {
console.log("REQUESTING BOARD CHANGES: ", deltas)
this.session.requestChanges(deltas)
this.session.change((state,_eph)=>{
for (const delta of deltas) {
boardGrammar.applyDelta(delta, state,_eph, undefined)
}
})
}

sessionParticipants() {
Expand Down
11 changes: 4 additions & 7 deletions ui/src/boardList.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Board } from "./board";
import { LazyHoloHashMap } from "@holochain-open-dev/utils";
import { derived, get, writable, type Readable, type Writable } from "svelte/store";
import { boardGrammar, type BoardDelta, type BoardGrammar, type BoardState } from "./board";
import { type AgentPubKey, type EntryHash, type EntryHashB64, encodeHashToBase64 } from "@holochain/client";
import {toPromise, type AsyncReadable, pipe, joinAsync, asyncDerived, sliceAndJoin, alwaysSubscribed} from '@holochain-open-dev/stores'
import { DocumentStore, SynStore, WorkspaceStore } from "@holochain-syn/core";
import { SynStore, WorkspaceStore } from "@holochain-syn/core";
import type { ProfilesStore } from "@holochain-open-dev/profiles";
import { cloneDeep } from "lodash";
import { Board, type BoardDelta, type BoardState } from "./board";

export enum BoardType {
active = "active",
Expand All @@ -33,11 +32,9 @@ export class BoardList {
activeBoardHash: Writable<EntryHash| undefined> = writable(undefined)
activeBoardHashB64: Readable<string| undefined> = derived(this.activeBoardHash, s=> s ? encodeHashToBase64(s): undefined)
boardCount: AsyncReadable<number>
documents: LazyHoloHashMap<EntryHash, DocumentStore<BoardGrammar>> = new LazyHoloHashMap( documentHash =>
new DocumentStore(this.synStore, boardGrammar, documentHash))

boardData2 = new LazyHoloHashMap( documentHash => {
const docStore = this.documents.get(documentHash)
const docStore = this.synStore.documents.get(documentHash)

const board = pipe(docStore.allWorkspaces,
workspaces =>
Expand All @@ -51,7 +48,7 @@ export class BoardList {

agentBoardHashes: LazyHoloHashMap<AgentPubKey, AsyncReadable<Array<BoardAndLatestState>>> = new LazyHoloHashMap(agent =>
pipe(this.activeBoardHashes,
documentHashes => joinAsync(documentHashes.map(documentHash=>this.documents.get(documentHash).allAuthors)),
documentHashes => joinAsync(documentHashes.map(documentHash=>this.synStore.documents.get(documentHash).allAuthors)),
(documentsAuthors, documentHashes) => {
const agentBoardHashes: AsyncReadable<BoardAndLatestState>[] = []
const b64 = encodeHashToBase64(agent)
Expand Down

0 comments on commit a375088

Please sign in to comment.