clockworklabs / clockworklabs/SpacetimeDB

VueJS view return type as `t.option` still returns an array

Open
#5,060 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
25.2k
Forks
1.1k
Avg merge
2d 7h
Merged PRs (30d)
46

Description

Given the following spacetimedb definition:

const user = table(
    { public: false },
    {
        id: t.uuid().primaryKey(),
        identity: t.identity().unique(),
        name: t.string(),
    }
)
const spacetimedb = schema({ user });

export const userGet = spacetimedb.view(
    {name: 'me', public: true},
    t.option(user.rowType), // We are not returning an array
    (ctx) => {
        return ctx.db.user.identity.find(ctx.sender) ?? undefined;
    }
)

The VueJS code has to be written as:

const [userData] = useTable(tables.userGet);
const user = computed(() => userData?.value[0] ?? undefined); // We have to "unwrap" the first array item besides this not being defined as an array

(Note that this is maybe a more general typescript issue)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the TypeScript example with the VueJS useTable(tables.userGet) call and inspect how the t.option view result is typed and exposed. Trace the relevant useTable typing or entry point; done means an optional single view value is available without indexing the first array element.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.