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

Add clearCache function to ImagesLoaded #159

Closed
wants to merge 1 commit into from
Closed

Add clearCache function to ImagesLoaded #159

wants to merge 1 commit into from

Conversation

joshhepworth
Copy link

This is related to issues I experiences that affect #103 and #92.

When using JavaScript to add images to the DOM later on with the same src attribute, simply calling imagesLoaded again will trigger immediately for these images, even if the image has not actually loaded yet.

By hooking into the event of my (or your) app that causes the addition and calling clearCache() on your ImagesLoaded instance, you can ensure that it will trigger at the appropriate time. For example, in an Ember View:

Ember.View.extend({
  imagesLoaded: null,

  addMasonry: function() {
    Ember.run.scheduleOnce('afterRender', this, function() {
      var $collection = this.$('.collection');

      $collection.masonry({ itemSelector: '.item' });

      this.set('imagesLoaded',
        new imagesLoaded($collection, function() {
          $collection.masonry();
        })
      );
    });
  }.on('didInsertElement'),

  removeMasonry: function() {
    this.$('.collection').masonry('destroy');
    // Calling clearCache here makes sure that imagesLoaded doesn't trigger too quickly when the
    // Ember View is reinserted into the DOM later on.
    this.get('imagesLoaded').clearCache();
  }.on('willDestroyElement')
});

@desandro
Copy link
Owner

Hi Josh! Thanks for digging in to this. Ember is outside my comfort zone, so I appreciate you adding your expertise.

I did cut a branch that removes the cache completely, no-cache. I'm evaluating whether its worth merging in this branch to master. It sounds like it would be useful for your use case. You wouldn't need the clearCache method at all. What do you think?

@joshhepworth
Copy link
Author

That would also work great.

I just assumed that the cache was here to stay, and saw the issues I referenced, leading me to add the clearCache function. You can certainly just close this PR if that’s the direction you’re headed.

On Tue, Aug 19, 2014 at 5:10 PM, David DeSandro notifications@github.com
wrote:

Hi Josh! Thanks for digging in to this. Ember is outside my comfort zone, so I appreciate you adding your expertise.

I did cut a branch that removes the cache completely, no-cache. I'm evaluating whether its worth merging in this branch to master. It sounds like it would be useful for your use case. You wouldn't need the clearCache method at all. What do you think?

Reply to this email directly or view it on GitHub:
#159 (comment)

@desandro
Copy link
Owner

imagesLoaded v3.2.0 no longer uses the cache. Thank you for this contribution. It's closing time 🍊

@desandro desandro closed this Oct 29, 2015
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

Successfully merging this pull request may close these issues.

2 participants