Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$asyncComputed state #75

Open
dmitriykorobkov opened this issue Apr 9, 2019 · 5 comments
Open

$asyncComputed state #75

dmitriykorobkov opened this issue Apr 9, 2019 · 5 comments

Comments

@dmitriykorobkov
Copy link

dmitriykorobkov commented Apr 9, 2019

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

@dmitriykorobkov dmitriykorobkov changed the title $requestState $asyncComputed state Apr 9, 2019
foxbenjaminfox added a commit that referenced this issue Apr 9, 2019
@foxbenjaminfox
Copy link
Owner

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?

@dmitriykorobkov
Copy link
Author

dmitriykorobkov commented Apr 10, 2019

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.

@foxbenjaminfox
Copy link
Owner

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?

@dmitriykorobkov
Copy link
Author

dmitriykorobkov commented Apr 11, 2019

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;

foxbenjaminfox added a commit that referenced this issue Apr 11, 2019
@foxbenjaminfox
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants