xwp / unsplash-wp

GNU General Public License v2.0
9 stars 3 forks source link

Support WordPress 4.9 #65

Closed pierlon closed 4 years ago

pierlon commented 4 years ago

Summary

Ensures plugin works on WordPress 4.9.

Checklist

spacedmonkey commented 4 years ago

Apifetch is only used by the importImage. It is would be easier to just replace with the apirequest library. We use this elsewhere. ApiRequest seems to have been added in 4.9, so we can use it.

Thoughts?

Otherwise, I like breaking off the gutenberg only override into other file.

pierlon commented 4 years ago

Apifetch is only used by the importImage. It is would be easier to just replace with the apirequest library. We use this elsewhere. ApiRequest seems to have been added in 4.9, so we can use it.

The only downside I see would be losing out on the Promise it returns. We could just use window.fetch instead, but would we need a polyfill for that? Not sure if we need to accomodate older browsers such as IE.

spacedmonkey commented 4 years ago

The only downside I see would be losing out on the Promise it returns

jQuery ajax doesn't use native browser promises, but it does use a javascript version of promises, which I think is good enough here.

It would also be super simple to wrap apiRequest it in a native promise. Something like this.

function ajax(options) {
  return new Promise(function (resolve, reject) {
    $.ajax(options).done(resolve).fail(reject);
  });
}

See this.

We could just use window.fetch instead, but would we need a polyfill for that? It is much simpler, faster and requires less testing to use an existing apiRequest package.

spacedmonkey commented 4 years ago

Tests are broken.