@@ -410,48 +410,6 @@ functions.crypto = async (ticker) => {
410410 }
411411}
412412
413- function flattenArgs ( computed ) {
414- if ( computed ?. refs == null ) {
415- return computed . value ;
416- }
417- return (
418- computed . refs
419- . map ( ( r ) => flattenArgs ( r ) )
420- . flat ( )
421- // Hack for detecting stores instead of primitive values
422- . filter ( ( r ) => r ?. subscribe != null )
423- ) ;
424- }
425-
426- function flattenComputedToFunction ( computed ) {
427- if ( computed ?. refs == null ) {
428- return ( ...args ) => args ;
429- }
430- let thunk = computed . thunk ?? ( ( ...args ) => args ) ;
431- let refArgsCounts = computed . refs . map ( ( r ) => r ?. numRefArgs ?? 1 ) ;
432- return async ( ...args ) => {
433- let offset = 0 ;
434- // Call the thunk with the correct args from the flattened list. Use `.call`
435- // and `.apply` to pass the correct `this` value.
436- return await thunk . apply (
437- this ,
438- (
439- await Promise . all (
440- computed . refs . map ( ( r , i ) => {
441- const oldOffset = offset ;
442- offset += refArgsCounts [ i ] ;
443- // Recurse with the relevant portion of the flattened arguments list
444- return flattenComputedToFunction . call (
445- this ,
446- r ,
447- ) ( ...args . slice ( oldOffset , offset ) ) ;
448- } ) ,
449- )
450- ) . flat ( ) ,
451- ) ;
452- } ;
453- }
454-
455413export class Sheet {
456414 name = $state ( ) ;
457415 cells = $state ( ) ;
@@ -515,7 +473,7 @@ export class Sheet {
515473 cell . col ,
516474 ) ;
517475 cell . value . rederive (
518- flattenArgs ( computed ) ,
476+ computed . flattenArgs ( ) ,
519477 ( dependencyValues , _set , _update ) => {
520478 const set = ( ...args ) => {
521479 try {
@@ -545,11 +503,8 @@ export class Sheet {
545503 element : undefined ,
546504 globals : this . globals ,
547505 } ;
548- flattenComputedToFunction
549- . call (
550- _this ,
551- computed ,
552- ) ( ...dependencyValues )
506+ computed
507+ . flattenComputedToFunction ( _this ) ( ...dependencyValues )
553508 . then ( ( [ result ] ) => {
554509 update ( ( old ) => {
555510 // TODO: Find a better trigger for resets than just waiting
0 commit comments