krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
18.15k stars 767 forks source link

Index not being created using a Vuex4 getter #634

Closed austintoddj closed 2 years ago

austintoddj commented 2 years ago

Not sure what might be happening, but my understanding of the problem I'm having is that the _myIndex property on the Fuse object I'm instantiating is never created.

Seems to only happen when I'm pulling the data from a store getter (Vuex4/Vue3).

If I hardcode the data, everything works like it should. I do see that the _docs property is hydrated, so I'm unsure of why the _myIndex property isn't updating as well.

<script setup>
import { computed, ref, onMounted } from 'vue'
import { useStore } from 'vuex';
import Fuse from 'fuse.js';

const store = useStore()
const trans = computed(() => store.getters["settings/trans"])
const search = computed(() => store.getters["search/index"])

// works
// const posts = [{"id":"015ff504-bc4e-49e6-b5d4-2c26557fcf81","title":"I Ran to Escape My Problems. Then Running Became One.","name":"I Ran to Escape My Problems. Then Running Became One.","type":"Post","route":"edit-post","estimated_read_time_in_minutes":0},{"id":"d118281a-0593-485e-a7e6-248b2fe18572","title":"Being Happy Is Hard Work","name":"Being Happy Is Hard Work","type":"Post","route":"edit-post","estimated_read_time_in_minutes":0},{"id":"401b7e4f-bf3e-44ea-a226-877046320994","title":"The Architect of Tomorow","name":"The Architect of Tomorow","type":"Post","route":"edit-post","estimated_read_time_in_minutes":0},{"id":"afc7362a-f168-4271-be23-3d24e15f36ce","title":"Here\u2019s How Robots Can Help Us Deal With Pollution","name":"Here\u2019s How Robots Can Help Us Deal With Pollution","type":"Post","route":"edit-post","estimated_read_time_in_minutes":0},{"id":"421a03b1-8742-42e0-aa7e-061d240a513e","title":"How Facebook Borrows From the NSA Playbook","name":"How Facebook Borrows From the NSA Playbook","type":"Post","route":"edit-post","estimated_read_time_in_minutes":0},{"id":"6e227148-20f6-4ad8-9d98-bea906674c8c","title":"A New Vision for the Future of Driving","name":"A New Vision for the Future of Driving","type":"Post","route":"edit-post","estimated_read_time_in_minutes":0}];
// const fuse = new Fuse(posts, {  
//  keys: [
//      "name",
//  ]
//});

// doesn't work
const fuse = new Fuse(search.value, {  
    keys: [
        "name",
    ]
  }
);
</script>

Devtools output when using the store:

Screen Shot 2022-03-28 at 10 05 59 AM

Devtools output when hardcoding the data:

Screen Shot 2022-03-28 at 10 06 17 AM
github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days