Skip to content

Commit

Permalink
Rename T extends Schema to S extends Schema
Browse files Browse the repository at this point in the history
  • Loading branch information
steida committed Oct 27, 2023
1 parent 51ead17 commit 76d274f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
34 changes: 17 additions & 17 deletions packages/evolu-common-react/src/React.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ export interface ReactHooks<S extends Schema> {
readonly useSyncState: () => SyncState;
}

export const ReactHooks = <T extends Schema>(): Context.Tag<
ReactHooks<T>,
ReactHooks<T>
> => Context.Tag<ReactHooks<T>>("evolu/ReactHooks");
export const ReactHooks = <S extends Schema>(): Context.Tag<
ReactHooks<S>,
ReactHooks<S>
> => Context.Tag<ReactHooks<S>>("evolu/ReactHooks");

type UseQuery<S extends Schema> = {
<QueryRow extends Row>(
Expand Down Expand Up @@ -216,23 +216,23 @@ type UseMutation<S extends Schema> = () => {
readonly update: Update<S>;
};

export const ReactHooksLive = <T extends Schema>(): Layer.Layer<
Platform | Evolu<T>,
export const ReactHooksLive = <S extends Schema>(): Layer.Layer<
Platform | Evolu<S>,
never,
ReactHooks<T>
ReactHooks<S>
> =>
Layer.effect(
ReactHooks<T>(),
ReactHooks<S>(),
Effect.gen(function* (_) {
const evolu = yield* _(Evolu<T>());
const evolu = yield* _(Evolu<S>());
const platform = yield* _(Platform);
const cacheFilterMap = makeCacheFilterMap();

const useQuery: UseQuery<T> = <
const useQuery: UseQuery<S> = <
QueryRow extends Row,
FilterMapRow extends Row,
>(
queryCallback: QueryCallback<T, QueryRow>,
queryCallback: QueryCallback<S, QueryRow>,
initialFilterMap?: FilterMap<QueryRow, FilterMapRow>,
) => {
const query = useMemo(
Expand Down Expand Up @@ -275,35 +275,35 @@ export const ReactHooksLive = <T extends Schema>(): Layer.Layer<
};
};

const useMutation: UseMutation<T> = () =>
const useMutation: UseMutation<S> = () =>
useMemo(() => ({ create: evolu.create, update: evolu.update }), []);

const useEvoluError: ReactHooks<T>["useEvoluError"] = () =>
const useEvoluError: ReactHooks<S>["useEvoluError"] = () =>
useSyncExternalStore(
evolu.subscribeError,
evolu.getError,
Function.constNull,
);

const useOwner: ReactHooks<T>["useOwner"] = () =>
const useOwner: ReactHooks<S>["useOwner"] = () =>
useSyncExternalStore(
evolu.subscribeOwner,
evolu.getOwner,
Function.constNull,
);

const useOwnerActions: ReactHooks<T>["useOwnerActions"] = () =>
const useOwnerActions: ReactHooks<S>["useOwnerActions"] = () =>
evolu.ownerActions;

const syncStateInitial: SyncState = { _tag: "SyncStateInitial" };
const useSyncState: ReactHooks<T>["useSyncState"] = () =>
const useSyncState: ReactHooks<S>["useSyncState"] = () =>
useSyncExternalStore(
evolu.subscribeSyncState,
evolu.getSyncState,
() => syncStateInitial,
);

return ReactHooks<T>().of({
return ReactHooks<S>().of({
useQuery,
useMutation,
useEvoluError,
Expand Down
2 changes: 1 addition & 1 deletion packages/evolu-common/src/Db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const kysely: Kysely.Kysely<QuerySchema<Schema>> = new Kysely.Kysely({
});

export const makeCreateQuery =
<T extends Schema>(): CreateQuery<T> =>
<S extends Schema>(): CreateQuery<S> =>
(queryCallback) =>
queryObjectToQuery(queryCallback(kysely as never).compile() as QueryObject);

Expand Down
44 changes: 22 additions & 22 deletions packages/evolu-common/src/Evolu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export interface Evolu<S extends Schema> {
readonly ensureSchema: (tables: Tables) => void;
}

export const Evolu = <T extends Schema>(): Context.Tag<Evolu<T>, Evolu<T>> =>
Context.Tag<Evolu<T>>("evolu/Evolu");
export const Evolu = <S extends Schema>(): Context.Tag<Evolu<S>, Evolu<S>> =>
Context.Tag<Evolu<S>>("evolu/Evolu");

type ErrorStore = Store<EvoluError | null>;

Expand Down Expand Up @@ -118,8 +118,8 @@ type Mutate<S extends Schema> = <
readonly id: U[T]["id"];
};

const Mutate = <T extends Schema>(): Context.Tag<Mutate<T>, Mutate<T>> =>
Context.Tag<Mutate<T>>("evolu/Mutate");
const Mutate = <S extends Schema>(): Context.Tag<Mutate<S>, Mutate<S>> =>
Context.Tag<Mutate<S>>("evolu/Mutate");

type SchemaForMutate<S extends Schema> = {
readonly [Table in keyof S]: NullableExceptOfId<
Expand Down Expand Up @@ -297,13 +297,13 @@ const QueryStoreLive = Layer.effect(
}),
);

const MutateLive = <T extends Schema>(): Layer.Layer<
const MutateLive = <S extends Schema>(): Layer.Layer<
NanoId | OnCompletes | Time | SubscribedQueries | LoadingPromises | DbWorker,
never,
Mutate<T>
Mutate<S>
> =>
Layer.effect(
Mutate<T>(),
Mutate<S>(),
Effect.gen(function* (_) {
const nanoid = yield* _(NanoId);
const onCompletes = yield* _(OnCompletes);
Expand All @@ -314,7 +314,7 @@ const MutateLive = <T extends Schema>(): Layer.Layer<

const queue: Array<MutateItem> = [];

return Mutate<T>().of((table, { id, ...values }, onComplete) => {
return Mutate<S>().of((table, { id, ...values }, onComplete) => {
const isInsert = id == null;
if (isInsert) id = Effect.runSync(nanoid.nanoid) as never;

Expand Down Expand Up @@ -381,15 +381,15 @@ const OwnerActionsLive = Layer.effect(
}),
);

export const EvoluLive = <T extends Schema>(
export const EvoluLive = <S extends Schema>(
tables: Tables,
): Layer.Layer<
DbWorker | Bip39 | Config | FlushSync | NanoId | Time | AppState,
never,
Evolu<T>
Evolu<S>
> =>
Layer.effect(
Evolu<T>(),
Evolu<S>(),
Effect.gen(function* (_) {
const dbWorker = yield* _(DbWorker);
const appState = yield* _(AppState);
Expand Down Expand Up @@ -425,16 +425,16 @@ export const EvoluLive = <T extends Schema>(
).pipe(Effect.runSync);

const mutate = Effect.provide(
Mutate<T>(),
Layer.use(MutateLive<T>(), Layers),
Mutate<S>(),
Layer.use(MutateLive<S>(), Layers),
).pipe(Effect.runSync);

const ownerActions = Effect.provide(
OwnerActions,
Layer.use(OwnerActionsLive, Layers),
).pipe(Effect.runSync);

const ensureSchema: Evolu<T>["ensureSchema"] = (tables) => {
const ensureSchema: Evolu<S>["ensureSchema"] = (tables) => {
dbWorker.postMessage({ _tag: "ensureSchema", tables });
};

Expand Down Expand Up @@ -486,42 +486,42 @@ export const EvoluLive = <T extends Schema>(
appState.onReconnect(sync);
sync();

return Evolu<T>().of({
return Evolu<S>().of({
subscribeError: errorStore.subscribe,
getError: errorStore.getState,

subscribeOwner: ownerStore.subscribe,
getOwner: ownerStore.getState,

createQuery: makeCreateQuery<T>(),
createQuery: makeCreateQuery<S>(),
subscribeQuery: queryStore.subscribe,
getQuery: queryStore.getState,
loadQuery: queryStore.loadQuery,

subscribeSyncState: syncStateStore.subscribe,
getSyncState: syncStateStore.getState,

create: mutate as Create<T>,
update: mutate as Update<T>,
create: mutate as Create<S>,
update: mutate as Update<S>,
ownerActions,
ensureSchema,
});
}),
);

export const makeEvoluForPlatform = <T extends Schema>(
export const makeEvoluForPlatform = <S extends Schema>(
PlatformLayer: Layer.Layer<
never,
never,
DbWorker | Bip39 | NanoId | FlushSync | AppState
>,
tables: Tables,
config?: Partial<Config>,
): Evolu<T> =>
): Evolu<S> =>
Effect.provide(
Evolu<T>(),
Evolu<S>(),
Layer.use(
EvoluLive<T>(tables),
EvoluLive<S>(tables),
Layer.mergeAll(PlatformLayer, ConfigLive(config), TimeLive),
),
).pipe(Effect.runSync);

1 comment on commit 76d274f

@vercel
Copy link

@vercel vercel bot commented on 76d274f Oct 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

evolu – ./

evolu.vercel.app
evolu-evolu.vercel.app
evolu-git-main-evolu.vercel.app
www.evolu.dev
evolu.dev

Please sign in to comment.