document querystring support in routes

This commit is contained in:
Leo Horie 2014-05-25 15:37:53 -04:00
parent d4cb7959d4
commit 38634a0292
4 changed files with 26 additions and 5 deletions

View file

@ -6,7 +6,7 @@ This page aims to provide a comparison between Mithril and some of the most wide
### Code Size
One of the most obvious differences between Mithril and most frameworks is in file size: Mithril is less than 3kb gzipped and has no dependencies on other libraries.
One of the most obvious differences between Mithril and most frameworks is in file size: Mithril is around 4kb gzipped and has no dependencies on other libraries.
Note that while a small gzipped size can look appealing, that number is often used to "hide the weight" of the uncompressed code: remember that the decompressed Javascript still needs to be parsed and evaluated on every page load, and this cost (which can be in the dozens of milliseconds range for some frameworks in some browsers) cannot be cached.

View file

@ -4,7 +4,7 @@
Mithril is a client-side Javascript MVC framework, i.e. it's a tool to make application code divided into a data layer (called "**M**odel"), a UI layer (called **V**iew), and a glue layer (called **C**ontroller)
Mithril is around 3kb gzipped thanks to its [small, focused, API](mithril.md). It provides a templating engine with a virtual DOM diff implementation for performant rendering, utilities for high-level modelling via functional composition, as well as support for routing and componentization.
Mithril is around 4kb gzipped thanks to its [small, focused, API](mithril.md). It provides a templating engine with a virtual DOM diff implementation for performant rendering, utilities for high-level modelling via functional composition, as well as support for routing and componentization.
The goal of the framework is to make application code discoverable, readable and maintainable, and hopefully help you become an even better developer.

View file

@ -47,7 +47,7 @@
<div class="feature col(4,4,12)">
<h2>Light-weight</h2>
<ul>
<li>Only 3kb gzipped, no dependencies</li>
<li>Only 4kb gzipped, no dependencies</li>
<li>Small API, small learning curve</li>
</ul>
</div>

View file

@ -74,6 +74,8 @@ The string `johndoe` is bound to the `:userID` parameter, which can be retrived
The `m.route.mode` defines which part of the URL to use for routing.
---
#### Variadic routes
We can append an ellipsis (`...`) to the name of a route argument to allow it to match URL snippets that contain slashes:
@ -107,7 +109,22 @@ m.route.param("date") === "archive/2014"
//the routes should be flipped around to get `m.route.param("year") == "2014"`
```
### Running clean up code on route change
---
#### Routes with querystrings
In addition to route parameters, it's possible to pass arbitrary data to `m.route.param` using the querystring
```javascript
m.route("/grid?sortby=date&dir=desc")
var sortBy = m.route.param("sortby") // "date"
var dir = m.route.param("dir") // "desc"
```
---
#### Running clean up code on route change
If a module's controller implements an instance method called `onunload`, this method will be called when a route changes.
@ -208,10 +225,14 @@ where:
A route with parameters might look like this:
`"/path/to/page/:id"` - here `id` is the name of the route parameter
`"/path/to/page/:id"` - here, `id` is the name of the route parameter
If the currently active route is `/dashboard/:userID` and the current URL is `/dashboard/johndoe`, then calling `m.route.param("userID")` returns `"johndoe"`
Querystring parameters in a route are also available in this collection automatically.
`"/grid?sortby=date"` - here, `m.route.param("sortby")` returns `"date"`
- **String key**
The name of a route parameter