nanorouter icon indicating copy to clipboard operation
nanorouter copied to clipboard

redo API

Open yoshuawuyts opened this issue 7 years ago • 4 comments

var nanorouter = require('nanorouter')

var router = nanorouter()
router.route('default', function (params) {
})

router.route('/foo/:bar', function (params) {
})

router.match(window.location)

Base it on prototypes - and that's it I think :sparkles:

yoshuawuyts avatar Jun 28 '17 14:06 yoshuawuyts

why route instead of on? (I like on since it's sort of like an event emitter -- we're going to trigger this function when this event happens. Its just that the event is the browser's URL being changed)

toddself avatar Jun 28 '17 16:06 toddself

For API parity with server-router mostly, I was thinking

On Wed, Jun 28, 2017, 18:08 Todd Kennedy [email protected] wrote:

why route instead of on? (I like on since it's sort of like an event emitter -- we're going to trigger this function when this event happens. Its just that the event is the browser's URL being changed)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/yoshuawuyts/nanorouter/issues/6#issuecomment-311708473, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWlel431qaolkluFDmiUc5vE9pA46LNks5sInprgaJpZM4OIFEb .

yoshuawuyts avatar Jun 28 '17 16:06 yoshuawuyts

Also on might imply multiple handlers would be called if you defined them, and I assume that's not the case (though maybe?).

The use of default as a route like that feels smelly to me, but not sure what to propose instead and you may have already thought about this. What if the way you defined the default route was to define a .route('*', ...) route at the very end? In theory that would work with no code changes, and is thus less API to memorise. Right? Or would it be called in addition to matched handlers..

timwis avatar Jun 28 '17 23:06 timwis

Oh, I like the wildcard thing - def makes sense (:

On Thu, Jun 29, 2017 at 1:45 AM Tim Wisniewski [email protected] wrote:

Also on might imply multiple handlers would be called if you defined them, and I assume that's not the case (though maybe?).

The use of default as a route like that feels smelly to me, but not sure what to propose instead and you may have already thought about this. What if the way you defined the default route was to define a .route('*', ...) route at the very end? In theory that would work with no code changes, and is thus less API to memorise. Right? Or would it be called in addition to matched handlers..

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/yoshuawuyts/nanorouter/issues/6#issuecomment-311822691, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWleo7B0nePacFYgzC1vLzoI6S4Si1xks5sIuWsgaJpZM4OIFEb .

yoshuawuyts avatar Jun 29 '17 00:06 yoshuawuyts