From 38634a02927da4f9c96254e18914134ce801204f Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Sun, 25 May 2014 15:37:53 -0400 Subject: [PATCH] document querystring support in routes --- docs/comparison.md | 2 +- docs/getting-started.md | 2 +- docs/layout/index.html | 2 +- docs/mithril.route.md | 25 +++++++++++++++++++++++-- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/docs/comparison.md b/docs/comparison.md index 20a0dbb5..4366842f 100644 --- a/docs/comparison.md +++ b/docs/comparison.md @@ -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. diff --git a/docs/getting-started.md b/docs/getting-started.md index 1f11a1ea..cec324de 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -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. diff --git a/docs/layout/index.html b/docs/layout/index.html index cfc9e3af..112994ab 100644 --- a/docs/layout/index.html +++ b/docs/layout/index.html @@ -47,7 +47,7 @@

Light-weight

diff --git a/docs/mithril.route.md b/docs/mithril.route.md index 90c868a8..2409cce1 100644 --- a/docs/mithril.route.md +++ b/docs/mithril.route.md @@ -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