Skip to content
This repository was archived by the owner on Dec 28, 2019. It is now read-only.

Commit 7b87dff

Browse files
committed
Small changes
1 parent f8e4d66 commit 7b87dff

File tree

3 files changed

+41
-32
lines changed

3 files changed

+41
-32
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ node_modules
33
package-lock.json
44
location
55
react
6-
routes
6+
routes
7+
design.js

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.DS_Store
2-
node_modules
2+
node_modules
3+
design.js

src/location/index.js

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ export function createLocation(url, object, prop = 'location') {
7575
pushState(href)
7676
setHref(getWindowLocation(), mutation)
7777
} else if (mutation.prop === 'query') {
78-
let href,
79-
prop,
80-
query = mutation.value,
81-
search = []
82-
for (prop in query)
78+
let href
79+
let prop
80+
let query = mutation.value
81+
let search = []
82+
for (prop in query) {
8383
search.push(enc(prop) + '=' + enc(query[prop]))
84+
}
8485

8586
href =
8687
location.pathname + '?' + search.join('&') + location.hash
@@ -113,18 +114,20 @@ export function createLocation(url, object, prop = 'location') {
113114

114115
intercept(location.query, (mutation, object) => {
115116
if (!shallWeEmit) {
116-
let href,
117-
query = location.query,
118-
search = [],
119-
prop = mutation.prop
117+
let href
118+
let query = location.query
119+
let search = []
120+
let prop = mutation.prop
120121
// Is true if is not a delete
121122
if (mutation.hasOwnProperty('value')) {
122123
let propenc = enc(mutation.prop)
123124
let valueenc = enc(mutation.value)
124125
delete object[mutation.prop]
125126
object[propenc] = valueenc
126127
}
127-
for (prop in query) search.push(prop + '=' + query[prop])
128+
for (prop in query) {
129+
search.push(prop + '=' + query[prop])
130+
}
128131
href = location.pathname + '?' + search.join('&') + location.hash
129132

130133
pushState(href)
@@ -151,11 +154,15 @@ export function createLocation(url, object, prop = 'location') {
151154
set(location.path, 'length', newlocation.path.length)
152155

153156
// query
154-
let prop,
155-
newquery = newlocation.query,
156-
query = location.query
157-
for (prop in newquery) set(query, prop, newquery[prop])
158-
for (prop in query) if (!newquery.hasOwnProperty(prop)) del(query, prop)
157+
let prop
158+
let newquery = newlocation.query
159+
let query = location.query
160+
for (prop in newquery) {
161+
set(query, prop, newquery[prop])
162+
}
163+
for (prop in query) {
164+
if (!newquery.hasOwnProperty(prop)) del(query, prop)
165+
}
159166

160167
// emit
161168
shallWeEmit = false
@@ -186,21 +193,21 @@ function getHref(location) {
186193
}
187194

188195
function parse(url) {
189-
let match = /((.*):\/\/([^/#?]+))?([^?#]*)([^#]*)(.*)?/.exec(
190-
decodeURIComponent(url)
191-
),
192-
query = {},
193-
location = {
194-
url: url,
195-
origin: match[1],
196-
protocol: match[2],
197-
host: match[3],
198-
pathname: match[4] === '' ? '/' : match[4],
199-
path: match[4].split('/').filter(item => item.length > 0),
200-
search: match[5],
201-
query: query,
202-
hash: match[6] || ''
203-
}
196+
const match = /((.*):\/\/([^/#?]+))?([^?#]*)([^#]*)(.*)?/.exec(
197+
decodeURIComponent(url)
198+
)
199+
const query = {}
200+
const location = {
201+
url: url,
202+
origin: match[1],
203+
protocol: match[2],
204+
host: match[3],
205+
pathname: match[4] === '' ? '/' : match[4],
206+
path: match[4].split('/').filter(item => item.length > 0),
207+
search: match[5],
208+
query: query,
209+
hash: match[6] || ''
210+
}
204211

205212
location.href = getHref(location)
206213

0 commit comments

Comments
 (0)