@@ -55,13 +55,29 @@ export default class Signal extends Function {
55
55
56
56
get ( ) {
57
57
if ( arguments . length > 0 ) throw Error ( 'Signal.get() does not accept any arguments' )
58
+ if ( this [ SEGMENTS ] . length === 3 && this [ SEGMENTS ] [ 0 ] === QUERIES && this [ SEGMENTS ] [ 2 ] === 'ids' ) {
59
+ // TODO: This should never happen, but in reality it happens sometimes
60
+ // Patch getting query ids because sometimes for some reason we are not getting them
61
+ const ids = this [ GET ] ( _get )
62
+ if ( ! Array . isArray ( ids ) ) {
63
+ console . warn ( 'Signal.get() on Query didn\'t find ids' , this [ SEGMENTS ] )
64
+ return [ ]
65
+ }
66
+ return ids
67
+ }
58
68
return this [ GET ] ( _get )
59
69
}
60
70
61
71
getIds ( ) {
62
72
if ( arguments . length > 0 ) throw Error ( 'Signal.getIds() does not accept any arguments' )
63
73
if ( this [ IS_QUERY ] ) {
64
- return _get ( [ QUERIES , this [ HASH ] , 'ids' ] )
74
+ const ids = _get ( [ QUERIES , this [ HASH ] , 'ids' ] )
75
+ if ( ! Array . isArray ( ids ) ) {
76
+ // TODO: This should never happen, but in reality it happens sometimes
77
+ console . warn ( 'Signal.getIds() on Query didn\'t find ids' , [ QUERIES , this [ HASH ] , 'ids' ] )
78
+ return [ ]
79
+ }
80
+ return ids
65
81
} else if ( this [ IS_AGGREGATION ] ) {
66
82
const docs = _get ( this [ SEGMENTS ] )
67
83
if ( ! Array . isArray ( docs ) ) return [ ]
@@ -95,6 +111,11 @@ export default class Signal extends Function {
95
111
* [ Symbol . iterator ] ( ) {
96
112
if ( this [ IS_QUERY ] ) {
97
113
const ids = _get ( [ QUERIES , this [ HASH ] , 'ids' ] )
114
+ if ( ! Array . isArray ( ids ) ) {
115
+ // TODO: This should never happen, but in reality it happens sometimes
116
+ console . warn ( 'Signal iterator on Query didn\'t find ids' , [ QUERIES , this [ HASH ] , 'ids' ] )
117
+ return
118
+ }
98
119
for ( const id of ids ) yield getSignal ( getRoot ( this ) , [ this [ SEGMENTS ] [ 0 ] , id ] )
99
120
} else {
100
121
const items = _get ( this [ SEGMENTS ] )
@@ -108,6 +129,11 @@ export default class Signal extends Function {
108
129
const collection = this [ SEGMENTS ] [ 0 ]
109
130
const hash = this [ HASH ]
110
131
const ids = _get ( [ QUERIES , hash , 'ids' ] )
132
+ if ( ! Array . isArray ( ids ) ) {
133
+ // TODO: This should never happen, but in reality it happens sometimes
134
+ console . warn ( 'Signal array method on Query didn\'t find ids' , [ QUERIES , hash , 'ids' ] , method )
135
+ return nonArrayReturnValue
136
+ }
111
137
return ids . map (
112
138
id => getSignal ( getRoot ( this ) , [ collection , id ] )
113
139
) [ method ] ( ...args )
0 commit comments