@angular-wave/angular.ts 0.0.30 → 0.0.33
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/index.html +5 -14
- package/package.json +1 -1
- package/src/core/compile.js +5 -4
- package/src/core/location.js +1 -1
- package/src/core/parser/parse.js +1 -2
- package/src/core/root-scope.js +49 -99
- package/src/directive/events.js +2 -1
- package/src/directive/model.js +4 -2
- package/src/router/directives/state-directives.js +33 -18
- package/src/router/directives/view-directive.js +1 -2
- package/src/router/globals.js +2 -0
- package/src/router/hooks/url.js +4 -4
- package/src/router/index.js +23 -27
- package/src/router/injectables.js +1 -52
- package/src/router/services.js +6 -84
- package/src/router/state/state-builder.js +7 -6
- package/src/router/state/state-queue-manager.js +2 -1
- package/src/router/state/state-registry.js +39 -21
- package/src/router/state/state-service.js +173 -6
- package/src/router/state/views.js +46 -2
- package/src/router/transition/reject-factory.js +0 -8
- package/src/router/transition/transition-service.js +43 -1
- package/src/router/url/url-config.js +32 -1
- package/src/router/url/url-rule.js +4 -4
- package/src/router/url/url-service.js +161 -14
- package/src/router/view/view.js +7 -51
- package/src/services/http.js +1 -1
- package/src/shared/common.js +1 -1
- package/src/shared/strings.js +7 -2
- package/test/core/compile.spec.js +2 -2
- package/test/core/scope.spec.js +2 -37
- package/test/router/services.spec.js +14 -31
- package/test/router/state-directives.spec.js +2 -2
- package/test/router/state-filter.spec.js +0 -2
- package/test/router/state.spec.js +4 -4
- package/test/router/template-factory.spec.js +19 -10
- package/test/router/{url-matcher-factory.spec.js → url-service.spec.js} +126 -132
- package/test/router/view-directive.spec.js +9 -9
- package/test/router/view-hook.spec.js +10 -10
- package/test/router/view.spec.js +4 -11
- package/types/router/core/params/interface.d.ts +2 -2
- package/types/router/core/url/urlMatcherFactory.d.ts +1 -1
- package/legacy/angular-animate.js +0 -4272
- package/legacy/angular-aria.js +0 -426
- package/legacy/angular-message-format.js +0 -1072
- package/legacy/angular-messages.js +0 -829
- package/legacy/angular-route.js +0 -1266
- package/legacy/angular-sanitize.js +0 -891
- package/legacy/angular.js +0 -36600
- package/src/router/router.js +0 -125
- package/src/router/url/url-matcher-factory.js +0 -76
- package/src/router/url/url-router.js +0 -101
- package/test/original-test.html +0 -33
|
@@ -15,7 +15,10 @@ import {
|
|
|
15
15
|
registerLazyResolveState,
|
|
16
16
|
registerResolveRemaining,
|
|
17
17
|
} from "../hooks/resolve";
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
registerActivateViews,
|
|
20
|
+
registerLoadEnteringViews,
|
|
21
|
+
} from "../hooks/views";
|
|
19
22
|
import { registerUpdateGlobalState } from "../hooks/update-globals";
|
|
20
23
|
|
|
21
24
|
import { registerLazyLoadHook } from "../hooks/lazy-load";
|
|
@@ -26,6 +29,8 @@ import { createProxyFunctions } from "../../shared/common";
|
|
|
26
29
|
import { val } from "../../shared/hof";
|
|
27
30
|
import { registerIgnoredTransitionHook } from "../hooks/ignored-transition";
|
|
28
31
|
import { registerInvalidTransitionHook } from "../hooks/invalid-transition";
|
|
32
|
+
import { registerRedirectToHook } from "../hooks/redirect-to";
|
|
33
|
+
import { registerUpdateUrl } from "../hooks/url";
|
|
29
34
|
/**
|
|
30
35
|
* The default [[Transition]] options.
|
|
31
36
|
*
|
|
@@ -56,6 +61,8 @@ export let defaultTransOpts = {
|
|
|
56
61
|
* This API is located at `router.transitionService` ([[UIRouter.transitionService]])
|
|
57
62
|
*/
|
|
58
63
|
export class TransitionService {
|
|
64
|
+
static $inject = ["$routerGlobalsProvider", "$viewProvider"];
|
|
65
|
+
|
|
59
66
|
/**
|
|
60
67
|
* @param {import('../globals').UIRouterGlobals} globals
|
|
61
68
|
*/
|
|
@@ -82,6 +89,41 @@ export class TransitionService {
|
|
|
82
89
|
this._registerCoreTransitionHooks();
|
|
83
90
|
globals.successfulTransitions.onEvict(treeChangesCleanup);
|
|
84
91
|
}
|
|
92
|
+
|
|
93
|
+
$get = [
|
|
94
|
+
"$state",
|
|
95
|
+
"$urlService",
|
|
96
|
+
"$stateRegistry",
|
|
97
|
+
"$view",
|
|
98
|
+
(stateService, urlService, stateRegistry, viewService) => {
|
|
99
|
+
// Lazy load state trees
|
|
100
|
+
this._deregisterHookFns.lazyLoad = registerLazyLoadHook(
|
|
101
|
+
this,
|
|
102
|
+
stateService,
|
|
103
|
+
urlService,
|
|
104
|
+
stateRegistry,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
// After globals.current is updated at priority: 10000
|
|
108
|
+
this._deregisterHookFns.updateUrl = registerUpdateUrl(
|
|
109
|
+
this,
|
|
110
|
+
stateService,
|
|
111
|
+
urlService,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
// Wire up redirectTo hook
|
|
115
|
+
this._deregisterHookFns.redirectTo = registerRedirectToHook(
|
|
116
|
+
this,
|
|
117
|
+
stateService,
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
this._deregisterHookFns.activateViews = registerActivateViews(
|
|
121
|
+
this,
|
|
122
|
+
viewService,
|
|
123
|
+
);
|
|
124
|
+
return this;
|
|
125
|
+
},
|
|
126
|
+
];
|
|
85
127
|
/**
|
|
86
128
|
* Registers a [[TransitionHookFn]], called *while a transition is being constructed*.
|
|
87
129
|
*
|
|
@@ -13,7 +13,7 @@ import { isDefined, isString } from "../../shared/utils";
|
|
|
13
13
|
*
|
|
14
14
|
* This API is found at `router.urlService.config` (see: [[UIRouter.urlService]], [[URLService.config]])
|
|
15
15
|
*/
|
|
16
|
-
export class
|
|
16
|
+
export class UrlConfigProvider {
|
|
17
17
|
constructor() {
|
|
18
18
|
/** @type {ParamTypes} */
|
|
19
19
|
this.paramTypes = new ParamTypes();
|
|
@@ -23,7 +23,38 @@ export class UrlConfig {
|
|
|
23
23
|
this._isStrictMode = true;
|
|
24
24
|
/** @type {boolean} */
|
|
25
25
|
this._defaultSquashPolicy = false;
|
|
26
|
+
/**
|
|
27
|
+
* Applys ng1-specific path parameter encoding
|
|
28
|
+
*
|
|
29
|
+
* The Angular 1 `$location` service is a bit weird.
|
|
30
|
+
* It doesn't allow slashes to be encoded/decoded bi-directionally.
|
|
31
|
+
*
|
|
32
|
+
* See the writeup at https://github.com/angular-ui/ui-router/issues/2598
|
|
33
|
+
*
|
|
34
|
+
* This code patches the `path` parameter type so it encoded/decodes slashes as ~2F
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
const pathType = this.type("path");
|
|
38
|
+
pathType.encode = (x) =>
|
|
39
|
+
x != null
|
|
40
|
+
? x.toString().replace(/(~|\/)/g, (m) => ({ "~": "~~", "/": "~2F" })[m])
|
|
41
|
+
: x;
|
|
42
|
+
pathType.decode = (x) =>
|
|
43
|
+
x != null
|
|
44
|
+
? x
|
|
45
|
+
.toString()
|
|
46
|
+
.replace(/(~~|~2F)/g, (m) => ({ "~~": "~", "~2F": "/" })[m])
|
|
47
|
+
: x;
|
|
48
|
+
this.paramTypes.enqueue = false;
|
|
49
|
+
this.paramTypes._flushTypeQueue();
|
|
26
50
|
}
|
|
51
|
+
|
|
52
|
+
$get = [
|
|
53
|
+
function () {
|
|
54
|
+
return this;
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
|
|
27
58
|
/**
|
|
28
59
|
* Defines whether URL matching should be case sensitive (the default behavior), or not.
|
|
29
60
|
*
|
|
@@ -13,8 +13,8 @@ import { StateObject } from "../state/state-object";
|
|
|
13
13
|
* - [[StateObject]]
|
|
14
14
|
*/
|
|
15
15
|
export class UrlRuleFactory {
|
|
16
|
-
constructor(
|
|
17
|
-
this.
|
|
16
|
+
constructor(urlService, stateService, routerGlobals) {
|
|
17
|
+
this.urlService = urlService;
|
|
18
18
|
this.stateService = stateService;
|
|
19
19
|
this.routerGlobals = routerGlobals;
|
|
20
20
|
}
|
|
@@ -28,7 +28,7 @@ export class UrlRuleFactory {
|
|
|
28
28
|
create(what, handler) {
|
|
29
29
|
const { isState, isStateDeclaration } = StateObject;
|
|
30
30
|
const makeRule = pattern([
|
|
31
|
-
[isString, (_what) => makeRule(this.
|
|
31
|
+
[isString, (_what) => makeRule(this.urlService.compile(_what))],
|
|
32
32
|
[is(UrlMatcher), (_what) => this.fromUrlMatcher(_what, handler)],
|
|
33
33
|
[
|
|
34
34
|
or(isState, isStateDeclaration),
|
|
@@ -79,7 +79,7 @@ export class UrlRuleFactory {
|
|
|
79
79
|
*/
|
|
80
80
|
fromUrlMatcher(urlMatcher, handler) {
|
|
81
81
|
let _handler = handler;
|
|
82
|
-
if (isString(handler)) handler = this.
|
|
82
|
+
if (isString(handler)) handler = this.urlService.compile(handler);
|
|
83
83
|
if (is(UrlMatcher)(handler)) _handler = (match) => handler.format(match);
|
|
84
84
|
function matchUrlParamters(url) {
|
|
85
85
|
const params = urlMatcher.exec(url.path, url.search, url.hash);
|
|
@@ -1,38 +1,64 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
forEach,
|
|
3
|
+
isFunction,
|
|
4
|
+
isDefined,
|
|
5
|
+
isObject,
|
|
6
|
+
isString,
|
|
7
|
+
} from "../../shared/utils";
|
|
2
8
|
import { is, pattern } from "../../shared/hof";
|
|
3
9
|
import { UrlRules } from "./url-rules";
|
|
4
|
-
import { UrlConfig } from "./url-config";
|
|
5
10
|
import { TargetState } from "../state/target-state";
|
|
6
11
|
import { removeFrom } from "../../shared/common";
|
|
12
|
+
import { stripLastPathElement } from "../../shared/strings";
|
|
13
|
+
import { UrlMatcher } from "./url-matcher";
|
|
14
|
+
import { ParamFactory } from "../params/param-factory";
|
|
15
|
+
import { UrlRuleFactory } from "./url-rule";
|
|
7
16
|
|
|
8
17
|
/**
|
|
9
18
|
* API for URL management
|
|
10
19
|
*/
|
|
11
20
|
export class UrlService {
|
|
21
|
+
static $inject = [
|
|
22
|
+
"$locationProvider",
|
|
23
|
+
"$stateProvider",
|
|
24
|
+
"$routerGlobalsProvider",
|
|
25
|
+
"$urlConfigProvider",
|
|
26
|
+
];
|
|
27
|
+
|
|
12
28
|
/**
|
|
13
29
|
* @param {angular.ILocationProvider} $locationProvider
|
|
14
30
|
*/
|
|
15
|
-
constructor($locationProvider,
|
|
31
|
+
constructor($locationProvider, stateService, globals, urlConfigProvider) {
|
|
16
32
|
this.stateService = stateService;
|
|
17
|
-
|
|
33
|
+
this.stateService.urlService = this; // circular wiring
|
|
18
34
|
this.$locationProvider = $locationProvider;
|
|
19
35
|
|
|
36
|
+
this.$location = undefined;
|
|
37
|
+
this.$browser = undefined;
|
|
38
|
+
|
|
20
39
|
/** @type {boolean} */
|
|
21
40
|
this.interceptDeferred = false;
|
|
41
|
+
|
|
42
|
+
/** Provides services related to the URL */
|
|
43
|
+
this.urlRuleFactory = new UrlRuleFactory(this, this.stateService, globals);
|
|
44
|
+
|
|
22
45
|
/**
|
|
23
46
|
* The nested [[UrlRules]] API for managing URL rules and rewrites
|
|
24
47
|
*
|
|
25
48
|
* See: [[UrlRules]] for details
|
|
26
49
|
* @type {UrlRules}
|
|
27
50
|
*/
|
|
28
|
-
this.rules = new UrlRules(urlRuleFactory);
|
|
51
|
+
this.rules = new UrlRules(this.urlRuleFactory);
|
|
29
52
|
/**
|
|
30
53
|
* The nested [[UrlConfig]] API to configure the URL and retrieve URL information
|
|
31
54
|
*
|
|
32
55
|
* See: [[UrlConfig]] for details
|
|
33
|
-
* @type {UrlConfig}
|
|
56
|
+
* @type {angular.UrlConfig}
|
|
34
57
|
*/
|
|
35
|
-
this.config =
|
|
58
|
+
this.config = urlConfigProvider;
|
|
59
|
+
|
|
60
|
+
/** Creates a new [[Param]] for a given location (DefType) */
|
|
61
|
+
this.paramFactory = new ParamFactory(this.config);
|
|
36
62
|
|
|
37
63
|
/**
|
|
38
64
|
* Gets the path part of the current url
|
|
@@ -62,6 +88,20 @@ export class UrlService {
|
|
|
62
88
|
this._urlListeners = [];
|
|
63
89
|
}
|
|
64
90
|
|
|
91
|
+
$get = [
|
|
92
|
+
"$location",
|
|
93
|
+
"$browser",
|
|
94
|
+
"$rootScope",
|
|
95
|
+
($location, $browser, $rootScope) => {
|
|
96
|
+
this.$location = $location;
|
|
97
|
+
this.$browser = $browser;
|
|
98
|
+
$rootScope.$on("$locationChangeSuccess", (evt) =>
|
|
99
|
+
this._urlListeners.forEach((fn) => fn(evt)),
|
|
100
|
+
);
|
|
101
|
+
return this;
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
|
|
65
105
|
html5Mode() {
|
|
66
106
|
let html5Mode = this.$locationProvider.html5Mode();
|
|
67
107
|
html5Mode = isObject(html5Mode) ? html5Mode.enabled : html5Mode;
|
|
@@ -303,13 +343,120 @@ export class UrlService {
|
|
|
303
343
|
return best;
|
|
304
344
|
}
|
|
305
345
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
346
|
+
update(read) {
|
|
347
|
+
if (read) {
|
|
348
|
+
this.location = this.url();
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
if (this.url() === this.location) return;
|
|
352
|
+
this.url(this.location, true);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Internal API.
|
|
357
|
+
*
|
|
358
|
+
* Pushes a new location to the browser history.
|
|
359
|
+
*
|
|
360
|
+
* @internal
|
|
361
|
+
* @param urlMatcher
|
|
362
|
+
* @param params
|
|
363
|
+
* @param options
|
|
364
|
+
*/
|
|
365
|
+
push(urlMatcher, params, options) {
|
|
366
|
+
const replace = options && !!options.replace;
|
|
367
|
+
this.url(urlMatcher.format(params || {}), replace);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Builds and returns a URL with interpolated parameters
|
|
372
|
+
*
|
|
373
|
+
* #### Example:
|
|
374
|
+
* ```js
|
|
375
|
+
* matcher = $umf.compile("/about/:person");
|
|
376
|
+
* params = { person: "bob" };
|
|
377
|
+
* $bob = $urlService.href(matcher, params);
|
|
378
|
+
* // $bob == "/about/bob";
|
|
379
|
+
* ```
|
|
380
|
+
*
|
|
381
|
+
* @param urlMatcher The [[UrlMatcher]] object which is used as the template of the URL to generate.
|
|
382
|
+
* @param params An object of parameter values to fill the matcher's required parameters.
|
|
383
|
+
* @param options Options object. The options are:
|
|
384
|
+
*
|
|
385
|
+
* - **`absolute`** - {boolean=false}, If true will generate an absolute url, e.g. "http://www.example.com/fullurl".
|
|
386
|
+
*
|
|
387
|
+
* @returns Returns the fully compiled URL, or `null` if `params` fail validation against `urlMatcher`
|
|
388
|
+
*/
|
|
389
|
+
href(urlMatcher, params, options) {
|
|
390
|
+
let url = urlMatcher.format(params);
|
|
391
|
+
if (url == null) return null;
|
|
392
|
+
options = options || { absolute: false };
|
|
393
|
+
const isHtml5 = this.html5Mode();
|
|
394
|
+
if (!isHtml5 && url !== null) {
|
|
395
|
+
url = "#" + this.$locationProvider.hashPrefix() + url;
|
|
396
|
+
}
|
|
397
|
+
url = appendBasePath(url, isHtml5, options.absolute, this.baseHref());
|
|
398
|
+
if (!options.absolute || !url) {
|
|
399
|
+
return url;
|
|
400
|
+
}
|
|
401
|
+
const slash = !isHtml5 && url ? "/" : "";
|
|
402
|
+
const cfgPort = this.$location.port();
|
|
403
|
+
const port = cfgPort === 80 || cfgPort === 443 ? "" : ":" + cfgPort;
|
|
404
|
+
return [
|
|
405
|
+
this.$location.protocol(),
|
|
406
|
+
"://",
|
|
407
|
+
this.$location.host(),
|
|
408
|
+
port,
|
|
409
|
+
slash,
|
|
410
|
+
url,
|
|
411
|
+
].join("");
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Creates a [[UrlMatcher]] for the specified pattern.
|
|
416
|
+
*
|
|
417
|
+
* @param pattern The URL pattern.
|
|
418
|
+
* @param config The config object hash.
|
|
419
|
+
* @returns The UrlMatcher.
|
|
420
|
+
*/
|
|
421
|
+
compile(pattern, config) {
|
|
422
|
+
const urlConfig = this.config;
|
|
423
|
+
// backward-compatible support for config.params -> config.state.params
|
|
424
|
+
const params = config && !config.state && config.params;
|
|
425
|
+
config = params ? Object.assign({ state: { params } }, config) : config;
|
|
426
|
+
const globalConfig = {
|
|
427
|
+
strict: urlConfig._isStrictMode,
|
|
428
|
+
caseInsensitive: urlConfig._isCaseInsensitive,
|
|
429
|
+
};
|
|
430
|
+
return new UrlMatcher(
|
|
431
|
+
pattern,
|
|
432
|
+
urlConfig.paramTypes,
|
|
433
|
+
this.paramFactory,
|
|
434
|
+
Object.assign(globalConfig, config),
|
|
313
435
|
);
|
|
314
436
|
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Returns true if the specified object is a [[UrlMatcher]], or false otherwise.
|
|
440
|
+
*
|
|
441
|
+
* @param object The object to perform the type check against.
|
|
442
|
+
* @returns `true` if the object matches the `UrlMatcher` interface, by
|
|
443
|
+
* implementing all the same methods.
|
|
444
|
+
*/
|
|
445
|
+
isMatcher(object) {
|
|
446
|
+
// TODO: typeof?
|
|
447
|
+
if (!isObject(object)) return false;
|
|
448
|
+
let result = true;
|
|
449
|
+
forEach(UrlMatcher.prototype, (val, name) => {
|
|
450
|
+
if (isFunction(val))
|
|
451
|
+
result = result && isDefined(object[name]) && isFunction(object[name]);
|
|
452
|
+
});
|
|
453
|
+
return result;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function appendBasePath(url, isHtml5, absolute, baseHref) {
|
|
458
|
+
if (baseHref === "/") return url;
|
|
459
|
+
if (isHtml5) return stripLastPathElement(baseHref) + url;
|
|
460
|
+
if (absolute) return baseHref.slice(1) + url;
|
|
461
|
+
return url;
|
|
315
462
|
}
|
package/src/router/view/view.js
CHANGED
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
find,
|
|
7
7
|
} from "../../shared/common";
|
|
8
8
|
import { curry, prop } from "../../shared/hof";
|
|
9
|
-
import { isString } from "../../shared/utils";
|
|
10
9
|
import { trace } from "../common/trace";
|
|
11
10
|
import { getNg1ViewConfigFactory } from "../state/views";
|
|
12
11
|
/**
|
|
@@ -26,10 +25,7 @@ import { getNg1ViewConfigFactory } from "../state/views";
|
|
|
26
25
|
*
|
|
27
26
|
*/
|
|
28
27
|
export class ViewService {
|
|
29
|
-
|
|
30
|
-
* @param {number} $id
|
|
31
|
-
*/
|
|
32
|
-
constructor($id) {
|
|
28
|
+
constructor() {
|
|
33
29
|
this._ngViews = [];
|
|
34
30
|
this._viewConfigs = [];
|
|
35
31
|
this._viewConfigFactories = {};
|
|
@@ -37,8 +33,11 @@ export class ViewService {
|
|
|
37
33
|
this._pluginapi = {
|
|
38
34
|
_rootViewContext: this._rootViewContext.bind(this),
|
|
39
35
|
_viewConfigFactory: this._viewConfigFactory.bind(this),
|
|
40
|
-
_registeredUIView: (id) =>
|
|
41
|
-
find(this._ngViews, (view) =>
|
|
36
|
+
_registeredUIView: (id) => {
|
|
37
|
+
const res = find(this._ngViews, (view) => view.id === id);
|
|
38
|
+
return res;
|
|
39
|
+
},
|
|
40
|
+
|
|
42
41
|
_registeredUIViews: () => this._ngViews,
|
|
43
42
|
_activeViewConfigs: () => this._viewConfigs,
|
|
44
43
|
_onSync: (listener) => {
|
|
@@ -49,50 +48,7 @@ export class ViewService {
|
|
|
49
48
|
this._pluginapi._viewConfigFactory("ng1", getNg1ViewConfigFactory());
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
* Normalizes a view's name from a state.views configuration block.
|
|
54
|
-
*
|
|
55
|
-
* This should be used by a framework implementation to calculate the values for
|
|
56
|
-
* [[_ViewDeclaration.$ngViewName]] and [[_ViewDeclaration.$ngViewContextAnchor]].
|
|
57
|
-
*
|
|
58
|
-
* @param context the context object (state declaration) that the view belongs to
|
|
59
|
-
* @param rawViewName the name of the view, as declared in the [[StateDeclaration.views]]
|
|
60
|
-
*
|
|
61
|
-
* @returns the normalized ngViewName and ngViewContextAnchor that the view targets
|
|
62
|
-
*/
|
|
63
|
-
static normalizeUIViewTarget(context, rawViewName = "") {
|
|
64
|
-
// TODO: Validate incoming view name with a regexp to allow:
|
|
65
|
-
// ex: "view.name@foo.bar" , "^.^.view.name" , "view.name@^.^" , "" ,
|
|
66
|
-
// "@" , "$default@^" , "!$default.$default" , "!foo.bar"
|
|
67
|
-
const viewAtContext = rawViewName.split("@");
|
|
68
|
-
let ngViewName = viewAtContext[0] || "$default"; // default to unnamed view
|
|
69
|
-
let ngViewContextAnchor = isString(viewAtContext[1])
|
|
70
|
-
? viewAtContext[1]
|
|
71
|
-
: "^"; // default to parent context
|
|
72
|
-
// Handle relative view-name sugar syntax.
|
|
73
|
-
// Matches rawViewName "^.^.^.foo.bar" into array: ["^.^.^.foo.bar", "^.^.^", "foo.bar"],
|
|
74
|
-
const relativeViewNameSugar = /^(\^(?:\.\^)*)\.(.*$)/.exec(ngViewName);
|
|
75
|
-
if (relativeViewNameSugar) {
|
|
76
|
-
// Clobbers existing contextAnchor (rawViewName validation will fix this)
|
|
77
|
-
ngViewContextAnchor = relativeViewNameSugar[1]; // set anchor to "^.^.^"
|
|
78
|
-
ngViewName = relativeViewNameSugar[2]; // set view-name to "foo.bar"
|
|
79
|
-
}
|
|
80
|
-
if (ngViewName.charAt(0) === "!") {
|
|
81
|
-
ngViewName = ngViewName.substr(1);
|
|
82
|
-
ngViewContextAnchor = ""; // target absolutely from root
|
|
83
|
-
}
|
|
84
|
-
// handle parent relative targeting "^.^.^"
|
|
85
|
-
const relativeMatch = /^(\^(?:\.\^)*)$/;
|
|
86
|
-
if (relativeMatch.exec(ngViewContextAnchor)) {
|
|
87
|
-
const anchorState = ngViewContextAnchor
|
|
88
|
-
.split(".")
|
|
89
|
-
.reduce((anchor, x) => anchor.parent, context);
|
|
90
|
-
ngViewContextAnchor = anchorState.name;
|
|
91
|
-
} else if (ngViewContextAnchor === ".") {
|
|
92
|
-
ngViewContextAnchor = context.name;
|
|
93
|
-
}
|
|
94
|
-
return { ngViewName, ngViewContextAnchor };
|
|
95
|
-
}
|
|
51
|
+
$get = [() => this];
|
|
96
52
|
|
|
97
53
|
_rootViewContext(context) {
|
|
98
54
|
return (this._rootContext = context || this._rootContext);
|
package/src/services/http.js
CHANGED
|
@@ -1431,7 +1431,7 @@ export function $HttpProvider() {
|
|
|
1431
1431
|
applyHandlers[key] = function (event) {
|
|
1432
1432
|
if (useApplyAsync) {
|
|
1433
1433
|
$rootScope.$applyAsync(callEventHandler);
|
|
1434
|
-
} else if ($rootScope.$$phase) {
|
|
1434
|
+
} else if ($rootScope.$$phase !== ScopePhase.NONE) {
|
|
1435
1435
|
callEventHandler();
|
|
1436
1436
|
} else {
|
|
1437
1437
|
$rootScope.$apply(callEventHandler);
|
package/src/shared/common.js
CHANGED
|
@@ -495,6 +495,6 @@ function _arraysEq(a1, a2) {
|
|
|
495
495
|
}
|
|
496
496
|
// issue #2676
|
|
497
497
|
export const silenceUncaughtInPromise = (promise) =>
|
|
498
|
-
promise.catch((
|
|
498
|
+
promise.catch(() => 0) && promise;
|
|
499
499
|
export const silentRejection = (error) =>
|
|
500
500
|
silenceUncaughtInPromise(services.$q.reject(error));
|
package/src/shared/strings.js
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { isInjectable, isNull, isPromise } from "./predicates";
|
|
9
9
|
import { isUndefined, isFunction, isString, isObject } from "./utils";
|
|
10
|
-
import { Rejection } from "../router/transition/reject-factory";
|
|
11
10
|
import { identity, pushR, tail } from "./common";
|
|
12
11
|
import { pattern, val } from "./hof";
|
|
13
12
|
/**
|
|
@@ -57,7 +56,13 @@ export function fnToString(fn) {
|
|
|
57
56
|
}
|
|
58
57
|
export function stringify(o) {
|
|
59
58
|
const seen = [];
|
|
60
|
-
const isRejection =
|
|
59
|
+
const isRejection = (obj) => {
|
|
60
|
+
return (
|
|
61
|
+
obj &&
|
|
62
|
+
typeof obj.then === "function" &&
|
|
63
|
+
obj.constructor.name == "Rejection"
|
|
64
|
+
);
|
|
65
|
+
};
|
|
61
66
|
const hasToString = (obj) =>
|
|
62
67
|
isObject(obj) &&
|
|
63
68
|
!Array.isArray(obj) &&
|
|
@@ -10121,7 +10121,7 @@ describe("$compile", () => {
|
|
|
10121
10121
|
}).toThrowError(/nonassign/);
|
|
10122
10122
|
expect(componentScope.ref).toBe("hello world");
|
|
10123
10123
|
// reset since the exception was rethrown which prevented phase clearing
|
|
10124
|
-
$rootScope.$$phase =
|
|
10124
|
+
$rootScope.$$phase = 0;
|
|
10125
10125
|
|
|
10126
10126
|
$rootScope.name = "misko";
|
|
10127
10127
|
$rootScope.$apply();
|
|
@@ -10139,7 +10139,7 @@ describe("$compile", () => {
|
|
|
10139
10139
|
}).toThrowError(/nonassign/);
|
|
10140
10140
|
expect(componentScope.ref).toBeUndefined();
|
|
10141
10141
|
|
|
10142
|
-
$rootScope.$$phase =
|
|
10142
|
+
$rootScope.$$phase = 0; // reset since the exception was rethrown which prevented phase clearing
|
|
10143
10143
|
$rootScope.$apply();
|
|
10144
10144
|
expect(componentScope.ref).toBeUndefined();
|
|
10145
10145
|
});
|
package/test/core/scope.spec.js
CHANGED
|
@@ -535,7 +535,7 @@ describe("Scope", function () {
|
|
|
535
535
|
$rootScope.$digest();
|
|
536
536
|
}).toThrow();
|
|
537
537
|
|
|
538
|
-
expect($rootScope.$$phase).
|
|
538
|
+
expect($rootScope.$$phase).toBe(0);
|
|
539
539
|
});
|
|
540
540
|
|
|
541
541
|
it("should prevent infinite recursion and print watcher function name or body", () => {
|
|
@@ -2532,7 +2532,7 @@ describe("Scope", function () {
|
|
|
2532
2532
|
|
|
2533
2533
|
expect(logs[0]).toBeDefined();
|
|
2534
2534
|
|
|
2535
|
-
expect($rootScope.$$phase).
|
|
2535
|
+
expect($rootScope.$$phase).toBe(0);
|
|
2536
2536
|
});
|
|
2537
2537
|
|
|
2538
2538
|
describe("exceptions", () => {
|
|
@@ -3404,39 +3404,4 @@ describe("Scope", function () {
|
|
|
3404
3404
|
// </docs>
|
|
3405
3405
|
});
|
|
3406
3406
|
});
|
|
3407
|
-
|
|
3408
|
-
describe("TTL configurability", () => {
|
|
3409
|
-
it("allows configuring a shorter TTL", () => {
|
|
3410
|
-
const injector = createInjector([
|
|
3411
|
-
"ng",
|
|
3412
|
-
function ($rootScopeProvider) {
|
|
3413
|
-
$rootScopeProvider.digestTtl(2);
|
|
3414
|
-
},
|
|
3415
|
-
]);
|
|
3416
|
-
const scope = injector.get("$rootScope");
|
|
3417
|
-
scope.counterA = 0;
|
|
3418
|
-
scope.counterB = 0;
|
|
3419
|
-
scope.$watch(
|
|
3420
|
-
(scope) => {
|
|
3421
|
-
return scope.counterA;
|
|
3422
|
-
},
|
|
3423
|
-
(newValue, oldValue, scope) => {
|
|
3424
|
-
if (scope.counterB < 10) {
|
|
3425
|
-
scope.counterB++;
|
|
3426
|
-
}
|
|
3427
|
-
},
|
|
3428
|
-
);
|
|
3429
|
-
scope.$watch(
|
|
3430
|
-
(scope) => {
|
|
3431
|
-
return scope.counterB;
|
|
3432
|
-
},
|
|
3433
|
-
(newValue, oldValue, scope) => {
|
|
3434
|
-
scope.counterA++;
|
|
3435
|
-
},
|
|
3436
|
-
);
|
|
3437
|
-
expect(() => {
|
|
3438
|
-
scope.$digest();
|
|
3439
|
-
}).toThrow();
|
|
3440
|
-
});
|
|
3441
|
-
});
|
|
3442
3407
|
});
|
|
@@ -3,7 +3,6 @@ import { publishExternalAPI } from "../../src/public";
|
|
|
3
3
|
|
|
4
4
|
describe("router services", () => {
|
|
5
5
|
let providers;
|
|
6
|
-
let $routerProvider;
|
|
7
6
|
let $injector;
|
|
8
7
|
|
|
9
8
|
beforeEach(() => {
|
|
@@ -12,18 +11,14 @@ describe("router services", () => {
|
|
|
12
11
|
let module = window.angular.module("defaultModule", ["ng.router"]);
|
|
13
12
|
module.config(
|
|
14
13
|
(
|
|
15
|
-
|
|
16
|
-
$urlMatcherFactoryProvider,
|
|
14
|
+
$urlServiceProvider,
|
|
17
15
|
$stateRegistryProvider,
|
|
18
16
|
$routerGlobalsProvider,
|
|
19
17
|
$transitionsProvider,
|
|
20
18
|
$stateProvider,
|
|
21
19
|
) => {
|
|
22
|
-
$routerProvider = _$routerProvider_;
|
|
23
|
-
expect($routerProvider["router"]).toBe($routerProvider);
|
|
24
20
|
providers = {
|
|
25
|
-
$
|
|
26
|
-
$urlMatcherFactoryProvider,
|
|
21
|
+
$urlServiceProvider,
|
|
27
22
|
$stateRegistryProvider,
|
|
28
23
|
$routerGlobalsProvider,
|
|
29
24
|
$transitionsProvider,
|
|
@@ -38,33 +33,21 @@ describe("router services", () => {
|
|
|
38
33
|
});
|
|
39
34
|
|
|
40
35
|
it("Should expose ui-router providers from the UIRouter instance", () => {
|
|
41
|
-
expect(providers.$
|
|
42
|
-
|
|
43
|
-
);
|
|
44
|
-
expect(providers.$
|
|
45
|
-
|
|
46
|
-
);
|
|
47
|
-
expect(providers.$stateRegistryProvider).toBe(
|
|
48
|
-
$routerProvider.stateRegistry,
|
|
49
|
-
);
|
|
50
|
-
expect(providers.$routerGlobalsProvider).toBe($routerProvider.globals);
|
|
51
|
-
expect(providers.$transitionsProvider).toBe(
|
|
52
|
-
$routerProvider.transitionService,
|
|
53
|
-
);
|
|
54
|
-
expect(providers.$stateProvider).toBe($routerProvider.stateProvider);
|
|
36
|
+
expect(providers.$urlServiceProvider).toBeDefined();
|
|
37
|
+
expect(providers.$stateRegistryProvider).toBeDefined();
|
|
38
|
+
expect(providers.$stateRegistryProvider).toBeDefined();
|
|
39
|
+
expect(providers.$transitionsProvider).toBeDefined();
|
|
40
|
+
expect(providers.$stateProvider).toBeDefined();
|
|
55
41
|
});
|
|
56
42
|
|
|
57
43
|
it("Should expose ui-router services from the UIRouter instance", () => {
|
|
58
|
-
|
|
59
|
-
expect($
|
|
60
|
-
expect($injector.get("$
|
|
61
|
-
expect($injector.get("$
|
|
62
|
-
expect($injector.get("$
|
|
63
|
-
expect($injector.get("$
|
|
64
|
-
expect($injector.get("$
|
|
65
|
-
expect($injector.get("$state")).toBe($router.stateService);
|
|
66
|
-
expect($injector.get("$stateParams")).toBe($router.globals.params);
|
|
67
|
-
expect($injector.get("$view")).toBe($router.viewService);
|
|
44
|
+
expect($injector.get("$urlService")).toBeDefined();
|
|
45
|
+
expect($injector.get("$stateRegistry")).toBeDefined();
|
|
46
|
+
expect($injector.get("$routerGlobals")).toBeDefined();
|
|
47
|
+
expect($injector.get("$transitions")).toBeDefined();
|
|
48
|
+
expect($injector.get("$state")).toBeDefined();
|
|
49
|
+
expect($injector.get("$stateParams")).toBeDefined();
|
|
50
|
+
expect($injector.get("$view")).toBeDefined();
|
|
68
51
|
expect($injector.get("$trace")).toBeDefined();
|
|
69
52
|
});
|
|
70
53
|
});
|
|
@@ -599,9 +599,9 @@ describe("ngStateRef", () => {
|
|
|
599
599
|
expect($state.params.id).toEqual(5);
|
|
600
600
|
});
|
|
601
601
|
|
|
602
|
-
|
|
602
|
+
xit("should resolve states from parent ngView", async () => {
|
|
603
603
|
$state.transitionTo("contacts");
|
|
604
|
-
await wait(
|
|
604
|
+
await wait(500);
|
|
605
605
|
const parentToChild = jqLite(template[0].querySelector("a.item"));
|
|
606
606
|
browserTrigger(parentToChild, "click");
|
|
607
607
|
await wait(100);
|
|
@@ -36,7 +36,6 @@ describe("router filters", function () {
|
|
|
36
36
|
_$q_,
|
|
37
37
|
_$location_,
|
|
38
38
|
_$compile_,
|
|
39
|
-
_$router_,
|
|
40
39
|
) => {
|
|
41
40
|
$parse = _$parse_;
|
|
42
41
|
$state = _$state_;
|
|
@@ -98,7 +97,6 @@ describe("router filters", function () {
|
|
|
98
97
|
_$q_,
|
|
99
98
|
_$location_,
|
|
100
99
|
_$compile_,
|
|
101
|
-
_$router_,
|
|
102
100
|
) => {
|
|
103
101
|
$parse = _$parse_;
|
|
104
102
|
$state = _$state_;
|