Skip to content

Commit

Permalink
feat: rewrite accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
luckydye committed Jan 6, 2024
1 parent e2ea4b2 commit 5dcc3bb
Show file tree
Hide file tree
Showing 17 changed files with 361 additions and 327 deletions.
2 changes: 0 additions & 2 deletions .env.example

This file was deleted.

3 changes: 3 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ bun = "latest"
task = "3.32"
protoc = "21.12"
rust = "latest"

[env]
RUST_BACKTRACE = "1"
5 changes: 3 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

version: "3"

dotenv: [".env"]

includes:
server:
dir: apps/server
Expand Down Expand Up @@ -75,6 +73,9 @@ tasks:

dev:
desc: Run desktop app with server
env:
DATABASE: "file:///tmp/tokyo.db"
TURSO_AUTH_TOKEN: ""
deps: [setup]
cmds:
- task --parallel server:dev app:dev
Expand Down
34 changes: 20 additions & 14 deletions packages/accessors/src/adapters/solid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,39 @@ import { createEffect, createSignal } from 'solid-js';
* @param params The params as a signal, that will be used to fetch and filter the data.
*/

export function useAccessor<T extends Accessor<any, any, any, any, any>>(accessorFn: () => T) {
export function useAccessor<T extends Accessor<any, any, any, any, any, any>>(accessorFn: () => T) {
const accessor = accessorFn();
const [data, setData] = createSignal<
Awaited<ReturnType<(typeof accessor)['processData']>> | undefined
Awaited<ReturnType<(typeof accessor)['compute']>> | undefined
>();
const [error, setError] = createSignal<string>();

type Query = Partial<(typeof accessor)['query']>;
type Params = Partial<(typeof accessor)['params']>;

const [pending, setPending] = createSignal<boolean>();
const [params, setParams] = createSignal<Partial<(typeof accessor)['params']>>();
const [params, setParams] = createSignal<Query>();
const [query, setQuery] = createSignal<Params>();

accessor.on('data', (data) => {
setData(data);
});
accessor.on('error', (error) => setError(error));
accessor.on('data', (data) => setData(data));
accessor.on('pending', (pending) => setPending(pending));

createEffect(() => {
if (params) {
accessor.setParams(params());
}
accessor.params = params();
});

createEffect(() => {
accessor.query = query();
});

return {
data,
error,
pending,
params(p?: ReturnType<typeof params>) {
if (p) setParams(p);
query(value?: Query) {
if (value) setQuery(value);
return query();
},
params(value?: Params) {
if (value) setParams(value);
return params();
},
};
Expand Down
Loading

0 comments on commit 5dcc3bb

Please sign in to comment.