Coder Social home page Coder Social logo

Comments (3)

arrilot avatar arrilot commented on July 26, 2024

Hi, what do you mean when you say "to query a data set for changes before reloading"?

from laravel-widgets.

danielroymoore avatar danielroymoore commented on July 26, 2024

Cheers for getting back to me, I've amended the question a little bit as I wrote it in a rush. I thought of two use cases that I'm trying to achieve that aren't immediately obvious ( or they are, but it seem I'm going about it wrong).

For example: I have a reloading widget that is reading values from a data set. At present, after the timeout the widget will refresh. However what I'd like is to query the table for changes and only call the run function if there has been a change since the last reload. My work around off the top of my head is:

protected $timeLastModified;

public function pollData()
{
    // Check last modified of some data source, update $timeLastModified if applicable and return a bool
}
public function run()
{
    if (pollData()) {
        return view("widgets.recent_news", [
            'config' => $this->config,
        ]);
    }
}

Is there are way of hooking up run function of a widget to Events in Laravel, so that the need for the above is not needed. This may remove the need to put this type of functionality within a reloading widget.

from laravel-widgets.

arrilot avatar arrilot commented on July 26, 2024
public function run()
{
    if ($this->pollData()) {
        return view("widgets.recent_news", [
            'config' => $this->config,
        ]);
    }
}

The problem is that it doesn't stop the widget from being reloaded. It's gonna be replaced with the blank content in this case. The widget MUST be reloaded each time to attach another setTimeout() handler for the next iteration.

So, there is nothing I can do for you here I'm afraid.

If you really need to do an extra check before reload just do it manually.

  1. Make widgget not reloadable
  2. Write your own javascript reloader using setInterval(). Make an ajax call to check state and reload widget manually by another ajax if it's needed.
    Not a big deal.

from laravel-widgets.

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.