Skip to content

Commit

Permalink
Merge pull request #74 from canjs/add-app-state-example
Browse files Browse the repository at this point in the history
Added setting AppState example related to canjs/canjs#3208
  • Loading branch information
imaustink committed May 22, 2017
2 parents 0cabdd3 + 1d1e244 commit 7062ef3
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions can-route.md
Expand Up @@ -67,11 +67,27 @@ can-route keeps the state of the hash in-sync with the `data` contained within i

## data

Underlying can-route is an observable map: `route.data`. Depending on what type of map your application uses this could be a [can-map], a [can-define/map/map], or maybe even a [can-simple-map].
Underlying `can-route` is an observable map: `route.data`. Depending on what type of map your application uses this could be a [can-map], a [can-define/map/map], or maybe even a [can-simple-map].

Understanding how maps work is essential to understanding can-route.
Here’s an example using [can-define/map/map DefineMap] to back `can-route`:

You can listen to changes in a map with `on(eventName, handler(ev, args...))` and change can-route's properties by modifying `route.data`.
```js
var DefineMap = require("can-define/map/map");
var route = require("can-route");

var AppViewModel = DefineMap.extend({
page: "string"
});

var appState = new AppViewModel();
route.data = appState;
route('{page}', {page: 'home'});
route.ready();
```

Understanding how maps work is essential to understanding `can-route`.

You can listen to changes in a map with `on(eventName, handler(ev, args...))` and change `can-route`’s properties by modifying `route.data`.

### Listening to changes in can-route

Expand Down

0 comments on commit 7062ef3

Please sign in to comment.