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

Proposal for silent refetch on expiry/thumbprint change using localstorage #934

Open
simplenotezy opened this issue Aug 10, 2014 · 1 comment
Milestone

Comments

@simplenotezy
Copy link

First of all; you've guys really nailed it. Typeahead is simply awesomeness. Really good job!

I have a proposal, to change the way Bloodhound handles expired datasets / changed thumbprints using Prefetch. Currently, when it expires, the localstorage is cleared, and user has to wait until the new data has been fetched. This can, if the dataset expiry is set to a very low or even negative value (I need this, as my datasets change very often), be very annoying for the enduser, as there will often be a lot of wasted time for the user, waiting for the new dataset data to arrive.

When the dataset in localstorage is expired, I imagine it to work something like this:

  1. User loads page. The expired localstorage will be used, until the request for new data has been completed.
  2. Server loads the prefetch URL to fetch fresh data. When the data is received, it will overwrite the localstorage data.
  3. Nice. Now the user still had instant suggestions (just from the expired dataset), while the new data was being loaded, and he did not even notice the dataset was refreshed!

EDIT:
I have created some code, which actually does what I want. Maybe the code will be better at explaining what I mean.

    Bloodhound.prototype.refreshDataset = function() {
        /**
         * Keep self
         */

            var BloodHound = this;

        /**
         * Run ajax
         */

            $.ajax(BloodHound.prefetch.url, BloodHound.prefetch.ajax).done(function(resp) {
                /**
                 * We have new data
                 */

                    /**
                     * Clear existing content
                     */

                        BloodHound.clear();

                    /**
                     * Add new content
                     */

                        BloodHound.add(BloodHound.prefetch.filter ? BloodHound.prefetch.filter(resp) : resp);

                    /**
                     * Save new storage
                     */

                        BloodHound._saveToStorage(BloodHound.index.serialize(), BloodHound.prefetch.thumbprint, self.prefetch.ttl);

            });

    }

Can be used like this:

        Bloodhound.initialize();
        Bloodhound.refreshDataset();

JSFIDDLE: http://jsfiddle.net/f5r371sL/1/ (no dataset)

@simplenotezy simplenotezy changed the title Proposal for "reloadPrefetch" setting Proposal for silent refetch on expiry/thumbprint change using localstorage Aug 10, 2014
@jharding
Copy link
Contributor

Another issue mentions a similar idea, but I can't seem to find it right now. It's something I'd be open to adding. It's not a high priority for me, but I'd most likely accept a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants