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

isPending is true by default #95

Closed
rigwild opened this issue Oct 29, 2019 · 2 comments
Closed

isPending is true by default #95

rigwild opened this issue Oct 29, 2019 · 2 comments

Comments

@rigwild
Copy link

rigwild commented Oct 29, 2019

Hey,

I started to use the combined slot as I find it more flexible for forms disabled states.

For example:

<Promised :promise="promise" v-slot:combined="{ isPending, data, error }">
  <button @click="refreshValue" :disabled="isPending">
    Load
  </button>

  <Loader v-if="isPending" />
  <textarea v-else-if="data" v-text="data"></textarea>
  <Alert v-else-if="error" v-text="error" />
</Promised>

By default, isPending is initialized as true when promise is initialized as null. This is frustrating as it makes the form being rendered as in a loading state (at first I was confused as it is not what I expected, and could not find the problem).

data: () => ({
resolved: false,
data: null,
error: null,
isDelayElapsed: false,
}),

if (this.$scopedSlots.combined) {
const node = this.$scopedSlots.combined({
isPending: !this.resolved,
isDelayOver: this.isDelayElapsed,
data: this.data,
error: this.error,
})

The workAround I use is to set a resolved Promise as initialization, but I don't think that is very beautiful 👀

data() {
  return {
    promise: Promise.resolve()
  }
}

Maybe a prop could be added to init as false instead of true.

That's not a huge deal though.

Have a nice day!

@posva
Copy link
Owner

posva commented Oct 29, 2019

This is intentional so the promise is on a pending state until there is something to wait for. Using a resolved promise to make the state automatically go into resolved is the way to go. It clearly expresses that we start as resolved
Promised is meant to reflect the 3 states of a promise, introducing new ones only complexifies the api and detach it more from the js promises

@posva posva closed this as completed Oct 29, 2019
@rigwild
Copy link
Author

rigwild commented Oct 30, 2019

I get your point. This issue may be useful to others who are facing the same problem!
Have a nice day 😸

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