@@ -43,13 +43,15 @@ import { storeSetterNext, wrapNext } from "./store.js";
4343import type { StoreNextFamily } from "./target.js" ;
4444
4545export function validateStoreValue ( value : void | object ) : void {
46- if ( value === undefined ) throw new Error ( "A seedless store projection must produce a value" ) ;
47- if ( value === null || typeof value !== "object" )
48- throw new Error ( "A seedless store projection must produce an object value" ) ;
49- if ( Array . isArray ( value ) ) throw new Error ( "Array store projections require an explicit seed" ) ;
50- const prototype = Object . getPrototypeOf ( value ) ;
46+ const prototype =
47+ value != null && typeof value === "object" ? Object . getPrototypeOf ( value ) : false ;
5148 if ( prototype !== Object . prototype && prototype !== null )
52- throw new Error ( "A seedless store projection must produce a plain object value" ) ;
49+ throw new Error ( __DEV__ ? "A seedless store projection must produce a plain object value" : "" ) ;
50+ }
51+
52+ export function validateSeedlessOptions ( options ?: SeededProjectionOptions ) : void {
53+ if ( options ?. seedLoadingValue )
54+ throw new Error ( __DEV__ ? "seedLoadingValue requires an explicit store seed" : "" ) ;
5355}
5456
5557export type ProjectionResultValidator < T extends object > = (
@@ -261,8 +263,7 @@ export function createProjectionNext<T extends object = {}>(
261263 options ?: SeededProjectionOptions
262264) : Refreshable < Store < T > > {
263265 const seeded = seed != null ;
264- if ( ! seeded && options ?. seedLoadingValue )
265- throw new Error ( "seedLoadingValue requires an explicit store seed" ) ;
266+ if ( ! seeded ) validateSeedlessOptions ( options ) ;
266267 const derive = seeded ? fn : ( ) => ( fn as ( ) => T | Promise < T > | AsyncIterable < T > ) ( ) ;
267268 return createProjectionNextInternal (
268269 derive ,
@@ -278,6 +279,7 @@ export function createProjectionHydrationReplayNext<T extends object = {}>(
278279 replaying : ( ) => boolean ,
279280 options ?: ProjectionOptions
280281) : Refreshable < Store < T > > {
282+ validateSeedlessOptions ( options ) ;
281283 return createProjectionNextInternal ( fn , { } as T , options , createReplayStoreValidator ( replaying ) )
282284 . store ;
283285}
@@ -293,8 +295,7 @@ export function createStoreDerivedNext<T extends object = {}>(
293295 options ?: SeededProjectionOptions
294296) : [ Refreshable < Store < T > > , ( f : ( draft : T ) => T | void ) => void ] {
295297 const seeded = seed != null ;
296- if ( ! seeded && options ?. seedLoadingValue )
297- throw new Error ( "seedLoadingValue requires an explicit store seed" ) ;
298+ if ( ! seeded ) validateSeedlessOptions ( options ) ;
298299 const derive = seeded ? fn : ( ) => ( fn as ( ) => T | Promise < T > | AsyncIterable < T > ) ( ) ;
299300 return createStoreDerivedNextInternal (
300301 derive ,
@@ -327,6 +328,7 @@ export function createStoreHydrationReplayNext<T extends object = {}>(
327328 replaying : ( ) => boolean ,
328329 options ?: ProjectionOptions
329330) : [ Refreshable < Store < T > > , ( f : ( draft : T ) => T | void ) => void ] {
331+ validateSeedlessOptions ( options ) ;
330332 return createStoreDerivedNextInternal (
331333 fn ,
332334 { } as T ,
0 commit comments