Code Monkey home page Code Monkey logo

Comments (5)

rrousselGit avatar rrousselGit commented on June 22, 2024

Could you be more specific? I don't really understand the problem, not what is suggested here.

Some examples of the problem and the suggestion would be great.

from riverpod.

samderlust avatar samderlust commented on June 22, 2024

@rrousselGit

final getProvider = FutureProvider<String>(
  (ref) async {
    // get remote data
    return '';
  }
);

//in other function somewhere esle
void updatedata()async{
  // await update data
  ref.invalidate(getProvider)
}

so in this case ref.invalidate(getProvider) will trigger get remote data right after the update. Sometime it doesn't leave enough time for server to update data all the way through. so it returns un updated data.
A hook could be something like this.

final getProvider = FutureProvider<String>(

  (ref) async {
    ref.beforeInvalidate(() async{
      await Future.delayed(const Duration(seconds: 1));
    })
    // get remote data
    return '';
  }
);

This could be useful in some other usecases I think

from riverpod.

rrousselGit avatar rrousselGit commented on June 22, 2024

I'm sceptical about this. If the provider was invalidated, to me it should rebuild immediately the next time it is used.
Adding an indirect delay like that would be confusing. It'd be hard to know why the refresh isn't happening.

To be, it sounds like you want to do:

//in other function somewhere esle
void updatedata()async{
  await Future.delayed(const Duration(seconds: 1));
  ref.invalidate(getProvider)
}

from riverpod.

rrousselGit avatar rrousselGit commented on June 22, 2024

In fact, the fact that you need this delay is weird to me.

Your server should be up-to-date. If it isn't, that means you didn't await something.

from riverpod.

samderlust avatar samderlust commented on June 22, 2024

yeah some time the request sent too fast and server still cache I think.

//in other function somewhere esle
void updatedata()async{
  await Future.delayed(const Duration(seconds: 1));
  ref.invalidate(getProvider)
}

This works most of the time. but Sometimes in the UI ref.invalidate(getProvider) scatters other places. so would a bit inconvenient to add a wait time to other places like that.

from riverpod.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.