Side effects in js-data-http adapter

Demonstration of how passing the same options variable into two different queries can have unexpected results.

by Michael Underwood

HTML

<script src="https://github.com/js-data/js-data/releases/download/3.0.2/js-data.js"></script>
<script src="https://github.com/js-data/js-data-http/releases/download/3.0.0/js-data-http.js"></script>
<h1>Open the console...</h1>
<p>
  ...and see that even though the first query is for userId 2 and the second for userId 4, both resultsets are for userId 4.
</p>

JavaScript

// https://github.com/js-data/js-data/releases/download/3.0.2/js-data.js
// https://github.com/js-data/js-data-http/releases/download/3.0.0/js-data-http.js
console.log('js-data v%s', JSData.version.full)
console.log('js-data-http v%s', JSDataHttp.version.full)

const store = new JSData.DataStore();
const httpAdapter = new JSDataHttp.HttpAdapter({
	basePath: 'https://jsonplaceholder.typicode.com',
});
store.registerAdapter('http', httpAdapter, { default: true });
store.defineMapper('post', { endpoint: 'posts' });

const opts = { force: true };
store.findAll('post', { userId: 2 }, opts).then(console.log);
store.findAll('post', { userId: 4 }, opts).then(console.log);