Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@ jobs:
- name: 🧪 Test project
run: pnpm test:unit -- --coverage

- name: 🧪 Test fixtures
run: pnpm test:e2e

- name: 🟩 Coverage
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"vue": "^3.5.13"
},
"dependencies": {
"@rocicorp/zero": "^1.4.0"
"@rocicorp/zero": "^1.7.0"
},
"devDependencies": {
"@antfu/eslint-config": "latest",
Expand Down
2,142 changes: 1,249 additions & 893 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,8 @@ describe('vueViewFactory', () => {
})

expect(view).toBeDefined()
expect(onTransactionCommit).not.toHaveBeenCalled()
expect(onTransactionCommit).toHaveBeenCalledTimes(1)
expect(onTransactionCommit).toHaveBeenCalledWith(expect.any(Function))
expect(onDestroy).not.toHaveBeenCalled()
view.destroy()
expect(onDestroy).toHaveBeenCalledTimes(1)
Expand Down
23 changes: 16 additions & 7 deletions src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import type {
TTL,
} from '@rocicorp/zero'
import type { ViewChange } from '@rocicorp/zero/bindings'
import type { Ref } from 'vue'
import type { Ref, ShallowRef } from 'vue'
import { applyChange, skipYields } from '@rocicorp/zero/bindings'
import { ref } from 'vue'
import { ref, shallowRef } from 'vue'

export type QueryStatus = QueryResultDetails['type']
export type QueryError = QueryErrorDetails['error']
Expand All @@ -30,10 +30,11 @@ export class VueView implements Output {
readonly #onDestroy: () => void
readonly #updateTTL: (ttl: TTL) => void

#data: Ref<Entry>
#data: ShallowRef<Entry>
#status: Ref<QueryStatus>
#error: Ref<QueryError | undefined>
#isDestroyed = false
#txnDirty = new WeakSet<object>()

constructor(
input: Input,
Expand All @@ -47,16 +48,18 @@ export class VueView implements Output {
this.#format = format
this.#onDestroy = onDestroy
this.#updateTTL = updateTTL
this.#data = ref({ '': format.singular ? undefined : [] })
this.#data = shallowRef({ '': format.singular ? undefined : [] })
this.#status = ref(queryComplete === true ? 'complete' : 'error' in queryComplete ? 'error' : 'unknown')
this.#error = ref(queryComplete !== true && 'error' in queryComplete ? makeError(queryComplete) : undefined) as Ref<QueryError | undefined>

input.setOutput(this)

for (const node of skipYields(input.fetch({}))) {
this.#applyChange({ type: 'add', node })
this.#applyChange({ type: 'add', node }, true)
}

onTransactionCommit(() => this.flush())

if (queryComplete !== true && !('error' in queryComplete)) {
void queryComplete.then(() => {
this.#status.value = 'complete'
Expand Down Expand Up @@ -87,13 +90,15 @@ export class VueView implements Output {
}
}

#applyChange(change: ViewChange): void {
applyChange(
#applyChange(change: ViewChange, mutate: boolean | WeakSet<object> = this.#txnDirty): void {
this.#data.value = applyChange(
this.#data.value,
change,
this.#input.getSchema(),
'',
this.#format,
false,
mutate,
)
}

Expand All @@ -105,6 +110,10 @@ export class VueView implements Output {
updateTTL(ttl: TTL): void {
this.#updateTTL(ttl)
}

flush(): void {
this.#txnDirty = new WeakSet<object>()
}
}

function materializeRelationships(change: Change): ViewChange {
Expand Down
3 changes: 2 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vitest/config'
import { configDefaults, defineConfig } from 'vitest/config'

export default defineConfig({
resolve: {
Expand All @@ -14,5 +14,6 @@ export default defineConfig({
include: ['src'],
reporter: ['text', 'json', 'html'],
},
exclude: [...configDefaults.exclude, 'test/fixtures/**'],
},
})