Skip to main content

store.selectIndex()

Used to select data from an object index in the store

Properties

store.selectIndex(name, options)

name

The name of the index we want to select from. The structure of the name is important.

Lets say we name the index comments, when we select we need to pass the [name]-[uniqueId]. So to select from the comments index, generally I'd imagine you would use postId or articleId or blogId as the uniqueId for the index. This way for each post, article or blog, the comments index will be maintained seperately.

So we would select like this:

                //  index  - uniqueId
store.selectIndex(`comments-${postId}`)

options

This property is the same as the arguments properties by store.select()

The only difference here is that we can pass multiple selectors, one for each object in the index.

/**
* Here we assume that on the Home Feed, we receive a mix of posts, articles and blogs.
* This index was created to manage the order of those object.
*/
const homeFeed = createRelationalObjectIndex("homeFeed", [post, article, blog])

const store = createStore({
// ...storeOptions
indexes: [
homeFeed
],
});

// Here we select data from the index, optionally, we can pass a different selector for each type of object.
store.selectIndex("homeFeed-main", {
post: {
from: "post",
fields: "*"
},
article: {
from: "article",
fields: "*"
},
blog: {
from: "blog",
fields: "*"
}
})

API

Properties

PropertyTypeDefaultDescription
namestringundefinedThe name of a the index.
optionsRecord<string, selector>undefinedUsed to select data from the respective object type.

Return value

Same return value as store.select()