Skip to content

Commit

Permalink
feat(all): more type info
Browse files Browse the repository at this point in the history
  • Loading branch information
EisenbergEffect committed Aug 14, 2015
1 parent 32b18de commit e11312e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
22 changes: 11 additions & 11 deletions src/interfaces.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
interface RouteHandler {
name:string;
name: string;
}

interface ConfigurableRoute {
path:string;
handler:RouteHandler;
path: string;
handler: RouteHandler;
}

interface HandlerEntry {
handler:RouteHandler;
names:string[];
handler: RouteHandler;
names: string[];
}

interface RecognizedRoute {
handler:RouteHandler;
params:Object;
isDynamic:boolean;
handler: RouteHandler;
params: Object;
isDynamic: boolean;
}

interface CharSpec {
invalidChars?:string;
validChars?:string;
repeat?:boolean;
invalidChars?: string;
validChars?: string;
repeat?: boolean;
}
16 changes: 8 additions & 8 deletions src/route-recognizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class RouteRecognizer {
* @method add
* @param {Object} route The route to add.
*/
add(route:ConfigurableRoute|ConfigurableRoute[]):State {
add(route: ConfigurableRoute|ConfigurableRoute[]): State {
if (Array.isArray(route)) {
for (let r of route) {
this.add(r);
Expand Down Expand Up @@ -84,7 +84,7 @@ export class RouteRecognizer {
* @param {String} name The name of the route.
* @return {Array} The handlers.
*/
handlersFor(name:string):HandlerEntry[] {
handlersFor(name: string): HandlerEntry[] {
var route = this.names[name],
result = [];

Expand All @@ -106,7 +106,7 @@ export class RouteRecognizer {
* @param {String} name The name of the route.
* @return {Boolean} True if the named route is recognized.
*/
hasRoute(name:string):boolean {
hasRoute(name: string): boolean {
return !!this.names[name];
}

Expand All @@ -119,7 +119,7 @@ export class RouteRecognizer {
* Properties not required by the pattern will be appended to the query string.
* @return {String} The generated absolute path and query string.
*/
generate(name:string, params:Object):string {
generate(name: string, params: Object): string {
params = Object.assign({}, params);

var route = this.names[name],
Expand Down Expand Up @@ -168,7 +168,7 @@ export class RouteRecognizer {
* @param {Object} params Object containing the keys and values to be used.
* @return {String} The generated query string, including leading '?'.
*/
generateQueryString(params:Object):string {
generateQueryString(params: Object): string {
var pairs = [], keys = [], encode = encodeURIComponent,
encodeKey = k => encode(k).replace('%24', '$');

Expand Down Expand Up @@ -210,7 +210,7 @@ export class RouteRecognizer {
* @param {String} The query string to parse.
* @return {Object} Object with keys and values mapped from the query string.
*/
parseQueryString(queryString:string):Object {
parseQueryString(queryString: string): Object {
var queryParams = {};
if (!queryString || typeof queryString !== 'string') {
return queryParams;
Expand Down Expand Up @@ -261,7 +261,7 @@ export class RouteRecognizer {
* `isDynanic` values for the matched route(s), or undefined if no match
* was found.
*/
recognize(path:string):RecognizedRoute[] {
recognize(path: string): RecognizedRoute[] {
var states = [ this.rootState ],
pathLen, i, l, queryStart, queryParams = {},
isSlashDropped = false;
Expand Down Expand Up @@ -314,7 +314,7 @@ export class RouteRecognizer {
}
class RecognizeResults {
constructor(queryParams:Object) {
constructor(queryParams: Object) {
this.splice = Array.prototype.splice;
this.slice = Array.prototype.slice;
this.push = Array.prototype.push;
Expand Down
28 changes: 14 additions & 14 deletions src/segments.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,61 +27,61 @@ export class StaticSegment {
this.string = string;
}

eachChar(callback:(spec:CharSpec) => void) {
eachChar(callback: (spec:CharSpec) => void): void {
for (let ch of this.string) {
callback({ validChars: ch });
}
}

regex():string {
regex(): string {
return this.string.replace(escapeRegex, '\\$1');
}

generate(params:Object, consumed:Object):string {
generate(params:Object, consumed:Object): string {
return this.string;
}
}

export class DynamicSegment {
constructor(name:string) {
constructor(name: string) {
this.name = name;
}

eachChar(callback:(spec:CharSpec) => void) {
eachChar(callback:(spec :CharSpec) => void): void {
callback({ invalidChars: '/', repeat: true });
}

regex():string {
regex(): string {
return '([^/]+)';
}

generate(params:Object, consumed:Object):string {
generate(params: Object, consumed: Object): string {
consumed[this.name] = true;
return params[this.name];
}
}

export class StarSegment {
constructor(name:string) {
constructor(name: string) {
this.name = name;
}

eachChar(callback:(spec:CharSpec) => void) {
eachChar(callback: (spec:CharSpec) => void): void {
callback({ invalidChars: '', repeat: true });
}

regex():string {
regex(): string {
return '(.+)';
}

generate(params:Object, consumed:Object):string {
generate(params: Object, consumed: Object): string {
consumed[this.name] = true;
return params[this.name];
}
}

export class EpsilonSegment {
eachChar(callback:(spec:CharSpec) => void) {}
regex():string { return ''; }
generate(params:Object, consumed:Object):string { return ''; }
eachChar(callback: (spec:CharSpec) => void): void {}
regex(): string { return ''; }
generate(params: Object, consumed: Object): string { return ''; }
}
8 changes: 4 additions & 4 deletions src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
// implementation would use a hash of keys pointing at one or more next states.

export class State {
constructor(charSpec:CharSpec) {
constructor(charSpec: CharSpec) {
this.charSpec = charSpec;
this.nextStates = [];
}

get(charSpec:CharSpec):State {
get(charSpec: CharSpec): State {
for (let child of this.nextStates) {
var isEqual = child.charSpec.validChars === charSpec.validChars &&
child.charSpec.invalidChars === charSpec.invalidChars;
Expand All @@ -32,7 +32,7 @@ export class State {
}
}

put(charSpec:CharSpec):State {
put(charSpec: CharSpec): State {
var state = this.get(charSpec);

// If the character specification already exists in a child of the current
Expand All @@ -59,7 +59,7 @@ export class State {
}

// Find a list of child states matching the next character
match(ch:string):State[] {
match(ch: string): State[] {
var nextStates = this.nextStates, results = [],
child, charSpec, chars;

Expand Down

0 comments on commit e11312e

Please sign in to comment.