Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

can-route

Package Overview
Dependencies
Maintainers
6
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

can-route - npm Package Compare versions

Comparing version 3.1.0-pre.2 to 3.1.0-pre.3

14

can-route.js

@@ -8,7 +8,7 @@ /*jshint -W079 */

var namespace = require('can-namespace');
var deparam = require('can-util/js/deparam/deparam');
var param = require('can-param');
var deparam = require('can-deparam');
var each = require('can-util/js/each/each');
var string = require('can-util/js/string/string');
var isFunction = require('can-util/js/is-function/is-function');
var param = require('can-util/js/param/param');
var isEmptyObject = require('can-util/js/is-empty-object/is-empty-object');

@@ -338,2 +338,10 @@ var deepAssign = require('can-util/js/deep-assign/deep-assign');

var decode = function(str){
try {
return decodeURIComponent(str);
} catch(ex) {
return unescape(str);
}
};
/**

@@ -533,3 +541,3 @@ * @static

if (part && part !== querySeparator) {
obj[route.names[i]] = decodeURIComponent(part);
obj[route.names[i]] = decode(part);
}

@@ -536,0 +544,0 @@ });

@@ -70,8 +70,24 @@ @function can-route can-route

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

@@ -111,2 +127,21 @@

### Encoded `/`
If the change in your route data includes a `/`, the `/` will be encoded into `%2F`.
You will see this result in the URL and `location.hash`.
```js
route.data.type = 'image/bar';
// OR
route.attr('type', 'image/bar');
```
The URL will look like this:
https://example.com/#!type=image%2Fbar
The location hash will look like this:
#!type=image%2Fbar
## Creating a route

@@ -113,0 +148,0 @@

{
"name": "can-route",
"version": "3.1.0-pre.2",
"version": "3.1.0-pre.3",
"description": "",

@@ -43,5 +43,7 @@ "homepage": "",

"can-compute": "^3.1.0-pre.1",
"can-deparam": "^1.0.1",
"can-event": "^3.0.1",
"can-namespace": "1.0.0",
"can-observation": "^3.2.0-pre.5",
"can-param": "^1.0.1",
"can-simple-map": "^3.2.0-pre.1",

@@ -48,0 +50,0 @@ "can-types": "^1.0.1",

@@ -99,2 +99,9 @@ /* jshint asi:true */

}, "default value and queryparams");
obj = canRoute.deparam("foo/%0g");
deepEqual(obj, {
index: "%0g",
page: "foo",
route: ":page/:index"
}, "can decode malformed urls");
});

@@ -101,0 +108,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc