@@ -58,15 +58,15 @@ var LogBehaviours = {};
58
58
59
59
var compareRoutes = function ( route1 , route2 ) {
60
60
61
- var route = ( route1 && route1 . name && route1 . name . indexOf ( ':' ) > - 1 && route1 ) || route2 ;
61
+ var route = ( route1 && route1 . path && route1 . path . indexOf ( ':' ) > - 1 && route1 ) || route2 ;
62
62
if ( route === route2 ) {
63
63
64
64
route2 = route1 ;
65
65
route1 = route ;
66
66
}
67
- if ( route && route . name ) route = new Route ( route . name ) ;
68
- return ( route && route . match ( ( route2 && route2 . name ) || ' ' ) ||
69
- route1 . name === ( route2 && route2 . name ) ) &&
67
+ if ( route && route . path ) route = new Route ( route . path ) ;
68
+ return ( route && route . match ( ( route2 && route2 . path ) || ' ' ) ||
69
+ route1 . path === ( route2 && route2 . path ) ) &&
70
70
( route1 . method || '' ) . toLowerCase ( ) === ( ( route2 && route2 . method ) || '' ) . toLowerCase ( ) ;
71
71
} ;
72
72
@@ -115,12 +115,12 @@ backend.behaviour = function (path, config) {
115
115
throw new Error ( 'Invalid constructor' ) ;
116
116
}
117
117
var named = typeof options . name === 'string' && options . name . length > 0 ;
118
+ var skipSameRoutes ;
118
119
var unduplicated = function ( ) {
119
120
120
- var skipSameRoutes ;
121
121
if ( typeof config === 'object' ) skipSameRoutes = config . skipSameRoutes ;
122
- if ( behaviours [ options . name ] && ( typeof skipSameRoutes !== 'boolean' ||
123
- ! skipSameRoutes ) ) throw new Error ( 'Duplicated behavior name: ' + options . name ) ;
122
+ if ( behaviours [ options . name ] && skipSameRoutes !== true )
123
+ throw new Error ( 'Duplicated behavior name: ' + options . name ) ;
124
124
return ! behaviours [ options . name ] ;
125
125
} ( ) ;
126
126
var BehaviourConstructor = define ( getConstructor ) . extend ( getLogBehaviour ( options , config ,
@@ -294,24 +294,26 @@ backend.behaviour = function (path, config) {
294
294
295
295
return {
296
296
297
- name : ( behaviours [ name ] && behaviours [ name ] . path ) || name ,
297
+ name : name ,
298
+ path : behaviours [ name ] && behaviours [ name ] . path ,
298
299
method : behaviours [ name ] && behaviours [ name ] . method
299
300
} ;
300
301
} ) . filter ( function ( opt ) {
301
302
302
- var suffix = opt . name ;
303
+ var name = opt . name ;
304
+ var suffix = opt . path ;
303
305
var method = opt . method ;
304
306
var route = typeof prefix === 'string' &&
305
307
request . path . startsWith ( prefix ) &&
306
308
typeof suffix === 'string' ?
307
309
join ( prefix , suffix ) : suffix || prefix ;
308
- return compareRoutes ( {
310
+ return name === options . name && compareRoutes ( {
309
311
310
- name : route ,
312
+ path : route ,
311
313
method : method
312
314
} , {
313
315
314
- name : request . path ,
316
+ path : request . path ,
315
317
method : request . method
316
318
} ) ;
317
319
} ) . length > 0 ;
@@ -326,15 +328,15 @@ backend.behaviour = function (path, config) {
326
328
if ( isRoute ) {
327
329
328
330
var keys = Object . keys ( behaviours ) ;
329
- if ( keys . some ( function ( key ) {
331
+ if ( ! skipSameRoutes && keys . some ( function ( key ) {
330
332
331
333
return compareRoutes ( {
332
334
333
- name : behaviours [ key ] . path ,
335
+ path : behaviours [ key ] . path ,
334
336
method : behaviours [ key ] . method
335
337
} , {
336
338
337
- name : options . path ,
339
+ path : options . path ,
338
340
method : options . method
339
341
} ) ;
340
342
} ) ) throw new Error ( 'Duplicated behavior path: ' + options . path ) ;
0 commit comments