Skip to content

Commit 819ab75

Browse files
committed
active.route refactoring
1 parent 91c118a commit 819ab75

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

client/active.route.js

+25-19
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,26 @@ const init = (FlowRouter) => {
4747
disabledClass: 'disabled'
4848
});
4949

50-
const test = (value, pattern) => {
51-
let result;
50+
const test = (_value, _pattern) => {
51+
let value = _value;
52+
let pattern = _pattern;
5253
if (!value) {
5354
return false;
5455
}
56+
5557
if (Match.test(pattern, RegExp)) {
56-
result = value.search(pattern);
57-
result = result > -1;
58-
} else if (Match.test(pattern, String)) {
58+
return value.search(pattern) > -1;
59+
}
60+
61+
if (Match.test(pattern, String)) {
5962
if (config.equals('caseSensitive', false)) {
6063
value = value.toLowerCase();
6164
pattern = pattern.toLowerCase();
6265
}
63-
result = (value === pattern);
66+
return (value === pattern);
6467
}
65-
return (result != null) ? result : false;
68+
69+
return false;
6670
};
6771

6872
const ActiveRoute = {
@@ -114,9 +118,9 @@ const init = (FlowRouter) => {
114118
}
115119
helperName += 'Active' + type;
116120

117-
return (options = {}, attributes = {}) => {
118-
options = (_.isObject(options)) ? (options.hash || options) : options;
119-
attributes = (_.isObject(attributes)) ? (attributes.hash || attributes) : attributes;
121+
return (_options = {}, _attributes = {}) => {
122+
let options = (_.isObject(_options)) ? (_options.hash || _options) : _options;
123+
let attributes = (_.isObject(_attributes)) ? (_attributes.hash || _attributes) : _attributes;
120124

121125
if (Match.test(options, String)) {
122126
if (config.equals('regex', true)) {
@@ -167,16 +171,16 @@ const init = (FlowRouter) => {
167171
}
168172
}
169173

170-
if (regex == null) {
174+
if (!_.isRegExp(regex)) {
171175
regex = name || path;
172176
}
173177

174178
if (inverse) {
175-
if (className == null) {
179+
if (!_.isString(className)) {
176180
className = config.get('disabledClass');
177181
}
178182
} else {
179-
if (className == null) {
183+
if (!_.isString(className)) {
180184
className = config.get('activeClass');
181185
}
182186
}
@@ -220,8 +224,8 @@ const init = (FlowRouter) => {
220224
// arillo:flow-router-helpers
221225
// https://github.com/arillo/meteor-flow-router-helpers
222226
// License (MIT License): https://github.com/arillo/meteor-flow-router-helpers/blob/master/LICENCE
223-
const subsReady = (...subs) => {
224-
subs = subs.slice(0, -1);
227+
const subsReady = (..._subs) => {
228+
let subs = _subs.slice(0, -1);
225229
if (subs.length === 1) {
226230
return FlowRouter.subsReady();
227231
}
@@ -233,7 +237,9 @@ const init = (FlowRouter) => {
233237
}, true);
234238
};
235239

236-
const pathFor = (path, view = {hash: {}}) => {
240+
const pathFor = (_path, _view = {hash: {}}) => {
241+
let path = _path;
242+
let view = _view;
237243
if (!path) {
238244
throw new Error('no path defined');
239245
}
@@ -244,12 +250,12 @@ const init = (FlowRouter) => {
244250
};
245251
}
246252

247-
if (path.hash && path.hash.route != null) {
253+
if (path.hash && path.hash.route) {
248254
view = path;
249255
path = view.hash.route;
250256
delete view.hash.route;
251257
}
252-
const query = view.hash.query ? FlowRouter._qs.parse(view.hash.query) : {};
258+
const query = view.hash.query ? FlowRouter._qs.parse(view.hash.query) : {};
253259
const hashBang = view.hash.hash ? view.hash.hash : '';
254260
return FlowRouter.path(path, view.hash, query) + (hashBang ? '#' + hashBang : '');
255261
};
@@ -305,7 +311,7 @@ const init = (FlowRouter) => {
305311
}
306312
}
307313

308-
return _.extend(ActiveRoute, FlowRouterHelpers);
314+
return Object.assign({}, ActiveRoute, FlowRouterHelpers);
309315
};
310316

311317
export default init;

0 commit comments

Comments
 (0)