Skip to content

Commit

Permalink
upgrade first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
joemcelroy committed Feb 20, 2017
1 parent 86e9242 commit 508faad
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 61 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -71,7 +71,7 @@
"es6-promise": "^3.1.2",
"history": "^2.1.1",
"lodash": "4.14.2",
"qs": "ssetem/qs",
"qs": "joemcelroy/qs",
"rc-slider": "5.4.3",
"react-addons-update": "^15.4.0"
},
Expand Down
42 changes: 0 additions & 42 deletions release/bundle.js

This file was deleted.

11 changes: 0 additions & 11 deletions release/theme.css

This file was deleted.

12 changes: 12 additions & 0 deletions src/__test__/core/history/HistorySpec.ts
@@ -0,0 +1,12 @@
import { encodeObjUrl, decodeObjString } from '../../../core/history'

describe("qs", () => {

it("encode / decode searchkit obj", () => {
const obj = {q: "test", categories: [["movie"],["Crime"]], actors: ["a", 'b-c', 'd & e', 'f=g'], writers: ['d'] }
const str = encodeObjUrl(obj)
expect(str).toEqual('q=test&categories[0][0]=movie&categories[1][0]=Crime&actors[0]=a&actors[1]=b-c&actors[2]=d%20%26%20e&actors[3]=f%3Dg&writers[0]=d')
expect(decodeObjString(str)).toEqual(obj)
})

})
15 changes: 13 additions & 2 deletions src/core/history.ts
@@ -1,13 +1,24 @@
import { createHistory, useQueries, History, HistoryQueries } from 'history'
const qs = require("qs")
const qsUtils = require("qs/lib/utils")

export const encodeObjUrl = (obj) => {
return qs.stringify(obj, { encode: true, encoder: (str, isPrefix) => {
return isPrefix ? str : qsUtils.encode(str)
}})
}

export const decodeObjString = (str) => {
return qs.parse(str)
}

export const createHistoryInstance = function(){
return useQueries(createHistory)({
stringifyQuery(ob){
return qs.stringify(ob, {encode:true})
return encodeObjUrl(ob)
},
parseQueryString(str){
return qs.parse(str)
return decodeObjString(str)
}
})
}
1 change: 1 addition & 0 deletions tsconfig.json
Expand Up @@ -121,6 +121,7 @@
"./src/__test__/core/accessors/StatefulAccessorSpec.ts",
"./src/__test__/core/accessors/SuggestionsAccessorSpec.ts",
"./src/__test__/core/accessors/ViewOptionsAccessorSpec.ts",
"./src/__test__/core/history/HistorySpec.ts",
"./src/__test__/core/query/field_context/ChildrenFieldContext.unit.ts",
"./src/__test__/core/query/field_context/EmbeddedFieldContext.unit.ts",
"./src/__test__/core/query/field_context/NestedFieldContext.unit.ts",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Expand Up @@ -908,7 +908,7 @@ debug@0.7.4:
version "0.7.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-0.7.4.tgz#06e1ea8082c2cb14e39806e22e2f6f757f92af39"

debug@2, debug@2.6.1, debug@^2.2.0:
debug@2, debug@2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.1.tgz#79855090ba2c4e3115cc7d8769491d58f0491351"
dependencies:
Expand All @@ -920,7 +920,7 @@ debug@2.2.0, debug@~2.2.0:
dependencies:
ms "0.7.1"

debug@2.3.3:
debug@2.3.3, debug@^2.2.0:
version "2.3.3"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.3.3.tgz#40c453e67e6e13c901ddec317af8986cda9eff8c"
dependencies:
Expand Down Expand Up @@ -3440,9 +3440,9 @@ qs@6.2.1:
version "6.2.1"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.2.1.tgz#ce03c5ff0935bc1d9d69a9f14cbd18e568d67625"

qs@ssetem/qs:
version "6.0.1"
resolved "https://codeload.github.com/ssetem/qs/tar.gz/fb2b80ac750fa375e0d69643adb0840e7e04d1d3"
qs@joemcelroy/qs:
version "6.3.1"
resolved "https://codeload.github.com/joemcelroy/qs/tar.gz/b21ade9637aa34b11b85a9d220b58404b707e70b"

qs@~6.3.0:
version "6.3.0"
Expand Down

0 comments on commit 508faad

Please sign in to comment.