From 836f5ff978d7e577479bf0081244b850e8a7acd5 Mon Sep 17 00:00:00 2001 From: Guy Marriott Date: Tue, 4 Dec 2018 15:50:25 +1300 Subject: [PATCH] FIX Adding a debounce to fetching lazy loaded tags with tag field --- .gitignore | 1 + client/dist/js/bundle.js | 2 +- client/src/components/TagField.js | 10 +++++++++- client/src/components/tests/TagField-test.js | 8 ++++++-- package.json | 3 ++- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 2da04cd..752646d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ framework node_modules/ /**/*.js.map /**/*.css.map +yarn-error.log diff --git a/client/dist/js/bundle.js b/client/dist/js/bundle.js index 9da20bd..3e76316 100644 --- a/client/dist/js/bundle.js +++ b/client/dist/js/bundle.js @@ -1 +1 @@ -!function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s="./client/src/bundles/bundle.js")}({"./client/src/boot/index.js":function(t,e,n){"use strict";var r=n("./client/src/boot/registerComponents.js"),o=function(t){return t&&t.__esModule?t:{default:t}}(r);window.document.addEventListener("DOMContentLoaded",function(){(0,o.default)()})},"./client/src/boot/registerComponents.js":function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0});var o=n(0),s=r(o),a=n("./client/src/components/TagField.js"),i=r(a);e.default=function(){s.default.component.registerMany({TagField:i.default})}},"./client/src/bundles/bundle.js":function(t,e,n){"use strict";n("./client/src/legacy/entwine/TagField.js"),n("./client/src/boot/index.js")},"./client/src/components/TagField.js":function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{default:t}}function o(t,e){var n={};for(var r in t)e.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n}function s(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function a(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function h(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(e,"__esModule",{value:!0});var u=Object.assign||function(t){for(var e=1;e1&&(r=n[0]+"@",t=n[1]),t=t.replace(T,"."),r+a(t.split("."),e).join(".")}function h(t){for(var e,n,r=[],o=0,s=t.length;o=55296&&e<=56319&&o65535&&(t-=65536,e+=U(t>>>10&1023|55296),t=56320|1023&t),e+=U(t)}).join("")}function l(t){return t-48<10?t-22:t-65<26?t-65:t-97<26?t-97:g}function c(t,e){return t+22+75*(t<26)-((0!=e)<<5)}function p(t,e,n){var r=0;for(t=n?k(t/x):t>>1,t+=k(t/e);t>R*O>>1;r+=g)t=k(t/R);return k(r+(R+1)*t/(t+w))}function f(t){var e,n,r,o,a,i,h,c,f,d,m=[],y=t.length,v=0,w=_,x=C;for(n=t.lastIndexOf(P),n<0&&(n=0),r=0;r=128&&s("not-basic"),m.push(t.charCodeAt(r));for(o=n>0?n+1:0;o=y&&s("invalid-input"),c=l(t.charCodeAt(o++)),(c>=g||c>k((b-v)/i))&&s("overflow"),v+=c*i,f=h<=x?j:h>=x+O?O:h-x,!(ck(b/d)&&s("overflow"),i*=d;e=m.length+1,x=p(v-a,e,0==a),k(v/e)>b-w&&s("overflow"),w+=k(v/e),v%=e,m.splice(v++,0,w)}return u(m)}function d(t){var e,n,r,o,a,i,u,l,f,d,m,y,v,w,x,q=[];for(t=h(t),y=t.length,e=_,n=0,a=C,i=0;i=e&&mk((b-n)/v)&&s("overflow"),n+=(u-e)*v,e=u,i=0;ib&&s("overflow"),m==e){for(l=n,f=g;d=f<=a?j:f>=a+O?O:f-a,!(l= 0x80 (not a basic code point)","invalid-input":"Invalid input"},R=g-j,k=Math.floor,U=String.fromCharCode;v={version:"1.4.1",ucs2:{decode:h,encode:u},decode:f,encode:d,toASCII:y,toUnicode:m},void 0!==(o=function(){return v}.call(e,n,e,t))&&(t.exports=o)}()}).call(e,n("./node_modules/webpack/buildin/module.js")(t),n("./node_modules/webpack/buildin/global.js"))},"./node_modules/querystring-es3/decode.js":function(t,e,n){"use strict";function r(t,e){return Object.prototype.hasOwnProperty.call(t,e)}t.exports=function(t,e,n,s){e=e||"&",n=n||"=";var a={};if("string"!=typeof t||0===t.length)return a;var i=/\+/g;t=t.split(e);var h=1e3;s&&"number"==typeof s.maxKeys&&(h=s.maxKeys);var u=t.length;h>0&&u>h&&(u=h);for(var l=0;l=0?(c=m.substr(0,y),p=m.substr(y+1)):(c=m,p=""),f=decodeURIComponent(c),d=decodeURIComponent(p),r(a,f)?o(a[f])?a[f].push(d):a[f]=[a[f],d]:a[f]=d}return a};var o=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}},"./node_modules/querystring-es3/encode.js":function(t,e,n){"use strict";function r(t,e){if(t.map)return t.map(e);for(var n=[],r=0;r",'"',"`"," ","\r","\n","\t"],d=["{","}","|","\\","^","`"].concat(f),m=["'"].concat(d),y=["%","/","?",";","#"].concat(m),v=["/","?","#"],b=/^[+a-z0-9A-Z_-]{0,63}$/,g=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,j={javascript:!0,"javascript:":!0},O={javascript:!0,"javascript:":!0},w={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},x=n("./node_modules/querystring-es3/index.js");r.prototype.parse=function(t,e,n){if(!u.isString(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var r=t.indexOf("?"),o=-1!==r&&r127?F+="x":F+=U[S];if(!F.match(b)){var M=R.slice(0,P),L=R.slice(P+1),N=U.match(g);N&&(M.push(N[1]),L.unshift(N[2])),L.length&&(i="/"+L.join(".")+i),this.hostname=M.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),I||(this.hostname=h.toASCII(this.hostname));var K=this.port?":"+this.port:"",z=this.hostname||"";this.host=z+K,this.href+=this.host,I&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==i[0]&&(i="/"+i))}if(!j[d])for(var P=0,k=m.length;P0)&&n.host.split("@");_&&(n.auth=_.shift(),n.host=n.hostname=_.shift())}return n.search=t.search,n.query=t.query,u.isNull(n.pathname)&&u.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.href=n.format(),n}if(!x.length)return n.pathname=null,n.search?n.path="/"+n.search:n.path=null,n.href=n.format(),n;for(var P=x.slice(-1)[0],q=(n.host||t.host||x.length>1)&&("."===P||".."===P)||""===P,A=0,T=x.length;T>=0;T--)P=x[T],"."===P?x.splice(T,1):".."===P?(x.splice(T,1),A++):A&&(x.splice(T,1),A--);if(!g&&!j)for(;A--;A)x.unshift("..");!g||""===x[0]||x[0]&&"/"===x[0].charAt(0)||x.unshift(""),q&&"/"!==x.join("/").substr(-1)&&x.push("");var I=""===x[0]||x[0]&&"/"===x[0].charAt(0);if(C){n.hostname=n.host=I?"":x.length?x.shift():"";var _=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@");_&&(n.auth=_.shift(),n.host=n.hostname=_.shift())}return g=g||n.host&&x.length,g&&!I&&x.unshift(""),x.length?n.pathname=x.join("/"):(n.pathname=null,n.path=null),u.isNull(n.pathname)&&u.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.auth=t.auth||n.auth,n.slashes=n.slashes||t.slashes,n.href=n.format(),n},r.prototype.parseHost=function(){var t=this.host,e=c.exec(t);e&&(e=e[0],":"!==e&&(this.port=e.substr(1)),t=t.substr(0,t.length-e.length)),t&&(this.hostname=t)}},"./node_modules/url/util.js":function(t,e,n){"use strict";t.exports={isString:function(t){return"string"==typeof t},isObject:function(t){return"object"==typeof t&&null!==t},isNull:function(t){return null===t},isNullOrUndefined:function(t){return null==t}}},"./node_modules/webpack/buildin/global.js":function(t,e){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(n=window)}t.exports=n},"./node_modules/webpack/buildin/module.js":function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},0:function(t,e){t.exports=Injector},1:function(t,e){t.exports=React},2:function(t,e){t.exports=IsomorphicFetch},3:function(t,e){t.exports=ReactDom},4:function(t,e){t.exports=ReactSelect}}); \ No newline at end of file +!function(t){function e(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,e),r.l=!0,r.exports}var n={};e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,o){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:o})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s="./client/src/bundles/bundle.js")}({"./client/src/boot/index.js":function(t,e,n){"use strict";var o=n("./client/src/boot/registerComponents.js"),r=function(t){return t&&t.__esModule?t:{default:t}}(o);window.document.addEventListener("DOMContentLoaded",function(){(0,r.default)()})},"./client/src/boot/registerComponents.js":function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0});var r=n(0),s=o(r),i=n("./client/src/components/TagField.js"),a=o(i);e.default=function(){s.default.component.registerMany({TagField:a.default})}},"./client/src/bundles/bundle.js":function(t,e,n){"use strict";n("./client/src/legacy/entwine/TagField.js"),n("./client/src/boot/index.js")},"./client/src/components/TagField.js":function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function r(t,e){var n={};for(var o in t)e.indexOf(o)>=0||Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n}function s(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(e,"__esModule",{value:!0});var l=Object.assign||function(t){for(var e=1;e=e||n<0||T&&o>=g}function p(){var t=s();if(f(t))return d(t);_=setTimeout(p,c(t))}function d(t){return _=void 0,P&&y?o(t):(y=j=void 0,O)}function m(){void 0!==_&&clearTimeout(_),w=0,y=x=j=_=void 0}function v(){return void 0===_?O:d(s())}function b(){var t=s(),n=f(t);if(y=arguments,j=this,x=t,n){if(void 0===_)return h(x);if(T)return _=setTimeout(p,e),o(x)}return void 0===_&&(_=setTimeout(p,e)),O}var y,j,g,O,_,x,w=0,C=!1,T=!1,P=!0;if("function"!=typeof t)throw new TypeError(a);return e=i(e)||0,r(n)&&(C=!!n.leading,T="maxWait"in n,g=T?u(i(n.maxWait)||0,e):g,P="trailing"in n?!!n.trailing:P),b.cancel=m,b.flush=v,b}var r=n("./node_modules/lodash/isObject.js"),s=n("./node_modules/lodash/now.js"),i=n("./node_modules/lodash/toNumber.js"),a="Expected a function",u=Math.max,l=Math.min;t.exports=o},"./node_modules/lodash/isObject.js":function(t,e){function n(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}t.exports=n},"./node_modules/lodash/isObjectLike.js":function(t,e){function n(t){return null!=t&&"object"==typeof t}t.exports=n},"./node_modules/lodash/isSymbol.js":function(t,e,n){function o(t){return"symbol"==typeof t||s(t)&&r(t)==i}var r=n("./node_modules/lodash/_baseGetTag.js"),s=n("./node_modules/lodash/isObjectLike.js"),i="[object Symbol]";t.exports=o},"./node_modules/lodash/now.js":function(t,e,n){var o=n("./node_modules/lodash/_root.js"),r=function(){return o.Date.now()};t.exports=r},"./node_modules/lodash/toNumber.js":function(t,e,n){function o(t){if("number"==typeof t)return t;if(s(t))return i;if(r(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=r(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(a,"");var n=l.test(t);return n||h.test(t)?c(t.slice(2),n?2:8):u.test(t)?i:+t}var r=n("./node_modules/lodash/isObject.js"),s=n("./node_modules/lodash/isSymbol.js"),i=NaN,a=/^\s+|\s+$/g,u=/^[-+]0x[0-9a-f]+$/i,l=/^0b[01]+$/i,h=/^0o[0-7]+$/i,c=parseInt;t.exports=o},"./node_modules/punycode/punycode.js":function(t,e,n){(function(t,o){var r;!function(o){function s(t){throw new RangeError(S[t])}function i(t,e){for(var n=t.length,o=[];n--;)o[n]=e(t[n]);return o}function a(t,e){var n=t.split("@"),o="";return n.length>1&&(o=n[0]+"@",t=n[1]),t=t.replace(A,"."),o+i(t.split("."),e).join(".")}function u(t){for(var e,n,o=[],r=0,s=t.length;r=55296&&e<=56319&&r65535&&(t-=65536,e+=k(t>>>10&1023|55296),t=56320|1023&t),e+=k(t)}).join("")}function h(t){return t-48<10?t-22:t-65<26?t-65:t-97<26?t-97:j}function c(t,e){return t+22+75*(t<26)-((0!=e)<<5)}function f(t,e,n){var o=0;for(t=n?I(t/x):t>>1,t+=I(t/e);t>R*O>>1;o+=j)t=I(t/R);return I(o+(R+1)*t/(t+_))}function p(t){var e,n,o,r,i,a,u,c,p,d,m=[],v=t.length,b=0,_=C,x=w;for(n=t.lastIndexOf(T),n<0&&(n=0),o=0;o=128&&s("not-basic"),m.push(t.charCodeAt(o));for(r=n>0?n+1:0;r=v&&s("invalid-input"),c=h(t.charCodeAt(r++)),(c>=j||c>I((y-b)/a))&&s("overflow"),b+=c*a,p=u<=x?g:u>=x+O?O:u-x,!(cI(y/d)&&s("overflow"),a*=d;e=m.length+1,x=f(b-i,e,0==i),I(b/e)>y-_&&s("overflow"),_+=I(b/e),b%=e,m.splice(b++,0,_)}return l(m)}function d(t){var e,n,o,r,i,a,l,h,p,d,m,v,b,_,x,P=[];for(t=u(t),v=t.length,e=C,n=0,i=w,a=0;a=e&&mI((y-n)/b)&&s("overflow"),n+=(l-e)*b,e=l,a=0;ay&&s("overflow"),m==e){for(h=n,p=j;d=p<=i?g:p>=i+O?O:p-i,!(h= 0x80 (not a basic code point)","invalid-input":"Invalid input"},R=j-g,I=Math.floor,k=String.fromCharCode;b={version:"1.4.1",ucs2:{decode:u,encode:l},decode:p,encode:d,toASCII:v,toUnicode:m},void 0!==(r=function(){return b}.call(e,n,e,t))&&(t.exports=r)}()}).call(e,n("./node_modules/webpack/buildin/module.js")(t),n("./node_modules/webpack/buildin/global.js"))},"./node_modules/querystring-es3/decode.js":function(t,e,n){"use strict";function o(t,e){return Object.prototype.hasOwnProperty.call(t,e)}t.exports=function(t,e,n,s){e=e||"&",n=n||"=";var i={};if("string"!=typeof t||0===t.length)return i;var a=/\+/g;t=t.split(e);var u=1e3;s&&"number"==typeof s.maxKeys&&(u=s.maxKeys);var l=t.length;u>0&&l>u&&(l=u);for(var h=0;h=0?(c=m.substr(0,v),f=m.substr(v+1)):(c=m,f=""),p=decodeURIComponent(c),d=decodeURIComponent(f),o(i,p)?r(i[p])?i[p].push(d):i[p]=[i[p],d]:i[p]=d}return i};var r=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}},"./node_modules/querystring-es3/encode.js":function(t,e,n){"use strict";function o(t,e){if(t.map)return t.map(e);for(var n=[],o=0;o",'"',"`"," ","\r","\n","\t"],d=["{","}","|","\\","^","`"].concat(p),m=["'"].concat(d),v=["%","/","?",";","#"].concat(m),b=["/","?","#"],y=/^[+a-z0-9A-Z_-]{0,63}$/,j=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,g={javascript:!0,"javascript:":!0},O={javascript:!0,"javascript:":!0},_={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},x=n("./node_modules/querystring-es3/index.js");o.prototype.parse=function(t,e,n){if(!l.isString(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var o=t.indexOf("?"),r=-1!==o&&o127?U+="x":U+=k[F];if(!U.match(y)){var E=R.slice(0,T),M=R.slice(T+1),L=k.match(j);L&&(E.push(L[1]),M.unshift(L[2])),M.length&&(a="/"+M.join(".")+a),this.hostname=E.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),S||(this.hostname=u.toASCII(this.hostname));var K=this.port?":"+this.port:"",$=this.hostname||"";this.host=$+K,this.href+=this.host,S&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==a[0]&&(a="/"+a))}if(!g[d])for(var T=0,I=m.length;T0)&&n.host.split("@");C&&(n.auth=C.shift(),n.host=n.hostname=C.shift())}return n.search=t.search,n.query=t.query,l.isNull(n.pathname)&&l.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.href=n.format(),n}if(!x.length)return n.pathname=null,n.search?n.path="/"+n.search:n.path=null,n.href=n.format(),n;for(var T=x.slice(-1)[0],P=(n.host||t.host||x.length>1)&&("."===T||".."===T)||""===T,q=0,A=x.length;A>=0;A--)T=x[A],"."===T?x.splice(A,1):".."===T?(x.splice(A,1),q++):q&&(x.splice(A,1),q--);if(!j&&!g)for(;q--;q)x.unshift("..");!j||""===x[0]||x[0]&&"/"===x[0].charAt(0)||x.unshift(""),P&&"/"!==x.join("/").substr(-1)&&x.push("");var S=""===x[0]||x[0]&&"/"===x[0].charAt(0);if(w){n.hostname=n.host=S?"":x.length?x.shift():"";var C=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@");C&&(n.auth=C.shift(),n.host=n.hostname=C.shift())}return j=j||n.host&&x.length,j&&!S&&x.unshift(""),x.length?n.pathname=x.join("/"):(n.pathname=null,n.path=null),l.isNull(n.pathname)&&l.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.auth=t.auth||n.auth,n.slashes=n.slashes||t.slashes,n.href=n.format(),n},o.prototype.parseHost=function(){var t=this.host,e=c.exec(t);e&&(e=e[0],":"!==e&&(this.port=e.substr(1)),t=t.substr(0,t.length-e.length)),t&&(this.hostname=t)}},"./node_modules/url/util.js":function(t,e,n){"use strict";t.exports={isString:function(t){return"string"==typeof t},isObject:function(t){return"object"==typeof t&&null!==t},isNull:function(t){return null===t},isNullOrUndefined:function(t){return null==t}}},"./node_modules/webpack/buildin/global.js":function(t,e){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(n=window)}t.exports=n},"./node_modules/webpack/buildin/module.js":function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},0:function(t,e){t.exports=Injector},1:function(t,e){t.exports=React},2:function(t,e){t.exports=IsomorphicFetch},3:function(t,e){t.exports=ReactDom},4:function(t,e){t.exports=ReactSelect}}); \ No newline at end of file diff --git a/client/src/components/TagField.js b/client/src/components/TagField.js index af8ebcd..1aa561b 100644 --- a/client/src/components/TagField.js +++ b/client/src/components/TagField.js @@ -2,6 +2,8 @@ import React, { Component, PropTypes } from 'react'; import Select from 'react-select'; import fetch from 'isomorphic-fetch'; import url from 'url'; +// eslint-disable-next-line import/no-extraneous-dependencies +import debounce from 'lodash/debounce'; class TagField extends Component { constructor(props) { @@ -13,6 +15,7 @@ class TagField extends Component { this.onChange = this.onChange.bind(this); this.getOptions = this.getOptions.bind(this); + this.fetchOptions = debounce(this.fetchOptions, 500); } onChange(value) { @@ -26,7 +29,7 @@ class TagField extends Component { } getOptions(input) { - const { lazyLoad, options, optionUrl, labelKey, valueKey } = this.props; + const { lazyLoad, options } = this.props; if (!lazyLoad) { return Promise.resolve({ options }); @@ -36,6 +39,11 @@ class TagField extends Component { return Promise.resolve({ options: [] }); } + return this.fetchOptions(input); + } + + fetchOptions(input) { + const { optionUrl, labelKey, valueKey } = this.props; const fetchURL = url.parse(optionUrl, true); fetchURL.query.term = input; diff --git a/client/src/components/tests/TagField-test.js b/client/src/components/tests/TagField-test.js index aa00019..d756555 100644 --- a/client/src/components/tests/TagField-test.js +++ b/client/src/components/tests/TagField-test.js @@ -73,9 +73,13 @@ describe('TagField', () => { })); }); - it('should fetch the URL for results', () => { + it('should fetch the URL for results', done => { wrapper.instance().getOptions('a'); - expect(fetch).toBeCalledWith('localhost/some-fetch-url?term=a', expect.anything()); + + setTimeout(() => { + expect(fetch).toBeCalledWith('localhost/some-fetch-url?term=a', expect.anything()); + done(); + }, 500); }); }); }); diff --git a/package.json b/package.json index 9cebe79..85345b0 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "node": ">=6.x" }, "scripts": { - "build": "yarn && yarn lint && NODE_ENV=production webpack -p --bail --progress", + "build": "yarn && yarn lint && yarn test && NODE_ENV=production webpack -p --bail --progress", "dev": "NODE_ENV=development webpack --progress", "watch": "NODE_ENV=development webpack --watch --progress", "css": "WEBPACK_CHILD=css npm run build", @@ -72,6 +72,7 @@ "classnames": "^2.2.5", "isomorphic-fetch": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz", "jquery": "^3.1.1", + "lodash.debounce": "^4.0.8", "react": "15.3.1", "react-dom": "15.3.1", "react-select": "^1.0.0-rc.5",