Skip to content

Commit

Permalink
Refactored grammar out
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Dec 19, 2023
1 parent b7eaa66 commit cb0391d
Show file tree
Hide file tree
Showing 35 changed files with 629 additions and 865 deletions.
23 changes: 8 additions & 15 deletions demo/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -100,30 +100,23 @@
async function initSyn(client) {
const store = new SynStore(new SynClient(client, 'syn-test'));
const documentsHashes= Array.from((await toPromise(store.documentsByTag.get("active"))).keys());
const documentsHashes = Array.from((await toPromise(store.documentsByTag.get("active"))).keys());
if (documentsHashes.length === 0) {
const {documentHash, firstCommitHash} = await store.createDocument(DocumentGrammar);
documentStore = new DocumentStore(store, DocumentGrammar, documentHash)
documentStore = await store.createDocument(DocumentGrammar.initialState());
const workspaceHash = await documentStore.createWorkspace(
'main',
firstCommitHash
);
await store.client.tagDocument(documentHash, 'active')
await store.client.tagDocument(documentStore.documentHash, 'active')
workspaceStore = new WorkspaceStore(documentStore, workspaceHash);
workspaceStore = await documentStore.createWorkspace(
'main'
);
sessionStore = await workspaceStore.joinSession();
synStore = store;
} else {
documentStore = new DocumentStore(
store,
DocumentGrammar,
documentsHashes[0]
);
documentStore = await toPromise(store.documents.get(documentsHashes[0]));
const workspaces = await toPromise(documentStore.allWorkspaces);
workspaceStore = new WorkspaceStore(documentStore, Array.from(workspaces.keys())[0]);
workspaceStore = await toPromise(Array.from(workspaces.values())[0]);
sessionStore = await workspaceStore.joinSession();
synStore = store;
}
Expand Down
25 changes: 5 additions & 20 deletions demo/src/syn.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,17 @@ import { extractSlice } from '@holochain-syn/core';
import { textEditorGrammar } from '@holochain-syn/text-editor';

export const DocumentGrammar = {
initState(state) {
state.title = '';
state.body = {};
textEditorGrammar.initState(state.body);
},
applyDelta(delta, state, eph, author) {
if (delta.type === 'SetTitle') {
state.title = delta.value;
} else {
textEditorGrammar.applyDelta(
delta.textEditorDelta,
state.body,
eph,
author
);
}
initialState() {
return {
title: '',
body: textEditorGrammar.initialState(),
};
},
};

export function textSlice(sessionStore) {
return extractSlice(
sessionStore,
change => ({
type: 'TextEditorDelta',
textEditorDelta: change,
}),
state => state.body,
eph => eph
);
Expand Down
3 changes: 3 additions & 0 deletions demo/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';

export default defineConfig({
optimizeDeps: {
disabled: true,
},
plugins: [svelte()],
});
25 changes: 5 additions & 20 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 packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class SynClient extends ZomeClient<SynSignal> {
/** Workspaces */
public async createWorkspace(
workspace: Workspace,
initial_commit_hash: EntryHash
initial_commit_hash: EntryHash | undefined
): Promise<EntryRecord<Workspace>> {
const record: Record = await this.callZome('create_workspace', {
workspace,
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ActionCommittedSignal } from '@holochain-open-dev/utils';
import { AgentPubKey, AnyDhtHash, EntryHash } from '@holochain/client';

export interface Document {
initial_state: Uint8Array;
meta: Uint8Array | undefined;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/contexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import type {

export const synContext = createContext<SynStore>('syn-context');

export const synDocumentContext = createContext<DocumentStore<any>>(
export const synDocumentContext = createContext<DocumentStore<any, any>>(
'syn-document-context'
);

export const synWorkspaceContext = createContext<WorkspaceStore<any>>(
export const synWorkspaceContext = createContext<WorkspaceStore<any, any>>(
'syn-workspace-context'
);

export const synSessionContext = createContext<SessionStore<any>>(
export const synSessionContext = createContext<SessionStore<any, any>>(
'syn-session-context'
);
2 changes: 1 addition & 1 deletion packages/core/src/elements/commit-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { synDocumentContext } from '../contexts.js';
export class CommitHistory extends LitElement {
@consume({ context: synDocumentContext, subscribe: true })
@property()
documentstore!: DocumentStore<any>;
documentstore!: DocumentStore<any, any>;

@property()
selectedCommitHash: EntryHashB64 | undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/elements/session-participants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { synSessionContext } from '../contexts.js';
export class SessionParticipants extends LitElement {
@consume({ context: synSessionContext, subscribe: true })
@property()
sessionstore!: SessionStore<any>;
sessionstore!: SessionStore<any, any>;

@property()
direction: 'column' | 'row' = 'column';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/elements/syn-document-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { synDocumentContext } from '../contexts.js';
export class SynDocumentContext extends LitElement {
@provide({ context: synDocumentContext })
@property()
documentstore!: DocumentStore<any>;
documentstore!: DocumentStore<any, any>;

render() {
return html`<slot></slot>`;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/elements/syn-session-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { synSessionContext } from '../contexts.js';
export class SynSessionContext extends LitElement {
@provide({ context: synSessionContext })
@property()
sessionstore!: SessionStore<any>;
sessionstore!: SessionStore<any, any>;

render() {
return html`<slot></slot>`;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/elements/syn-workspace-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { synWorkspaceContext } from '../contexts.js';
export class SynWorkspaceContext extends LitElement {
@provide({ context: synWorkspaceContext })
@property()
workspacestore!: WorkspaceStore<any>;
workspacestore!: WorkspaceStore<any, any>;

render() {
return html`<slot></slot>`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { synWorkspaceContext } from '../contexts.js';
export class WorkspaceParticipants extends LitElement {
@consume({ context: synWorkspaceContext, subscribe: true })
@property()
workspacestore!: WorkspaceStore<any>;
workspacestore!: WorkspaceStore<any, any>;

@property()
direction: 'column' | 'row' = 'column';
Expand Down
Loading

0 comments on commit cb0391d

Please sign in to comment.