foxbenjaminfox/vue-async-computed

$asyncComputed state

Opened this issue · 5 comments

$requestState.state is always updating if computed resolves to 0. It is never becomes success.

Hey, I've added a test case that tries to test this issue, but I'm not managing to reproduce it. Can you take a look, and help me track down what's causing your issue?

Hm. I can add I'm using default: null option too. And my async function resolves for about 1 second.
Maybe, it helps to reproduce the error.

Neither of those should matter (especially since the default default is already null.) I've run a variant of the test with a 1-second long timeout and an explicit default: null, but I still can't reproduce this.

Can you give me a code excerpt that seems to trigger this behaviour for you?

computed: {
  isLoading() {
    return this.$asyncComputed.someOperation.updating;
  }
}
...
asyncComputed: {
   someOperation: {
     default: null,
     get() {
       return asyncFnReturnsZero();
     }
   }
}

If the asyncFnReturnsZero resolves in a non-zero value everything goes ok, but if in zero, isLoading is always true;

I see what you're saying, and I've tried to replicate exactly that in the test suite here:

test("$asyncComputed[name].state resolves to 'success' even if the computed value is 0 (issue #75)", t => {
t.plan(13)
const vm = new Vue({
computed: {
isUpdating () {
return this.$asyncComputed.a.updating
}
},
asyncComputed: {
a: {
async get () {
return 0
},
default: null
}
}
})
t.equal(vm.$asyncComputed['a'].state, 'updating')
t.equal(vm.$asyncComputed['a'].updating, true)
t.equal(vm.$asyncComputed['a'].success, false)
t.equal(vm.$asyncComputed['a'].error, false)
t.equal(vm.$asyncComputed['a'].exception, null)
t.equal(vm.isUpdating, true)
Vue.nextTick(() => {
t.equal(vm.a, 0)
t.equal(vm.$asyncComputed['a'].state, 'success')
t.equal(vm.$asyncComputed['a'].updating, false)
t.equal(vm.$asyncComputed['a'].success, true)
t.equal(vm.$asyncComputed['a'].error, false)
t.equal(vm.$asyncComputed['a'].exception, null)
t.equal(vm.isUpdating, false)
})
})

The test still passes just fine, so I doubt that the problem is in something the test covers here. Is it possible that something else is going on here? Perhaps a reactivity issue of some sort in your code? (Along the lines of #18?)

If you can make an example (e.g. in codepen.io) that shows this issue happening, I'll look into it further.