-
-
Notifications
You must be signed in to change notification settings - Fork 116
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
I tracked down this error I was running into and was able to isolate it and create a test case. It only happens when a row is added after defining an index with both a multi-id slice and a sort key—basically a scenario where force is false. This:
- adds the
sliceId
array tounsortedSlices
. - Attempts to use the
sliceId
array as a key in a mapGet call.
The force: true
path just above doesn't have the same problem as it iterators over the keys in index
which are individual slice IDs.
Your Example Website or App
No response
Steps to Reproduce the Bug or Issue
import { createStore } from 'tinybase';
import { createIndexes } from 'tinybase/indexes';
const store = createStore();
const indexes = createIndexes(store);
indexes.setIndexDefinition(
'byLetter',
'names',
(getCell) => getCell('name').toLowerCase().split(''),
(getCell) => getCell('name').toLowerCase().split('')[0],
);
store.addRow('names', { name: 'John' });
Expected behavior
Index is added successfully without throwing an error.
Screenshots or Videos
const sliceArray = [...mapGet(index, sliceId)];
^
TypeError: mapGet is not a function or its return value is not iterable
at file:///Users/neil/Products/Inkdex/index-bug/node_modules/tinybase/indexes/index.js:453:36
at Set.forEach (<anonymous>)
at collForEach (file:///Users/neil/Products/Inkdex/index-bug/node_modules/tinybase/indexes/index.js:43:41)
at file:///Users/neil/Products/Inkdex/index-bug/node_modules/tinybase/indexes/index.js:446:11
at processTable (file:///Users/neil/Products/Inkdex/index-bug/node_modules/tinybase/indexes/index.js:182:7)
at Array.<anonymous> (file:///Users/neil/Products/Inkdex/index-bug/node_modules/tinybase/indexes/index.js:216:45)
at file:///Users/neil/Products/Inkdex/index-bug/node_modules/tinybase/index.js:473:36
at Set.forEach (<anonymous>)
at collForEach (file:///Users/neil/Products/Inkdex/index-bug/node_modules/tinybase/index.js:146:41)
at file:///Users/neil/Products/Inkdex/index-bug/node_modules/tinybase/index.js:472:7
Platform
- Version: 5.4.8
Additional context
If you put the addRow
before setIndexDefinition
there is no error and it works as expected.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working