@instantdb/react
Advanced tools
Comparing version 0.16.6 to 0.17.0-experimental.0
import { type ReactNode } from "react"; | ||
import type { InstantReactRoom } from "./InstantReact"; | ||
import type { InstantReactRoom } from "./InstantReactAbstractDatabase"; | ||
import type { RoomSchemaShape } from "@instantdb/core"; | ||
@@ -4,0 +4,0 @@ export declare function Cursors<RoomSchema extends RoomSchemaShape, RoomType extends keyof RoomSchema>({ as, spaceId: _spaceId, room, className, style, userCursorColor, children, renderCursor, propagate, zIndex, }: { |
import { id, tx, lookup, i, type QueryResponse, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantObject, type InstantEntity, type InstantSchemaDatabase, type IInstantDatabase, type User, type AuthState, type Query, type Config, type InstaQLParams, type ConnectionStatus, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type ValueTypes, type InstaQLEntity, type InstaQLResult, type InstantUnknownSchema, type InstantSchemaDef, type BackwardsCompatibleSchema, type InstantRules } from "@instantdb/core"; | ||
import { InstantReact } from "./InstantReact"; | ||
import InstantReactAbstractDatabase from "./InstantReactAbstractDatabase"; | ||
import { InstantReactWeb } from "./InstantReactWeb"; | ||
import InstantReactWebDatabase from "./InstantReactWebDatabase"; | ||
import { init, init_experimental } from "./init"; | ||
import { Cursors } from "./Cursors"; | ||
export { id, tx, lookup, init, init_experimental, InstantReactWeb, InstantReactWebDatabase, Cursors, i, InstantReact, InstantReactAbstractDatabase, type Config, type Query, type QueryResponse, type InstantObject, type User, type AuthState, type ConnectionStatus, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantEntity, type InstantSchemaDatabase, type IInstantDatabase, type InstaQLParams, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type ValueTypes, type InstaQLEntity, type InstaQLResult, type InstantUnknownSchema, type InstantSchemaDef, type BackwardsCompatibleSchema, type InstantRules, }; | ||
export { id, tx, lookup, init, init_experimental, InstantReactWebDatabase, Cursors, i, InstantReactAbstractDatabase, type Config, type Query, type QueryResponse, type InstantObject, type User, type AuthState, type ConnectionStatus, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantEntity, type InstantSchemaDatabase, type IInstantDatabase, type InstaQLParams, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type ValueTypes, type InstaQLEntity, type InstaQLResult, type InstantUnknownSchema, type InstantSchemaDef, type BackwardsCompatibleSchema, type InstantRules, }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.InstantReactAbstractDatabase = exports.InstantReact = exports.i = exports.Cursors = exports.InstantReactWebDatabase = exports.InstantReactWeb = exports.init_experimental = exports.init = exports.lookup = exports.tx = exports.id = void 0; | ||
exports.InstantReactAbstractDatabase = exports.i = exports.Cursors = exports.InstantReactWebDatabase = exports.init_experimental = exports.init = exports.lookup = exports.tx = exports.id = void 0; | ||
const core_1 = require("@instantdb/core"); | ||
@@ -13,8 +13,4 @@ Object.defineProperty(exports, "id", { enumerable: true, get: function () { return core_1.id; } }); | ||
Object.defineProperty(exports, "i", { enumerable: true, get: function () { return core_1.i; } }); | ||
const InstantReact_1 = require("./InstantReact"); | ||
Object.defineProperty(exports, "InstantReact", { enumerable: true, get: function () { return InstantReact_1.InstantReact; } }); | ||
const InstantReactAbstractDatabase_1 = __importDefault(require("./InstantReactAbstractDatabase")); | ||
exports.InstantReactAbstractDatabase = InstantReactAbstractDatabase_1.default; | ||
const InstantReactWeb_1 = require("./InstantReactWeb"); | ||
Object.defineProperty(exports, "InstantReactWeb", { enumerable: true, get: function () { return InstantReactWeb_1.InstantReactWeb; } }); | ||
const InstantReactWebDatabase_1 = __importDefault(require("./InstantReactWebDatabase")); | ||
@@ -21,0 +17,0 @@ exports.InstantReactWebDatabase = InstantReactWebDatabase_1.default; |
@@ -1,3 +0,2 @@ | ||
import type { Config, InstantConfig, InstantSchemaDef, RoomSchemaShape, InstantUnknownSchema } from "@instantdb/core"; | ||
import { InstantReactWeb } from "./InstantReactWeb"; | ||
import type { InstantConfig, InstantSchemaDef, InstantUnknownSchema } from "@instantdb/core"; | ||
import InstantReactWebDatabase from "./InstantReactWebDatabase"; | ||
@@ -15,13 +14,11 @@ /** | ||
* | ||
* type Schema = { | ||
* goals: { | ||
* title: string | ||
* } | ||
* } | ||
* | ||
* // TODO-now | ||
* const db = init<Schema>({ appId: "my-app-id" }) | ||
* | ||
*/ | ||
export declare function init<Schema extends {} = {}, RoomSchema extends RoomSchemaShape = {}>(config: Config): InstantReactWeb<Schema, RoomSchema, false>; | ||
export declare function init_experimental<Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema>(config: InstantConfig<Schema>): InstantReactWebDatabase<Schema>; | ||
export declare function init<Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema>(config: InstantConfig<Schema>): InstantReactWebDatabase<Schema>; | ||
/** | ||
* @deprecated | ||
* // TODO-now | ||
*/ | ||
export declare const init_experimental: typeof init; | ||
//# sourceMappingURL=init.d.ts.map |
@@ -6,6 +6,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.init_experimental = void 0; | ||
exports.init = init; | ||
exports.init_experimental = init_experimental; | ||
const InstantReactWeb_1 = require("./InstantReactWeb"); | ||
const InstantReactWebDatabase_1 = __importDefault(require("./InstantReactWebDatabase")); | ||
const version_1 = __importDefault(require("./version")); | ||
/** | ||
@@ -22,17 +22,15 @@ * | ||
* | ||
* type Schema = { | ||
* goals: { | ||
* title: string | ||
* } | ||
* } | ||
* | ||
* // TODO-now | ||
* const db = init<Schema>({ appId: "my-app-id" }) | ||
* | ||
*/ | ||
function init(config) { | ||
return new InstantReactWeb_1.InstantReactWeb(config); | ||
return new InstantReactWebDatabase_1.default(config, { | ||
"@instantdb/react": version_1.default, | ||
}); | ||
} | ||
function init_experimental(config) { | ||
return new InstantReactWebDatabase_1.default(config); | ||
} | ||
/** | ||
* @deprecated | ||
* // TODO-now | ||
*/ | ||
exports.init_experimental = init; | ||
//# sourceMappingURL=init.js.map |
@@ -105,3 +105,5 @@ import { Auth, Storage, type AuthState, type ConnectionStatus, type TransactionChunk, type PresenceOpts, type PresenceResponse, type RoomSchemaShape, type InstaQLParams, type InstantConfig, type PageInfoResponse, InstantCoreDatabase, InstaQLLifecycleState, InstaQLResponse, RoomsOf, InstantSchemaDef, IInstantDatabase } from "@instantdb/core"; | ||
static NetworkListener?: any; | ||
constructor(config: InstantConfig<Schema>); | ||
constructor(config: InstantConfig<Schema>, versions?: { | ||
[key: string]: string; | ||
}); | ||
getLocalId: (name: string) => Promise<string>; | ||
@@ -108,0 +110,0 @@ /** |
@@ -179,3 +179,3 @@ "use strict"; | ||
class InstantReactAbstractDatabase { | ||
constructor(config) { | ||
constructor(config, versions) { | ||
this.tx = (0, core_1.txInit)(); | ||
@@ -328,7 +328,7 @@ this.getLocalId = (name) => { | ||
}; | ||
this._core = (0, core_1.init_experimental)(config, | ||
this._core = (0, core_1.init)(config, | ||
// @ts-expect-error because TS can't resolve subclass statics | ||
this.constructor.Storage, | ||
// @ts-expect-error because TS can't resolve subclass statics | ||
this.constructor.NetworkListener); | ||
this.constructor.NetworkListener, versions); | ||
this.auth = this._core.auth; | ||
@@ -335,0 +335,0 @@ this.storage = this._core.storage; |
import { type ReactNode } from "react"; | ||
import type { InstantReactRoom } from "./InstantReact"; | ||
import type { InstantReactRoom } from "./InstantReactAbstractDatabase"; | ||
import type { RoomSchemaShape } from "@instantdb/core"; | ||
@@ -4,0 +4,0 @@ export declare function Cursors<RoomSchema extends RoomSchemaShape, RoomType extends keyof RoomSchema>({ as, spaceId: _spaceId, room, className, style, userCursorColor, children, renderCursor, propagate, zIndex, }: { |
import { id, tx, lookup, i, type QueryResponse, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantObject, type InstantEntity, type InstantSchemaDatabase, type IInstantDatabase, type User, type AuthState, type Query, type Config, type InstaQLParams, type ConnectionStatus, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type ValueTypes, type InstaQLEntity, type InstaQLResult, type InstantUnknownSchema, type InstantSchemaDef, type BackwardsCompatibleSchema, type InstantRules } from "@instantdb/core"; | ||
import { InstantReact } from "./InstantReact"; | ||
import InstantReactAbstractDatabase from "./InstantReactAbstractDatabase"; | ||
import { InstantReactWeb } from "./InstantReactWeb"; | ||
import InstantReactWebDatabase from "./InstantReactWebDatabase"; | ||
import { init, init_experimental } from "./init"; | ||
import { Cursors } from "./Cursors"; | ||
export { id, tx, lookup, init, init_experimental, InstantReactWeb, InstantReactWebDatabase, Cursors, i, InstantReact, InstantReactAbstractDatabase, type Config, type Query, type QueryResponse, type InstantObject, type User, type AuthState, type ConnectionStatus, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantEntity, type InstantSchemaDatabase, type IInstantDatabase, type InstaQLParams, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type ValueTypes, type InstaQLEntity, type InstaQLResult, type InstantUnknownSchema, type InstantSchemaDef, type BackwardsCompatibleSchema, type InstantRules, }; | ||
export { id, tx, lookup, init, init_experimental, InstantReactWebDatabase, Cursors, i, InstantReactAbstractDatabase, type Config, type Query, type QueryResponse, type InstantObject, type User, type AuthState, type ConnectionStatus, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantEntity, type InstantSchemaDatabase, type IInstantDatabase, type InstaQLParams, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type ValueTypes, type InstaQLEntity, type InstaQLResult, type InstantUnknownSchema, type InstantSchemaDef, type BackwardsCompatibleSchema, type InstantRules, }; | ||
//# sourceMappingURL=index.d.ts.map |
import { id, tx, lookup, i, } from "@instantdb/core"; | ||
import { InstantReact } from "./InstantReact"; | ||
import InstantReactAbstractDatabase from "./InstantReactAbstractDatabase"; | ||
import { InstantReactWeb } from "./InstantReactWeb"; | ||
import InstantReactWebDatabase from "./InstantReactWebDatabase"; | ||
import { init, init_experimental } from "./init"; | ||
import { Cursors } from "./Cursors"; | ||
export { id, tx, lookup, init, init_experimental, InstantReactWeb, InstantReactWebDatabase, Cursors, i, | ||
export { id, tx, lookup, init, init_experimental, InstantReactWebDatabase, Cursors, i, | ||
// internal | ||
InstantReact, InstantReactAbstractDatabase, }; | ||
InstantReactAbstractDatabase, }; | ||
//# sourceMappingURL=index.js.map |
@@ -1,3 +0,2 @@ | ||
import type { Config, InstantConfig, InstantSchemaDef, RoomSchemaShape, InstantUnknownSchema } from "@instantdb/core"; | ||
import { InstantReactWeb } from "./InstantReactWeb"; | ||
import type { InstantConfig, InstantSchemaDef, InstantUnknownSchema } from "@instantdb/core"; | ||
import InstantReactWebDatabase from "./InstantReactWebDatabase"; | ||
@@ -15,13 +14,11 @@ /** | ||
* | ||
* type Schema = { | ||
* goals: { | ||
* title: string | ||
* } | ||
* } | ||
* | ||
* // TODO-now | ||
* const db = init<Schema>({ appId: "my-app-id" }) | ||
* | ||
*/ | ||
export declare function init<Schema extends {} = {}, RoomSchema extends RoomSchemaShape = {}>(config: Config): InstantReactWeb<Schema, RoomSchema, false>; | ||
export declare function init_experimental<Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema>(config: InstantConfig<Schema>): InstantReactWebDatabase<Schema>; | ||
export declare function init<Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema>(config: InstantConfig<Schema>): InstantReactWebDatabase<Schema>; | ||
/** | ||
* @deprecated | ||
* // TODO-now | ||
*/ | ||
export declare const init_experimental: typeof init; | ||
//# sourceMappingURL=init.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import { InstantReactWeb } from "./InstantReactWeb"; | ||
import InstantReactWebDatabase from "./InstantReactWebDatabase"; | ||
import version from "./version"; | ||
/** | ||
@@ -14,17 +14,15 @@ * | ||
* | ||
* type Schema = { | ||
* goals: { | ||
* title: string | ||
* } | ||
* } | ||
* | ||
* // TODO-now | ||
* const db = init<Schema>({ appId: "my-app-id" }) | ||
* | ||
*/ | ||
export function init(config) { | ||
return new InstantReactWeb(config); | ||
return new InstantReactWebDatabase(config, { | ||
"@instantdb/react": version, | ||
}); | ||
} | ||
export function init_experimental(config) { | ||
return new InstantReactWebDatabase(config); | ||
} | ||
/** | ||
* @deprecated | ||
* // TODO-now | ||
*/ | ||
export const init_experimental = init; | ||
//# sourceMappingURL=init.js.map |
@@ -105,3 +105,5 @@ import { Auth, Storage, type AuthState, type ConnectionStatus, type TransactionChunk, type PresenceOpts, type PresenceResponse, type RoomSchemaShape, type InstaQLParams, type InstantConfig, type PageInfoResponse, InstantCoreDatabase, InstaQLLifecycleState, InstaQLResponse, RoomsOf, InstantSchemaDef, IInstantDatabase } from "@instantdb/core"; | ||
static NetworkListener?: any; | ||
constructor(config: InstantConfig<Schema>); | ||
constructor(config: InstantConfig<Schema>, versions?: { | ||
[key: string]: string; | ||
}); | ||
getLocalId: (name: string) => Promise<string>; | ||
@@ -108,0 +110,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import { txInit, init_experimental, } from "@instantdb/core"; | ||
import { txInit, init as core_init, } from "@instantdb/core"; | ||
import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore, } from "react"; | ||
@@ -175,3 +175,3 @@ import { useQueryInternal } from "./useQuery"; | ||
export default class InstantReactAbstractDatabase { | ||
constructor(config) { | ||
constructor(config, versions) { | ||
this.tx = txInit(); | ||
@@ -324,7 +324,7 @@ this.getLocalId = (name) => { | ||
}; | ||
this._core = init_experimental(config, | ||
this._core = core_init(config, | ||
// @ts-expect-error because TS can't resolve subclass statics | ||
this.constructor.Storage, | ||
// @ts-expect-error because TS can't resolve subclass statics | ||
this.constructor.NetworkListener); | ||
this.constructor.NetworkListener, versions); | ||
this.auth = this._core.auth; | ||
@@ -331,0 +331,0 @@ this.storage = this._core.storage; |
@@ -1,6 +0,2 @@ | ||
import { type Query, type Exactly, type InstantClient, type LifecycleSubscriptionState, type InstaQLParams, type InstantGraph, InstantCoreDatabase, InstaQLLifecycleState, InstantSchemaDef } from "@instantdb/core"; | ||
export declare function useQuery<Q extends Schema extends InstantGraph<any, any> ? InstaQLParams<Schema> : Exactly<Query, Q>, Schema extends InstantGraph<any, any, any> | {}, WithCardinalityInference extends boolean>(_core: InstantClient<Schema, any, WithCardinalityInference>, _query: null | Q): { | ||
state: LifecycleSubscriptionState<Q, Schema, WithCardinalityInference>; | ||
query: any; | ||
}; | ||
import { type InstaQLParams, InstantCoreDatabase, InstaQLLifecycleState, InstantSchemaDef } from "@instantdb/core"; | ||
export declare function useQueryInternal<Q extends InstaQLParams<Schema>, Schema extends InstantSchemaDef<any, any, any>>(_core: InstantCoreDatabase<Schema>, _query: null | Q): { | ||
@@ -7,0 +3,0 @@ state: InstaQLLifecycleState<Schema, Q>; |
@@ -12,30 +12,2 @@ import { weakHash, coerceQuery, } from "@instantdb/core"; | ||
} | ||
export function useQuery(_core, _query) { | ||
const query = _query ? coerceQuery(_query) : null; | ||
const queryHash = weakHash(query); | ||
// We use a ref to store the result of the query. | ||
// This is becuase `useSyncExternalStore` uses `Object.is` | ||
// to compare the previous and next state. | ||
// If we don't use a ref, the state will always be considered different, so | ||
// the component will always re-render. | ||
const resultCacheRef = useRef(stateForResult(_core._reactor.getPreviousResult(query))); | ||
// Similar to `resultCacheRef`, `useSyncExternalStore` will unsubscribe | ||
// if `subscribe` changes, so we use `useCallback` to memoize the function. | ||
const subscribe = useCallback((cb) => { | ||
// Don't subscribe if query is null | ||
if (!query) { | ||
const unsubscribe = () => { }; | ||
return unsubscribe; | ||
} | ||
const unsubscribe = _core.subscribeQuery(query, (result) => { | ||
resultCacheRef.current = Object.assign({ isLoading: !Boolean(result), data: undefined, pageInfo: undefined, error: undefined }, result); | ||
cb(); | ||
}); | ||
return unsubscribe; | ||
}, | ||
// Build a new subscribe function if the query changes | ||
[queryHash, _core]); | ||
const state = useSyncExternalStore(subscribe, () => resultCacheRef.current, () => defaultState); | ||
return { state, query }; | ||
} | ||
export function useQueryInternal(_core, _query) { | ||
@@ -42,0 +14,0 @@ const query = _query ? coerceQuery(_query) : null; |
export default version; | ||
declare const version: "v0.16.6"; | ||
declare const version: "v0.17.0-experimental.0"; | ||
//# sourceMappingURL=version.d.ts.map |
// Autogenerated by publish_packages.clj | ||
const version = "v0.16.6"; | ||
const version = "v0.17.0-experimental.0"; | ||
export default version; | ||
//# sourceMappingURL=version.js.map |
@@ -1,6 +0,2 @@ | ||
import { type Query, type Exactly, type InstantClient, type LifecycleSubscriptionState, type InstaQLParams, type InstantGraph, InstantCoreDatabase, InstaQLLifecycleState, InstantSchemaDef } from "@instantdb/core"; | ||
export declare function useQuery<Q extends Schema extends InstantGraph<any, any> ? InstaQLParams<Schema> : Exactly<Query, Q>, Schema extends InstantGraph<any, any, any> | {}, WithCardinalityInference extends boolean>(_core: InstantClient<Schema, any, WithCardinalityInference>, _query: null | Q): { | ||
state: LifecycleSubscriptionState<Q, Schema, WithCardinalityInference>; | ||
query: any; | ||
}; | ||
import { type InstaQLParams, InstantCoreDatabase, InstaQLLifecycleState, InstantSchemaDef } from "@instantdb/core"; | ||
export declare function useQueryInternal<Q extends InstaQLParams<Schema>, Schema extends InstantSchemaDef<any, any, any>>(_core: InstantCoreDatabase<Schema>, _query: null | Q): { | ||
@@ -7,0 +3,0 @@ state: InstaQLLifecycleState<Schema, Q>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.useQuery = useQuery; | ||
exports.useQueryInternal = useQueryInternal; | ||
@@ -16,30 +15,2 @@ const core_1 = require("@instantdb/core"); | ||
} | ||
function useQuery(_core, _query) { | ||
const query = _query ? (0, core_1.coerceQuery)(_query) : null; | ||
const queryHash = (0, core_1.weakHash)(query); | ||
// We use a ref to store the result of the query. | ||
// This is becuase `useSyncExternalStore` uses `Object.is` | ||
// to compare the previous and next state. | ||
// If we don't use a ref, the state will always be considered different, so | ||
// the component will always re-render. | ||
const resultCacheRef = (0, react_1.useRef)(stateForResult(_core._reactor.getPreviousResult(query))); | ||
// Similar to `resultCacheRef`, `useSyncExternalStore` will unsubscribe | ||
// if `subscribe` changes, so we use `useCallback` to memoize the function. | ||
const subscribe = (0, react_1.useCallback)((cb) => { | ||
// Don't subscribe if query is null | ||
if (!query) { | ||
const unsubscribe = () => { }; | ||
return unsubscribe; | ||
} | ||
const unsubscribe = _core.subscribeQuery(query, (result) => { | ||
resultCacheRef.current = Object.assign({ isLoading: !Boolean(result), data: undefined, pageInfo: undefined, error: undefined }, result); | ||
cb(); | ||
}); | ||
return unsubscribe; | ||
}, | ||
// Build a new subscribe function if the query changes | ||
[queryHash, _core]); | ||
const state = (0, react_1.useSyncExternalStore)(subscribe, () => resultCacheRef.current, () => defaultState); | ||
return { state, query }; | ||
} | ||
function useQueryInternal(_core, _query) { | ||
@@ -46,0 +17,0 @@ const query = _query ? (0, core_1.coerceQuery)(_query) : null; |
export default version; | ||
declare const version: "v0.16.6"; | ||
declare const version: "v0.17.0-experimental.0"; | ||
//# sourceMappingURL=version.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// Autogenerated by publish_packages.clj | ||
const version = "v0.16.6"; | ||
const version = "v0.17.0-experimental.0"; | ||
exports.default = version; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@instantdb/react", | ||
"version": "v0.16.6", | ||
"version": "v0.17.0-experimental.0", | ||
"description": "Instant DB for React", | ||
@@ -35,4 +35,4 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@instantdb/core": "v0.16.6" | ||
"@instantdb/core": "v0.17.0-experimental.0" | ||
} | ||
} |
@@ -45,5 +45,3 @@ import { | ||
import { InstantReact } from "./InstantReact"; | ||
import InstantReactAbstractDatabase from "./InstantReactAbstractDatabase"; | ||
import { InstantReactWeb } from "./InstantReactWeb"; | ||
import InstantReactWebDatabase from "./InstantReactWebDatabase"; | ||
@@ -59,3 +57,2 @@ import { init, init_experimental } from "./init"; | ||
init_experimental, | ||
InstantReactWeb, | ||
InstantReactWebDatabase, | ||
@@ -66,3 +63,2 @@ Cursors, | ||
// internal | ||
InstantReact, | ||
InstantReactAbstractDatabase, | ||
@@ -69,0 +65,0 @@ |
import type { | ||
// types | ||
Config, | ||
InstantConfig, | ||
InstantGraph, | ||
InstantSchemaDef, | ||
RoomSchemaShape, | ||
InstantUnknownSchema, | ||
} from "@instantdb/core"; | ||
import { InstantReactWeb } from "./InstantReactWeb"; | ||
import InstantReactWebDatabase from "./InstantReactWebDatabase"; | ||
import version from "./version"; | ||
@@ -24,22 +21,17 @@ /** | ||
* | ||
* type Schema = { | ||
* goals: { | ||
* title: string | ||
* } | ||
* } | ||
* | ||
* // TODO-now | ||
* const db = init<Schema>({ appId: "my-app-id" }) | ||
* | ||
*/ | ||
export function init< | ||
Schema extends {} = {}, | ||
RoomSchema extends RoomSchemaShape = {}, | ||
>(config: Config) { | ||
return new InstantReactWeb<Schema, RoomSchema>(config); | ||
} | ||
export function init_experimental< | ||
Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema, | ||
>(config: InstantConfig<Schema>) { | ||
return new InstantReactWebDatabase<Schema>(config); | ||
return new InstantReactWebDatabase<Schema>(config, { | ||
"@instantdb/react": version, | ||
}); | ||
} | ||
/** | ||
* @deprecated | ||
* // TODO-now | ||
*/ | ||
export const init_experimental = init; |
@@ -6,3 +6,2 @@ import { | ||
txInit, | ||
_init_internal, | ||
type AuthState, | ||
@@ -18,3 +17,3 @@ type ConnectionStatus, | ||
InstantCoreDatabase, | ||
init_experimental, | ||
init as core_init, | ||
InstaQLLifecycleState, | ||
@@ -309,4 +308,7 @@ InstaQLResponse, | ||
constructor(config: InstantConfig<Schema>) { | ||
this._core = init_experimental<Schema>( | ||
constructor( | ||
config: InstantConfig<Schema>, | ||
versions?: { [key: string]: string } | ||
) { | ||
this._core = core_init<Schema>( | ||
config, | ||
@@ -317,2 +319,3 @@ // @ts-expect-error because TS can't resolve subclass statics | ||
this.constructor.NetworkListener, | ||
versions, | ||
); | ||
@@ -319,0 +322,0 @@ this.auth = this._core.auth; |
@@ -6,3 +6,2 @@ import { | ||
type Exactly, | ||
type InstantClient, | ||
type LifecycleSubscriptionState, | ||
@@ -34,65 +33,2 @@ type InstaQLParams, | ||
export function useQuery< | ||
Q extends Schema extends InstantGraph<any, any> | ||
? InstaQLParams<Schema> | ||
: Exactly<Query, Q>, | ||
Schema extends InstantGraph<any, any, any> | {}, | ||
WithCardinalityInference extends boolean, | ||
>( | ||
_core: InstantClient<Schema, any, WithCardinalityInference>, | ||
_query: null | Q, | ||
): { | ||
state: LifecycleSubscriptionState<Q, Schema, WithCardinalityInference>; | ||
query: any; | ||
} { | ||
const query = _query ? coerceQuery(_query) : null; | ||
const queryHash = weakHash(query); | ||
// We use a ref to store the result of the query. | ||
// This is becuase `useSyncExternalStore` uses `Object.is` | ||
// to compare the previous and next state. | ||
// If we don't use a ref, the state will always be considered different, so | ||
// the component will always re-render. | ||
const resultCacheRef = useRef< | ||
LifecycleSubscriptionState<Q, Schema, WithCardinalityInference> | ||
>(stateForResult(_core._reactor.getPreviousResult(query))); | ||
// Similar to `resultCacheRef`, `useSyncExternalStore` will unsubscribe | ||
// if `subscribe` changes, so we use `useCallback` to memoize the function. | ||
const subscribe = useCallback( | ||
(cb) => { | ||
// Don't subscribe if query is null | ||
if (!query) { | ||
const unsubscribe = () => {}; | ||
return unsubscribe; | ||
} | ||
const unsubscribe = _core.subscribeQuery<Q>(query, (result) => { | ||
resultCacheRef.current = { | ||
isLoading: !Boolean(result), | ||
data: undefined, | ||
pageInfo: undefined, | ||
error: undefined, | ||
...result, | ||
}; | ||
cb(); | ||
}); | ||
return unsubscribe; | ||
}, | ||
// Build a new subscribe function if the query changes | ||
[queryHash, _core], | ||
); | ||
const state = useSyncExternalStore< | ||
LifecycleSubscriptionState<Q, Schema, WithCardinalityInference> | ||
>( | ||
subscribe, | ||
() => resultCacheRef.current, | ||
() => defaultState, | ||
); | ||
return { state, query }; | ||
} | ||
export function useQueryInternal< | ||
@@ -99,0 +35,0 @@ Q extends InstaQLParams<Schema>, |
// Autogenerated by publish_packages.clj | ||
const version = "v0.16.6"; | ||
const version = "v0.17.0-experimental.0"; | ||
export default version; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
450621
81
7881