clockworklabs / clockworklabs/SpacetimeDB
VueJS view return type as `t.option` still returns an array
Open
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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