@@ -155,15 +155,17 @@ const useListenable = <T>(
155155 let value = $state < T > (
156156 ( getThing ( ) ?. [ getMethod ] ?.( ...getArgs ( ) ) ?? defaultValue ) as T ,
157157 ) ;
158- $effect ( ( ) => {
159- const thing = getThing ( ) ;
160- const args = getArgs ( ) ;
161- value = ( thing ?. [ getMethod ] ?.( ...args ) ?? defaultValue ) as T ;
162- const listenerId = thing ?. [ addMethod ] ?.( ...args , ( ) => {
163- value = ( thing [ getMethod ] ( ...getArgs ( ) ) ?? defaultValue ) as T ;
158+ if ( typeof window !== 'undefined' ) {
159+ $effect ( ( ) => {
160+ const thing = getThing ( ) ;
161+ const args = getArgs ( ) ;
162+ value = ( thing ?. [ getMethod ] ?.( ...args ) ?? defaultValue ) as T ;
163+ const listenerId = thing ?. [ addMethod ] ?.( ...args , ( ) => {
164+ value = ( thing [ getMethod ] ( ...getArgs ( ) ) ?? defaultValue ) as T ;
165+ } ) ;
166+ return ( ) => thing ?. delListener ?.( listenerId ) ;
164167 } ) ;
165- return ( ) => thing ?. delListener ?.( listenerId ) ;
166- } ) ;
168+ }
167169 return {
168170 get current ( ) : T {
169171 return value as T ;
@@ -311,7 +313,7 @@ export const useCell = (
311313 rv ( cellId ) ,
312314 ] ) ;
313315
314- export const useCellState = (
316+ export const useBindableCell = (
315317 tableId : R < Id > ,
316318 rowId : R < Id > ,
317319 cellId : R < Id > ,
@@ -321,17 +323,19 @@ export const useCellState = (
321323 let value = $state < CellOrUndefined > (
322324 getS ( ) ?. getCell ( rv ( tableId ) , rv ( rowId ) , rv ( cellId ) ) ,
323325 ) ;
324- $effect ( ( ) => {
325- const s : any = getS ( ) ;
326- const t = rv ( tableId ) ,
327- r = rv ( rowId ) ,
328- c = rv ( cellId ) ;
329- value = s ?. getCell ( t , r , c ) ;
330- const listenerId = s ?. addCellListener ( t , r , c , ( st : any ) => {
331- value = st . getCell ( rv ( tableId ) , rv ( rowId ) , rv ( cellId ) ) ;
326+ if ( typeof window !== 'undefined' ) {
327+ $effect ( ( ) => {
328+ const s : any = getS ( ) ;
329+ const t = rv ( tableId ) ,
330+ r = rv ( rowId ) ,
331+ c = rv ( cellId ) ;
332+ value = s ?. getCell ( t , r , c ) ;
333+ const listenerId = s ?. addCellListener ( t , r , c , ( st : any ) => {
334+ value = st . getCell ( rv ( tableId ) , rv ( rowId ) , rv ( cellId ) ) ;
335+ } ) ;
336+ return ( ) => s ?. delListener ?.( listenerId ) ;
332337 } ) ;
333- return ( ) => s ?. delListener ?.( listenerId ) ;
334- } ) ;
338+ }
335339 return {
336340 get current ( ) : CellOrUndefined {
337341 return value ;
@@ -367,21 +371,23 @@ export const useValue = (
367371) : { readonly current : ValueOrUndefined } =>
368372 useGet ( sg ( storeOrStoreId ) , VALUE , undefined , ( ) => [ rv ( valueId ) ] ) ;
369373
370- export const useValueState = (
374+ export const useBindableValue = (
371375 valueId : R < Id > ,
372376 storeOrStoreId ?: R < Store | Id | undefined > ,
373377) : { get current ( ) : ValueOrUndefined ; set current ( v : Value ) } => {
374378 const getS = sg ( storeOrStoreId ) ;
375379 let value = $state < ValueOrUndefined > ( getS ( ) ?. getValue ( rv ( valueId ) ) ) ;
376- $effect ( ( ) => {
377- const s : any = getS ( ) ;
378- const vid = rv ( valueId ) ;
379- value = s ?. getValue ( vid ) ;
380- const listenerId = s ?. addValueListener ( vid , ( st : any ) => {
381- value = st . getValue ( rv ( valueId ) ) ;
380+ if ( typeof window !== 'undefined' ) {
381+ $effect ( ( ) => {
382+ const s : any = getS ( ) ;
383+ const vid = rv ( valueId ) ;
384+ value = s ?. getValue ( vid ) ;
385+ const listenerId = s ?. addValueListener ( vid , ( st : any ) => {
386+ value = st . getValue ( rv ( valueId ) ) ;
387+ } ) ;
388+ return ( ) => s ?. delListener ?.( listenerId ) ;
382389 } ) ;
383- return ( ) => s ?. delListener ?.( listenerId ) ;
384- } ) ;
390+ }
385391 return {
386392 get current ( ) : ValueOrUndefined {
387393 return value ;
@@ -398,9 +404,11 @@ export const useStore = (id?: Id): Store | undefined =>
398404export const useStoreIds = ( ) : { readonly current : Ids } => {
399405 const ctx = getCtx ( ) ;
400406 let ids = $state < Ids > ( getThingIds ( ctx , OFFSET_STORE ) ) ;
401- $effect ( ( ) => {
402- ids = getThingIds ( ctx , OFFSET_STORE ) ;
403- } ) ;
407+ if ( typeof window !== 'undefined' ) {
408+ $effect ( ( ) => {
409+ ids = getThingIds ( ctx , OFFSET_STORE ) ;
410+ } ) ;
411+ }
404412 return {
405413 get current ( ) {
406414 return ids ;
@@ -414,9 +422,11 @@ export const useMetrics = (id?: Id): Metrics | undefined =>
414422export const useMetricsIds = ( ) : { readonly current : Ids } => {
415423 const ctx = getCtx ( ) ;
416424 let ids = $state < Ids > ( getThingIds ( ctx , OFFSET_METRICS ) ) ;
417- $effect ( ( ) => {
418- ids = getThingIds ( ctx , OFFSET_METRICS ) ;
419- } ) ;
425+ if ( typeof window !== 'undefined' ) {
426+ $effect ( ( ) => {
427+ ids = getThingIds ( ctx , OFFSET_METRICS ) ;
428+ } ) ;
429+ }
420430 return {
421431 get current ( ) {
422432 return ids ;
@@ -441,9 +451,11 @@ export const useIndexes = (id?: Id): Indexes | undefined =>
441451export const useIndexesIds = ( ) : { readonly current : Ids } => {
442452 const ctx = getCtx ( ) ;
443453 let ids = $state < Ids > ( getThingIds ( ctx , OFFSET_INDEXES ) ) ;
444- $effect ( ( ) => {
445- ids = getThingIds ( ctx , OFFSET_INDEXES ) ;
446- } ) ;
454+ if ( typeof window !== 'undefined' ) {
455+ $effect ( ( ) => {
456+ ids = getThingIds ( ctx , OFFSET_INDEXES ) ;
457+ } ) ;
458+ }
447459 return {
448460 get current ( ) {
449461 return ids ;
@@ -478,9 +490,11 @@ export const useQueries = (id?: Id): Queries | undefined =>
478490export const useQueriesIds = ( ) : { readonly current : Ids } => {
479491 const ctx = getCtx ( ) ;
480492 let ids = $state < Ids > ( getThingIds ( ctx , OFFSET_QUERIES ) ) ;
481- $effect ( ( ) => {
482- ids = getThingIds ( ctx , OFFSET_QUERIES ) ;
483- } ) ;
493+ if ( typeof window !== 'undefined' ) {
494+ $effect ( ( ) => {
495+ ids = getThingIds ( ctx , OFFSET_QUERIES ) ;
496+ } ) ;
497+ }
484498 return {
485499 get current ( ) {
486500 return ids ;
@@ -577,9 +591,11 @@ export const useRelationships = (id?: Id): Relationships | undefined =>
577591export const useRelationshipsIds = ( ) : { readonly current : Ids } => {
578592 const ctx = getCtx ( ) ;
579593 let ids = $state < Ids > ( getThingIds ( ctx , OFFSET_RELATIONSHIPS ) ) ;
580- $effect ( ( ) => {
581- ids = getThingIds ( ctx , OFFSET_RELATIONSHIPS ) ;
582- } ) ;
594+ if ( typeof window !== 'undefined' ) {
595+ $effect ( ( ) => {
596+ ids = getThingIds ( ctx , OFFSET_RELATIONSHIPS ) ;
597+ } ) ;
598+ }
583599 return {
584600 get current ( ) {
585601 return ids ;
@@ -630,9 +646,11 @@ export const useCheckpoints = (id?: Id): Checkpoints | undefined =>
630646export const useCheckpointsIds = ( ) : { readonly current : Ids } => {
631647 const ctx = getCtx ( ) ;
632648 let ids = $state < Ids > ( getThingIds ( ctx , OFFSET_CHECKPOINTS ) ) ;
633- $effect ( ( ) => {
634- ids = getThingIds ( ctx , OFFSET_CHECKPOINTS ) ;
635- } ) ;
649+ if ( typeof window !== 'undefined' ) {
650+ $effect ( ( ) => {
651+ ids = getThingIds ( ctx , OFFSET_CHECKPOINTS ) ;
652+ } ) ;
653+ }
636654 return {
637655 get current ( ) {
638656 return ids ;
@@ -677,9 +695,11 @@ export const usePersister = (id?: Id): AnyPersister | undefined =>
677695export const usePersisterIds = ( ) : { readonly current : Ids } => {
678696 const ctx = getCtx ( ) ;
679697 let ids = $state < Ids > ( getThingIds ( ctx , OFFSET_PERSISTER ) ) ;
680- $effect ( ( ) => {
681- ids = getThingIds ( ctx , OFFSET_PERSISTER ) ;
682- } ) ;
698+ if ( typeof window !== 'undefined' ) {
699+ $effect ( ( ) => {
700+ ids = getThingIds ( ctx , OFFSET_PERSISTER ) ;
701+ } ) ;
702+ }
683703 return {
684704 get current ( ) {
685705 return ids ;
@@ -698,9 +718,11 @@ export const useSynchronizer = (id?: Id): Synchronizer | undefined =>
698718export const useSynchronizerIds = ( ) : { readonly current : Ids } => {
699719 const ctx = getCtx ( ) ;
700720 let ids = $state < Ids > ( getThingIds ( ctx , OFFSET_SYNCHRONIZER ) ) ;
701- $effect ( ( ) => {
702- ids = getThingIds ( ctx , OFFSET_SYNCHRONIZER ) ;
703- } ) ;
721+ if ( typeof window !== 'undefined' ) {
722+ $effect ( ( ) => {
723+ ids = getThingIds ( ctx , OFFSET_SYNCHRONIZER ) ;
724+ } ) ;
725+ }
704726 return {
705727 get current ( ) {
706728 return ids ;
@@ -715,10 +737,12 @@ export const useSynchronizerStatus = (
715737
716738const injectThing = ( offset : number , id : Id , thing : any ) : void => {
717739 const ctx = getCtx ( ) ;
718- $effect ( ( ) => {
719- ctx [ 16 ] ?.( offset , id , thing ) ;
720- return ( ) => ctx [ 17 ] ?.( offset , id ) ;
721- } ) ;
740+ if ( typeof window !== 'undefined' ) {
741+ $effect ( ( ) => {
742+ ctx [ 16 ] ?.( offset , id , thing ) ;
743+ return ( ) => ctx [ 17 ] ?.( offset , id ) ;
744+ } ) ;
745+ }
722746} ;
723747
724748export const provideStore = ( storeId : Id , store : Store ) : void =>
0 commit comments