Skip to content

Commit 4449c35

Browse files
committed
fix: fallback to empty array when the query ids are not there for some reason
1 parent 6208e7a commit 4449c35

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

packages/teamplay/orm/Signal.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,29 @@ export default class Signal extends Function {
5555

5656
get () {
5757
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+
}
5868
return this[GET](_get)
5969
}
6070

6171
getIds () {
6272
if (arguments.length > 0) throw Error('Signal.getIds() does not accept any arguments')
6373
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
6581
} else if (this[IS_AGGREGATION]) {
6682
const docs = _get(this[SEGMENTS])
6783
if (!Array.isArray(docs)) return []
@@ -95,6 +111,11 @@ export default class Signal extends Function {
95111
* [Symbol.iterator] () {
96112
if (this[IS_QUERY]) {
97113
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+
}
98119
for (const id of ids) yield getSignal(getRoot(this), [this[SEGMENTS][0], id])
99120
} else {
100121
const items = _get(this[SEGMENTS])
@@ -108,6 +129,11 @@ export default class Signal extends Function {
108129
const collection = this[SEGMENTS][0]
109130
const hash = this[HASH]
110131
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+
}
111137
return ids.map(
112138
id => getSignal(getRoot(this), [collection, id])
113139
)[method](...args)

0 commit comments

Comments
 (0)