Removed unnecessary urlQuery(), expose qs instead

The asset-admin module uses a simpler algo now
This commit is contained in:
Ingo Schommer 2017-01-05 16:31:50 +13:00 committed by Damian Mooyman
parent 9e8e6314da
commit f755c393a4
4 changed files with 3 additions and 42 deletions

View File

@ -32,6 +32,7 @@ require('expose?ApolloClient!apollo-client');
require('expose?ReactApollo!react-apollo');
require('expose?GraphQLTag!graphql-tag');
require('expose?GraphQLFragments!graphql-fragments');
require('expose?qs!qs');
require('../../../thirdparty/jquery-ondemand/jquery.ondemand.js');
require('../../../thirdparty/jquery-ui/jquery-ui.js');

View File

@ -1,32 +1,6 @@
import i18n from 'i18n';
import qs from 'qs';
/**
* Merge existing querystring with new querystring object.
* Does not deep merge.
*
* Example:
* `urlQuery({ foo: 1 }, { bar: 2 })` returns `'?foo=1&bar=2'`
*
* @param {Object} locationQuery - Current browser querystring object (window.location.query)
* @param {Object} newQuery - New object to update. Set to null to clear instead of merge.
* @returns {String}
*/
export function urlQuery(locationQuery, newQuery) {
if (newQuery === null) {
return '';
}
let mergedQuery = locationQuery || {};
if (newQuery) {
mergedQuery = Object.assign({}, mergedQuery, newQuery);
}
const query = qs.stringify(mergedQuery);
if (query) {
return `?${query}`;
}
return '';
}
/**
* Turn flatterned querystring object into recursive nested objects,
* similarly to how PHP handles nested querystring objects.

View File

@ -6,26 +6,11 @@ jest.unmock('../DataFormat');
jest.unmock('qs');
jest.unmock('merge');
import { urlQuery, decodeQuery } from '../DataFormat';
import { decodeQuery } from '../DataFormat';
describe('DataFormat', () => {
describe('urlQuery()', () => {
it('should return empty string when no newQuery is given', () => {
expect(urlQuery({}, null)).toBe('');
});
it('should add new keys', () => {
expect(urlQuery({ foo: 1 }, { bar: 2 })).toBe('?foo=1&bar=2');
});
it('should overwrite existing keys', () => {
expect(urlQuery({ foo: 1 }, { foo: 2 })).toBe('?foo=2');
});
it('should not deep merge nested keys', () => {
expect(urlQuery({ foo: { bar: 1 } }, { foo: { baz: 2 } })).toBe('?foo%5Bbaz%5D=2');
});
});
describe('decodeQuery', () => {
it('should decode flat keys', () => {
expect(decodeQuery('?foo=1')).toEqual({ foo: '1' });

View File

@ -97,6 +97,7 @@ const config = [
redux: 'Redux',
config: 'Config',
'lib/Router': 'Router',
qs: 'qs',
},
module: {
loaders: [