GithubHelp home page GithubHelp logo

Comments (8)

elsurudo avatar elsurudo commented on May 26, 2024 10

When things calm down a bit, I might give this one a try. Good to get some validation that it would be useful for others as well.

from render_async.

vanboom avatar vanboom commented on May 26, 2024 1

Yes, this works great. I was able to use the jquery.appear plugin to detect the appearance of the element, then trigger the render-async toggle event...

  $("#user_comments").appear({container: "body"});
  $("#user_comments").on("appear", function(event, $all_appeared_elements){ $("#user_comments").trigger("load-me"); });

I actually put this code into a global function called render_async_on_appear(selector) to make it easy to call from anywhere in the app. Thanks for the tips on how to use the trigger functionality to achieve this!

from render_async.

nikolalsvk avatar nikolalsvk commented on May 26, 2024

Sounds like a great idea. We could add some lazy_load flag to render_async which will do a request only when it's visible.

I love the idea, if you want to submit a PR I'd be more than glad to help out :)

from render_async.

nightsurge avatar nightsurge commented on May 26, 2024

Maybe using this library? Might be pretty quick and painless, but is a dependency so perhaps a conditional gem install or something to signify they only add this dependency if they wish to do these types of "is visible" render_async calls?

https://github.com/creativelive/appear

from render_async.

vanboom avatar vanboom commented on May 26, 2024

Suggestion - because we have the "refresh" event which can refresh the partial, a simple flag to inhibit the initial load of the partial would allow the developer more flexibility.

Eg.

= render_async user_comments_path(user), container_id: "user_comments", replace_container: false, lazy: true

would set up the plumbing, then later the user could fire the refresh event to load/refresh the container...

$("#user_comments").trigger("refresh"); 

from render_async.

nikolalsvk avatar nikolalsvk commented on May 26, 2024

We can do this even with the toggle functionality

Basically, you should be able to do the following:

<%= render_async user_comments_path(user), 
                 container_id: "user_comments", 
                 toggle: { selector: "#user_comments", event: "load-me" } %>

And, then you can do:

const callbackToCallOnElementVisible = () => { // I got it to work by passing this callback to the IntersectionObserver
  $("#user_comments").trigger("load-me");
}

WDYT about this, @vanboom?

from render_async.

vanboom avatar vanboom commented on May 26, 2024

Yes - this makes sense. I might be misunderstanding the toggle feature. If we do not specify interval the toggle event would not cause it to poll? (In many cases we want to delay loading, but cause the partial to refresh based upon the user clicking a refresh button or some other ajax event.)

from render_async.

nikolalsvk avatar nikolalsvk commented on May 26, 2024

If we do not specify interval the toggle event would not cause it to poll?

Yes, the toggle feature can be used without polling. I tried what I suggested above and it works. It might be worth to add it to the docs as an example.

from render_async.

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.