No breaking changes in this update.
-
[watch]: boolean|WatchOptions
Now reindex on resource changes can be debounced.
WatchOptions
-
[delay]:
number
If provided, reindex will be debounced with specified delay.
-
No breaking changes in this update.
-
[watch]: boolean
Whether needs to reindex if resource changes. This option is useful to avoid reindex overhead when the resource frequently changes.
Default:
true
Example:
searchPlugin({
resources: {
contacts: {
index: ['address', 'name'],
getter: state => state.myResources.contacts,
// Do not reindex automatically if resource changes
watch: false,
},
},
}),
-
reindex
Mapped action has signature:
() => void
. To be used when optionwatch
isfalse
. This action will reindex the resource and automatically re-search
current searchtext
. -
registerResource
Mapped action has signature:
(options: IndexOptions) => void
. This action will dynamically addresourceName
with options provided. -
unregisterResource
Mapped action has signature:
() => void
. This action will unwatch and removeresourceName
index.
In v1.x:
Vuex can use multiple named plugins, where each plugin defines one resourceGetter
and one searchApi
to be shared by resourceIndexes
in the plugin. Thus another plugin must be defined if different searchApi
is to be used.
searchPlugin({
name: 'myIndex',
resourceIndexes: {
contacts: ['address', 'name'],
},
resourceGetter: (resourceName, state) => state.myResources[resourceName],
searchApi: new SearchApi();
});
This sturcture may be confusing and redundant, since resource's name itself can already be a unique identifier for an index without plugin's name.
Also, this API makes impossible to support dynamic index registration.
In v2.0:
Similar to v1, custom searchApi
can be defined in plugin option. However, now each resource has its own getter
and optional searchApi
.
searchPlugin({
resources: {
contacts: {
// what fields to index
index: ['address', 'name'],
// access the state to be watched by Vuex Search
getter: state => state.myResources.contacts,
},
},
}),
vuex-search v2 also supports dynamic index registration.
Vuex Search can be accessed through store.search
or this.$store.search
in a Vue instance.
In v1.x:
Because plugin can be named, mapActions
and mapGetters
needs to be composed from composeSearchMappers
like so.
import { composeSearchMappers } from 'vuex-search';
// Composing actions and getters from selected plugin name
const { mapSearchGetters, mapSearchActions } = composeSearchMappers('myIndex');
In v2.0:
Plugin name option is removed. Now mappers needn't to be composed.
import {
mapActions as mapSearchActions,
mapGetters as mapSearchGetters,
} from 'vuex-search';
Initial release.