@angular-wave/angular.ts 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/angular-ts.esm.js +1 -1
- package/dist/angular-ts.umd.js +1 -1
- package/package.json +1 -1
- package/src/exts/messages.md +30 -30
- package/src/index.js +1 -0
- package/src/router/adapter/locationServices.js +3 -5
- package/src/router/adapter/services.js +10 -16
- package/src/router/core/common/common.js +1 -11
- package/src/router/core/hooks/coreResolvables.js +2 -2
- package/src/router/core/path/pathUtils.js +1 -2
- package/src/router/core/router.js +4 -2
- package/src/router/core/state/stateBuilder.js +2 -3
- package/src/router/core/state/stateMatcher.js +1 -2
- package/src/router/core/state/stateObject.js +5 -4
- package/src/router/core/state/stateQueueManager.js +1 -1
- package/src/router/core/transition/hookRegistry.js +3 -10
- package/src/router/core/transition/transitionService.js +2 -2
- package/src/router/router.js +18 -12
- package/test/module-test.html +6 -2
- package/test/module-test.js +0 -0
- package/src/router/adapter/urlRouterProvider.js +0 -196
- package/src/router/core/vanilla/baseLocationService.js +0 -31
- package/src/router/core/vanilla/browserLocationConfig.js +0 -42
- package/src/router/core/vanilla/hashLocationService.js +0 -19
- package/src/router/core/vanilla/injector.js +0 -98
- package/src/router/core/vanilla/interface.js +0 -1
- package/src/router/core/vanilla/memoryLocationConfig.js +0 -20
- package/src/router/core/vanilla/memoryLocationService.js +0 -13
- package/src/router/core/vanilla/plugins.js +0 -35
- package/src/router/core/vanilla/pushStateLocationService.js +0 -69
- package/src/router/core/vanilla/q.js +0 -54
- package/src/router/core/vanilla/utils.js +0 -63
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { deregAll, isDefined, removeFrom, root } from "../common/index";
|
|
2
|
-
import { buildUrl, getParams, parseUrl } from "./utils";
|
|
3
|
-
/** A base `LocationServices` */
|
|
4
|
-
export class BaseLocationServices {
|
|
5
|
-
constructor(router, fireAfterUpdate) {
|
|
6
|
-
this.fireAfterUpdate = fireAfterUpdate;
|
|
7
|
-
this._listeners = [];
|
|
8
|
-
this._listener = (evt) => this._listeners.forEach((cb) => cb(evt));
|
|
9
|
-
this.hash = () => parseUrl(this._get()).hash;
|
|
10
|
-
this.path = () => parseUrl(this._get()).path;
|
|
11
|
-
this.search = () => getParams(parseUrl(this._get()).search);
|
|
12
|
-
this._location = root.location;
|
|
13
|
-
this._history = root.history;
|
|
14
|
-
}
|
|
15
|
-
url(url, replace = true) {
|
|
16
|
-
if (isDefined(url) && url !== this._get()) {
|
|
17
|
-
this._set(null, null, url, replace);
|
|
18
|
-
if (this.fireAfterUpdate) {
|
|
19
|
-
this._listeners.forEach((cb) => cb({ url }));
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return buildUrl(this);
|
|
23
|
-
}
|
|
24
|
-
onChange(cb) {
|
|
25
|
-
this._listeners.push(cb);
|
|
26
|
-
return () => removeFrom(this._listeners, cb);
|
|
27
|
-
}
|
|
28
|
-
dispose(router) {
|
|
29
|
-
deregAll(this._listeners);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { isDefined, isUndefined } from "../common/predicates";
|
|
2
|
-
/** A `LocationConfig` that delegates to the browser's `location` object */
|
|
3
|
-
export class BrowserLocationConfig {
|
|
4
|
-
constructor(router, _isHtml5 = false) {
|
|
5
|
-
this._isHtml5 = _isHtml5;
|
|
6
|
-
this._baseHref = undefined;
|
|
7
|
-
this._hashPrefix = "";
|
|
8
|
-
}
|
|
9
|
-
port() {
|
|
10
|
-
if (location.port) {
|
|
11
|
-
return Number(location.port);
|
|
12
|
-
}
|
|
13
|
-
return this.protocol() === "https" ? 443 : 80;
|
|
14
|
-
}
|
|
15
|
-
protocol() {
|
|
16
|
-
return location.protocol.replace(/:/g, "");
|
|
17
|
-
}
|
|
18
|
-
host() {
|
|
19
|
-
return location.hostname;
|
|
20
|
-
}
|
|
21
|
-
html5Mode() {
|
|
22
|
-
return this._isHtml5;
|
|
23
|
-
}
|
|
24
|
-
hashPrefix(newprefix) {
|
|
25
|
-
return isDefined(newprefix)
|
|
26
|
-
? (this._hashPrefix = newprefix)
|
|
27
|
-
: this._hashPrefix;
|
|
28
|
-
}
|
|
29
|
-
baseHref(href) {
|
|
30
|
-
if (isDefined(href)) this._baseHref = href;
|
|
31
|
-
if (isUndefined(this._baseHref)) this._baseHref = this.getBaseHref();
|
|
32
|
-
return this._baseHref;
|
|
33
|
-
}
|
|
34
|
-
getBaseHref() {
|
|
35
|
-
const baseTag = document.getElementsByTagName("base")[0];
|
|
36
|
-
if (baseTag && baseTag.href) {
|
|
37
|
-
return baseTag.href.replace(/^([^/:]*:)?\/\/[^/]*/, "");
|
|
38
|
-
}
|
|
39
|
-
return this._isHtml5 ? "/" : location.pathname || "/";
|
|
40
|
-
}
|
|
41
|
-
dispose() {}
|
|
42
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { root, trimHashVal } from "../common/index";
|
|
2
|
-
import { BaseLocationServices } from "./baseLocationService";
|
|
3
|
-
/** A `LocationServices` that uses the browser hash "#" to get/set the current location */
|
|
4
|
-
export class HashLocationService extends BaseLocationServices {
|
|
5
|
-
constructor(router) {
|
|
6
|
-
super(router, false);
|
|
7
|
-
root.addEventListener("hashchange", this._listener, false);
|
|
8
|
-
}
|
|
9
|
-
_get() {
|
|
10
|
-
return trimHashVal(this._location.hash);
|
|
11
|
-
}
|
|
12
|
-
_set(state, title, url, replace) {
|
|
13
|
-
this._location.hash = url;
|
|
14
|
-
}
|
|
15
|
-
dispose(router) {
|
|
16
|
-
super.dispose(router);
|
|
17
|
-
root.removeEventListener("hashchange", this._listener);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
extend,
|
|
3
|
-
assertPredicate,
|
|
4
|
-
isFunction,
|
|
5
|
-
isArray,
|
|
6
|
-
isInjectable,
|
|
7
|
-
} from "../common/index";
|
|
8
|
-
// globally available injectables
|
|
9
|
-
const globals = {};
|
|
10
|
-
const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;
|
|
11
|
-
const ARGUMENT_NAMES = /([^\s,]+)/g;
|
|
12
|
-
/**
|
|
13
|
-
* A basic angular1-like injector api
|
|
14
|
-
*
|
|
15
|
-
* This object implements four methods similar to the
|
|
16
|
-
* [angular 1 dependency injector](https://docs.angularjs.org/api/auto/service/$injector)
|
|
17
|
-
*
|
|
18
|
-
* UI-Router evolved from an angular 1 library to a framework agnostic library.
|
|
19
|
-
* However, some of the `@uirouter/core` code uses these ng1 style APIs to support ng1 style dependency injection.
|
|
20
|
-
*
|
|
21
|
-
* This object provides a naive implementation of a globally scoped dependency injection system.
|
|
22
|
-
* It supports the following DI approaches:
|
|
23
|
-
*
|
|
24
|
-
* ### Function parameter names
|
|
25
|
-
*
|
|
26
|
-
* A function's `.toString()` is called, and the parameter names are parsed.
|
|
27
|
-
* This only works when the parameter names aren't "mangled" by a minifier such as UglifyJS.
|
|
28
|
-
*
|
|
29
|
-
* ```js
|
|
30
|
-
* function injectedFunction(FooService, BarService) {
|
|
31
|
-
* // FooService and BarService are injected
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* ### Function annotation
|
|
36
|
-
*
|
|
37
|
-
* A function may be annotated with an array of dependency names as the `$inject` property.
|
|
38
|
-
*
|
|
39
|
-
* ```js
|
|
40
|
-
* injectedFunction.$inject = [ 'FooService', 'BarService' ];
|
|
41
|
-
* function injectedFunction(fs, bs) {
|
|
42
|
-
* // FooService and BarService are injected as fs and bs parameters
|
|
43
|
-
* }
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
* ### Array notation
|
|
47
|
-
*
|
|
48
|
-
* An array provides the names of the dependencies to inject (as strings).
|
|
49
|
-
* The function is the last element of the array.
|
|
50
|
-
*
|
|
51
|
-
* ```js
|
|
52
|
-
* [ 'FooService', 'BarService', function (fs, bs) {
|
|
53
|
-
* // FooService and BarService are injected as fs and bs parameters
|
|
54
|
-
* }]
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
* @type {$InjectorLike}
|
|
58
|
-
*/
|
|
59
|
-
export const $injector = {
|
|
60
|
-
/** Gets an object from DI based on a string token */
|
|
61
|
-
get: (name) => globals[name],
|
|
62
|
-
/** Returns true if an object named `name` exists in global DI */
|
|
63
|
-
has: (name) => $injector.get(name) != null,
|
|
64
|
-
/**
|
|
65
|
-
* Injects a function
|
|
66
|
-
*
|
|
67
|
-
* @param fn the function to inject
|
|
68
|
-
* @param context the function's `this` binding
|
|
69
|
-
* @param locals An object with additional DI tokens and values, such as `{ someToken: { foo: 1 } }`
|
|
70
|
-
*/
|
|
71
|
-
invoke: (fn, context, locals) => {
|
|
72
|
-
const all = extend({}, globals, locals || {});
|
|
73
|
-
const params = $injector.annotate(fn);
|
|
74
|
-
const ensureExist = assertPredicate(
|
|
75
|
-
(key) => all.hasOwnProperty(key),
|
|
76
|
-
(key) => `DI can't find injectable: '${key}'`,
|
|
77
|
-
);
|
|
78
|
-
const args = params.filter(ensureExist).map((x) => all[x]);
|
|
79
|
-
if (isFunction(fn)) return fn.apply(context, args);
|
|
80
|
-
else return fn.slice(-1)[0].apply(context, args);
|
|
81
|
-
},
|
|
82
|
-
/**
|
|
83
|
-
* Returns a function's dependencies
|
|
84
|
-
*
|
|
85
|
-
* Analyzes a function (or array) and returns an array of DI tokens that the function requires.
|
|
86
|
-
* @return an array of `string`s
|
|
87
|
-
*/
|
|
88
|
-
annotate: (fn) => {
|
|
89
|
-
if (!isInjectable(fn)) throw new Error(`Not an injectable function: ${fn}`);
|
|
90
|
-
if (fn && fn.$inject) return fn.$inject;
|
|
91
|
-
if (isArray(fn)) return fn.slice(0, -1);
|
|
92
|
-
const fnStr = fn.toString().replace(STRIP_COMMENTS, "");
|
|
93
|
-
const result = fnStr
|
|
94
|
-
.slice(fnStr.indexOf("(") + 1, fnStr.indexOf(")"))
|
|
95
|
-
.match(ARGUMENT_NAMES);
|
|
96
|
-
return result || [];
|
|
97
|
-
},
|
|
98
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { isDefined } from "../common/predicates";
|
|
2
|
-
import { noop } from "../common/index";
|
|
3
|
-
/** A `LocationConfig` mock that gets/sets all config from an in-memory object */
|
|
4
|
-
export class MemoryLocationConfig {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.dispose = noop;
|
|
7
|
-
this._baseHref = "";
|
|
8
|
-
this._port = 80;
|
|
9
|
-
this._protocol = "http";
|
|
10
|
-
this._host = "localhost";
|
|
11
|
-
this._hashPrefix = "";
|
|
12
|
-
this.port = () => this._port;
|
|
13
|
-
this.protocol = () => this._protocol;
|
|
14
|
-
this.host = () => this._host;
|
|
15
|
-
this.baseHref = () => this._baseHref;
|
|
16
|
-
this.html5Mode = () => false;
|
|
17
|
-
this.hashPrefix = (newval) =>
|
|
18
|
-
isDefined(newval) ? (this._hashPrefix = newval) : this._hashPrefix;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { BaseLocationServices } from "./baseLocationService";
|
|
2
|
-
/** A `LocationServices` that gets/sets the current location from an in-memory object */
|
|
3
|
-
export class MemoryLocationService extends BaseLocationServices {
|
|
4
|
-
constructor(router) {
|
|
5
|
-
super(router, true);
|
|
6
|
-
}
|
|
7
|
-
_get() {
|
|
8
|
-
return this._url;
|
|
9
|
-
}
|
|
10
|
-
_set(state, title, url, replace) {
|
|
11
|
-
this._url = url;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { BrowserLocationConfig } from "./browserLocationConfig";
|
|
2
|
-
import { HashLocationService } from "./hashLocationService";
|
|
3
|
-
import { locationPluginFactory } from "./utils";
|
|
4
|
-
import { PushStateLocationService } from "./pushStateLocationService";
|
|
5
|
-
import { MemoryLocationService } from "./memoryLocationService";
|
|
6
|
-
import { MemoryLocationConfig } from "./memoryLocationConfig";
|
|
7
|
-
import { $injector } from "./injector";
|
|
8
|
-
import { $q } from "./q";
|
|
9
|
-
import { services } from "../common/coreservices";
|
|
10
|
-
export function servicesPlugin(router) {
|
|
11
|
-
services.$injector = $injector;
|
|
12
|
-
services.$q = $q;
|
|
13
|
-
return { name: "vanilla.services", $q, $injector, dispose: () => null };
|
|
14
|
-
}
|
|
15
|
-
/** A `UIRouterPlugin` uses the browser hash to get/set the current location */
|
|
16
|
-
export const hashLocationPlugin = locationPluginFactory(
|
|
17
|
-
"vanilla.hashBangLocation",
|
|
18
|
-
false,
|
|
19
|
-
HashLocationService,
|
|
20
|
-
BrowserLocationConfig,
|
|
21
|
-
);
|
|
22
|
-
/** A `UIRouterPlugin` that gets/sets the current location using the browser's `location` and `history` apis */
|
|
23
|
-
export const pushStateLocationPlugin = locationPluginFactory(
|
|
24
|
-
"vanilla.pushStateLocation",
|
|
25
|
-
true,
|
|
26
|
-
PushStateLocationService,
|
|
27
|
-
BrowserLocationConfig,
|
|
28
|
-
);
|
|
29
|
-
/** A `UIRouterPlugin` that gets/sets the current location from an in-memory object */
|
|
30
|
-
export const memoryLocationPlugin = locationPluginFactory(
|
|
31
|
-
"vanilla.memoryLocation",
|
|
32
|
-
false,
|
|
33
|
-
MemoryLocationService,
|
|
34
|
-
MemoryLocationConfig,
|
|
35
|
-
);
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { BaseLocationServices } from "./baseLocationService";
|
|
2
|
-
import {
|
|
3
|
-
root,
|
|
4
|
-
splitHash,
|
|
5
|
-
splitQuery,
|
|
6
|
-
stripLastPathElement,
|
|
7
|
-
} from "../common/index";
|
|
8
|
-
/**
|
|
9
|
-
* A `LocationServices` that gets/sets the current location using the browser's `location` and `history` apis
|
|
10
|
-
*
|
|
11
|
-
* Uses `history.pushState` and `history.replaceState`
|
|
12
|
-
*/
|
|
13
|
-
export class PushStateLocationService extends BaseLocationServices {
|
|
14
|
-
constructor(router) {
|
|
15
|
-
super(router, true);
|
|
16
|
-
this._config = router.urlService.config;
|
|
17
|
-
root.addEventListener("popstate", this._listener, false);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Gets the base prefix without:
|
|
21
|
-
* - trailing slash
|
|
22
|
-
* - trailing filename
|
|
23
|
-
* - protocol and hostname
|
|
24
|
-
*
|
|
25
|
-
* If <base href='/base/'>, this returns '/base'.
|
|
26
|
-
* If <base href='/foo/base/'>, this returns '/foo/base'.
|
|
27
|
-
* If <base href='/base/index.html'>, this returns '/base'.
|
|
28
|
-
* If <base href='http://localhost:8080/base/index.html'>, this returns '/base'.
|
|
29
|
-
* If <base href='/base'>, this returns ''.
|
|
30
|
-
* If <base href='http://localhost:8080'>, this returns ''.
|
|
31
|
-
* If <base href='http://localhost:8080/'>, this returns ''.
|
|
32
|
-
*
|
|
33
|
-
* See: https://html.spec.whatwg.org/dev/semantics.html#the-base-element
|
|
34
|
-
*/
|
|
35
|
-
_getBasePrefix() {
|
|
36
|
-
return stripLastPathElement(this._config.baseHref());
|
|
37
|
-
}
|
|
38
|
-
_get() {
|
|
39
|
-
let { pathname, hash, search } = this._location;
|
|
40
|
-
search = splitQuery(search)[1]; // strip ? if found
|
|
41
|
-
hash = splitHash(hash)[1]; // strip # if found
|
|
42
|
-
const basePrefix = this._getBasePrefix();
|
|
43
|
-
const exactBaseHrefMatch = pathname === this._config.baseHref();
|
|
44
|
-
const startsWithBase = pathname.substr(0, basePrefix.length) === basePrefix;
|
|
45
|
-
pathname = exactBaseHrefMatch
|
|
46
|
-
? "/"
|
|
47
|
-
: startsWithBase
|
|
48
|
-
? pathname.substring(basePrefix.length)
|
|
49
|
-
: pathname;
|
|
50
|
-
return pathname + (search ? "?" + search : "") + (hash ? "#" + hash : "");
|
|
51
|
-
}
|
|
52
|
-
_set(state, title, url, replace) {
|
|
53
|
-
const basePrefix = this._getBasePrefix();
|
|
54
|
-
const slash = url && url[0] !== "/" ? "/" : "";
|
|
55
|
-
const fullUrl =
|
|
56
|
-
url === "" || url === "/"
|
|
57
|
-
? this._config.baseHref()
|
|
58
|
-
: basePrefix + slash + url;
|
|
59
|
-
if (replace) {
|
|
60
|
-
this._history.replaceState(state, title, fullUrl);
|
|
61
|
-
} else {
|
|
62
|
-
this._history.pushState(state, title, fullUrl);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
dispose(router) {
|
|
66
|
-
super.dispose(router);
|
|
67
|
-
root.removeEventListener("popstate", this._listener);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { isArray, isObject } from "../common/index";
|
|
2
|
-
/**
|
|
3
|
-
* An angular1-like promise api
|
|
4
|
-
*
|
|
5
|
-
* This object implements four methods similar to the
|
|
6
|
-
* [angular 1 promise api](https://docs.angularjs.org/api/ng/service/$q)
|
|
7
|
-
*
|
|
8
|
-
* UI-Router evolved from an angular 1 library to a framework agnostic library.
|
|
9
|
-
* However, some of the `@uirouter/core` code uses these ng1 style APIs to support ng1 style dependency injection.
|
|
10
|
-
*
|
|
11
|
-
* This API provides native ES6 promise support wrapped as a $q-like API.
|
|
12
|
-
* Internally, UI-Router uses this $q object to perform promise operations.
|
|
13
|
-
* The `angular-ui-router` (ui-router for angular 1) uses the $q API provided by angular.
|
|
14
|
-
*
|
|
15
|
-
* $q-like promise api
|
|
16
|
-
*/
|
|
17
|
-
export const $q = {
|
|
18
|
-
/** Normalizes a value as a promise */
|
|
19
|
-
when: (val) => new Promise((resolve, reject) => resolve(val)),
|
|
20
|
-
/** Normalizes a value as a promise rejection */
|
|
21
|
-
reject: (val) =>
|
|
22
|
-
new Promise((resolve, reject) => {
|
|
23
|
-
reject(val);
|
|
24
|
-
}),
|
|
25
|
-
/** @returns a deferred object, which has `resolve` and `reject` functions */
|
|
26
|
-
defer: () => {
|
|
27
|
-
const deferred = {};
|
|
28
|
-
deferred.promise = new Promise((resolve, reject) => {
|
|
29
|
-
deferred.resolve = resolve;
|
|
30
|
-
deferred.reject = reject;
|
|
31
|
-
});
|
|
32
|
-
return deferred;
|
|
33
|
-
},
|
|
34
|
-
/** Like Promise.all(), but also supports object key/promise notation like $q */
|
|
35
|
-
all: (promises) => {
|
|
36
|
-
if (isArray(promises)) {
|
|
37
|
-
return Promise.all(promises);
|
|
38
|
-
}
|
|
39
|
-
if (isObject(promises)) {
|
|
40
|
-
// Convert promises map to promises array.
|
|
41
|
-
// When each promise resolves, map it to a tuple { key: key, val: val }
|
|
42
|
-
const chain = Object.keys(promises).map((key) =>
|
|
43
|
-
promises[key].then((val) => ({ key, val })),
|
|
44
|
-
);
|
|
45
|
-
// Then wait for all promises to resolve, and convert them back to an object
|
|
46
|
-
return $q.all(chain).then((values) =>
|
|
47
|
-
values.reduce((acc, tuple) => {
|
|
48
|
-
acc[tuple.key] = tuple.val;
|
|
49
|
-
return acc;
|
|
50
|
-
}, {}),
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
identity,
|
|
3
|
-
unnestR,
|
|
4
|
-
isArray,
|
|
5
|
-
splitEqual,
|
|
6
|
-
splitHash,
|
|
7
|
-
splitQuery,
|
|
8
|
-
} from "../common/index";
|
|
9
|
-
export const keyValsToObjectR = (accum, [key, val]) => {
|
|
10
|
-
if (!accum.hasOwnProperty(key)) {
|
|
11
|
-
accum[key] = val;
|
|
12
|
-
} else if (isArray(accum[key])) {
|
|
13
|
-
accum[key].push(val);
|
|
14
|
-
} else {
|
|
15
|
-
accum[key] = [accum[key], val];
|
|
16
|
-
}
|
|
17
|
-
return accum;
|
|
18
|
-
};
|
|
19
|
-
export const getParams = (queryString) =>
|
|
20
|
-
queryString
|
|
21
|
-
.split("&")
|
|
22
|
-
.filter(identity)
|
|
23
|
-
.map(splitEqual)
|
|
24
|
-
.reduce(keyValsToObjectR, {});
|
|
25
|
-
export function parseUrl(url) {
|
|
26
|
-
const orEmptyString = (x) => x || "";
|
|
27
|
-
const [beforehash, hash] = splitHash(url).map(orEmptyString);
|
|
28
|
-
const [path, search] = splitQuery(beforehash).map(orEmptyString);
|
|
29
|
-
return { path, search, hash, url };
|
|
30
|
-
}
|
|
31
|
-
export const buildUrl = (loc) => {
|
|
32
|
-
const path = loc.path();
|
|
33
|
-
const searchObject = loc.search();
|
|
34
|
-
const hash = loc.hash();
|
|
35
|
-
const search = Object.keys(searchObject)
|
|
36
|
-
.map((key) => {
|
|
37
|
-
const param = searchObject[key];
|
|
38
|
-
const vals = isArray(param) ? param : [param];
|
|
39
|
-
return vals.map((val) => key + "=" + val);
|
|
40
|
-
})
|
|
41
|
-
.reduce(unnestR, [])
|
|
42
|
-
.join("&");
|
|
43
|
-
return path + (search ? "?" + search : "") + (hash ? "#" + hash : "");
|
|
44
|
-
};
|
|
45
|
-
export function locationPluginFactory(
|
|
46
|
-
name,
|
|
47
|
-
isHtml5,
|
|
48
|
-
serviceClass,
|
|
49
|
-
configurationClass,
|
|
50
|
-
) {
|
|
51
|
-
return function (uiRouter) {
|
|
52
|
-
const service = (uiRouter.locationService = new serviceClass(uiRouter));
|
|
53
|
-
const configuration = (uiRouter.locationConfig = new configurationClass(
|
|
54
|
-
uiRouter,
|
|
55
|
-
isHtml5,
|
|
56
|
-
));
|
|
57
|
-
function dispose(router) {
|
|
58
|
-
router.dispose(service);
|
|
59
|
-
router.dispose(configuration);
|
|
60
|
-
}
|
|
61
|
-
return { name, service, configuration, dispose };
|
|
62
|
-
};
|
|
63
|
-
}
|