@@ -433,15 +433,34 @@ const defaultMethods = {
433
433
}
434
434
} ,
435
435
map : createArrayIterativeMethod ( 'map' ) ,
436
- some : createArrayIterativeMethod ( 'some' , true ) ,
436
+ some : {
437
+ ...createArrayIterativeMethod ( 'some' , true ) ,
438
+ method : ( input , context , above , engine ) => {
439
+ if ( ! Array . isArray ( input ) ) throw new InvalidControlInput ( input )
440
+ let [ selector , mapper ] = input
441
+
442
+ selector = engine . run ( selector , context , { above } ) || [ ]
443
+
444
+ for ( let i = 0 ; i < selector . length ; i ++ ) {
445
+ if ( engine . truthy ( engine . run ( mapper , selector [ i ] , { above : [ selector , context , above ] } ) ) ) return true
446
+ }
447
+ return false
448
+ }
449
+ } ,
437
450
all : {
438
451
[ Sync ] : oldAll [ Sync ] ,
439
452
method : ( args , context , above , engine ) => {
440
453
if ( Array . isArray ( args ) ) {
441
454
const first = engine . run ( args [ 0 ] , context , above )
442
455
if ( Array . isArray ( first ) && first . length === 0 ) return false
443
456
}
444
- return oldAll . method ( args , context , above , engine )
457
+ let [ selector , mapper ] = args
458
+ selector = engine . run ( selector , context , { above } ) || [ ]
459
+
460
+ for ( let i = 0 ; i < selector . length ; i ++ ) {
461
+ if ( ! engine . truthy ( engine . run ( mapper , selector [ i ] , { above : [ selector , context , above ] } ) ) ) return false
462
+ }
463
+ return true
445
464
} ,
446
465
asyncMethod : async ( args , context , above , engine ) => {
447
466
if ( Array . isArray ( args ) ) {
@@ -456,13 +475,8 @@ const defaultMethods = {
456
475
none : {
457
476
[ Sync ] : ( data , buildState ) => isSyncDeep ( data , buildState . engine , buildState ) ,
458
477
lazy : true ,
459
- // todo: add async build & build
460
- method : ( val , context , above , engine ) => {
461
- return ! defaultMethods . some . method ( val , context , above , engine )
462
- } ,
463
- asyncMethod : async ( val , context , above , engine ) => {
464
- return ! ( await defaultMethods . some . asyncMethod ( val , context , above , engine ) )
465
- } ,
478
+ method : ( val , context , above , engine ) => ! defaultMethods . some . method ( val , context , above , engine ) ,
479
+ asyncMethod : async ( val , context , above , engine ) => ! ( await defaultMethods . some . asyncMethod ( val , context , above , engine ) ) ,
466
480
compile : ( data , buildState ) => {
467
481
const result = defaultMethods . some . compile ( data , buildState )
468
482
return result ? buildState . compile `!(${ result } )` : false
@@ -480,7 +494,6 @@ const defaultMethods = {
480
494
}
481
495
return result
482
496
} ,
483
- every : createArrayIterativeMethod ( 'every' ) ,
484
497
filter : createArrayIterativeMethod ( 'filter' , true ) ,
485
498
reduce : {
486
499
deterministic : ( data , buildState ) => {
@@ -768,26 +781,21 @@ function createArrayIterativeMethod (name, useTruthy = false) {
768
781
method : ( input , context , above , engine ) => {
769
782
if ( ! Array . isArray ( input ) ) throw new InvalidControlInput ( input )
770
783
let [ selector , mapper ] = input
771
- selector =
772
- engine . run ( selector , context , {
773
- above
774
- } ) || [ ]
784
+
785
+ selector = engine . run ( selector , context , { above } ) || [ ]
775
786
776
787
return selector [ name ] ( ( i , index ) => {
777
- const result = engine . run ( mapper , i , {
778
- above : [ { iterator : selector , index } , context , above ]
779
- } )
788
+ if ( ! mapper || typeof mapper !== 'object' ) return useTruthy ? engine . truthy ( mapper ) : mapper
789
+ const result = engine . run ( mapper , i , { above : [ { iterator : selector , index } , context , above ] } )
780
790
return useTruthy ? engine . truthy ( result ) : result
781
791
} )
782
792
} ,
783
793
asyncMethod : async ( input , context , above , engine ) => {
784
794
if ( ! Array . isArray ( input ) ) throw new InvalidControlInput ( input )
785
795
let [ selector , mapper ] = input
786
- selector =
787
- ( await engine . run ( selector , context , {
788
- above
789
- } ) ) || [ ]
796
+ selector = ( await engine . run ( selector , context , { above } ) ) || [ ]
790
797
return asyncIterators [ name ] ( selector , async ( i , index ) => {
798
+ if ( ! mapper || typeof mapper !== 'object' ) return useTruthy ? engine . truthy ( mapper ) : mapper
791
799
const result = await engine . run ( mapper , i , {
792
800
above : [ { iterator : selector , index } , context , above ]
793
801
} )
@@ -822,6 +830,8 @@ function createArrayIterativeMethod (name, useTruthy = false) {
822
830
lazy : true
823
831
}
824
832
}
833
+
834
+ defaultMethods . every = defaultMethods . all
825
835
defaultMethods [ '?:' ] = defaultMethods . if
826
836
// declare all of the functions here synchronous
827
837
Object . keys ( defaultMethods ) . forEach ( ( item ) => {
0 commit comments