Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved route matching into a separate method named parseToken. #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,11 @@ Ext.define('Ext.ux.Router', {

/**
* Receives a url token and goes trough each of of the defined route objects searching
* for a match.
* for a match. If a match is found an object is returned with the fields route, token and params.
* If no match is found false is returned.
* @private
*/
parse: function(token) {
parseToken: function(token) {
var route, matches, params, names, j, param, value, rules,
tokenArgs, tokenWithoutArgs,
me = this,
Expand All @@ -236,10 +237,7 @@ Ext.define('Ext.ux.Router', {

if (matches) {
matches = matches.slice(1);

if (me.dispatch(token, route, matches)) {
return { captures: matches };
}
return {route:route, token:token, params:matches};
}
}
else {
Expand Down Expand Up @@ -272,13 +270,34 @@ Ext.define('Ext.ux.Router', {
params = Ext.applyIf(params, Ext.Object.fromQueryString(tokenArgs));
}

if (matches && me.dispatch(token, route, params)) {
return params;
if (matches) {
return {route:route, token:token, params:params};
}
}
}

}


return false;
},

/**
* Receives a url token and goes trough each of of the defined route objects searching
* for a match. If a route is found it is dispatched and returned, else false is returned.
* @private
*/
parse: function(token) {
var me = this;
var data = me.parseToken(token);

if(data && me.dispatch(data.token, data.route, data.params)) {
if(data.route.regex) {
return { captures: data.params};
} else {
return data.params;
}
}

me.fireEvent('routemissed', token);
return false;
},
Expand Down Expand Up @@ -402,4 +421,4 @@ function() {
}
}
});
});
});