@angular-wave/angular.ts 0.0.22 → 0.0.23

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/index.html CHANGED
@@ -103,8 +103,12 @@
103
103
  <script type="module" src="test/router/state-directives.spec.js"></script>
104
104
  <script type="module" src="test/router/state-filter.spec.js"></script>
105
105
  <script type="module" src="test/router/state.spec.js"></script>
106
-
107
-
106
+ <script type="module" src="test/router/template-factory.spec.js"></script>
107
+ <script type="module" src="test/router/url-matcher-factory.spec.js"></script>
108
+ <script type="module" src="test/router/view-directive.spec.js"></script>
109
+ <script type="module" src="test/router/view-hook.spec.js"></script>
110
+ <script type="module" src="test/router/view-scroll.spec.js"></script>
111
+ <script type="module" src="test/router/view.spec.js"></script>
108
112
 
109
113
  <!-- Run asyncs last to prevent digest polution-->
110
114
  <script type="module" src="test/core/interval.spec.js"></script>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@angular-wave/angular.ts",
3
3
  "license": "MIT",
4
- "version": "0.0.22",
4
+ "version": "0.0.23",
5
5
  "type": "module",
6
6
  "main": "dist/angular-ts.esm.js",
7
7
  "browser": "dist/angular-ts.umd.js",
@@ -12,7 +12,7 @@ orderByFilter.$inject = ["$parse"];
12
12
 
13
13
  /**
14
14
  *
15
- * @param {angular.IFilterOrderBy} $parse
15
+ * @param {angular.IParseService} $parse
16
16
  * @returns
17
17
  */
18
18
  export function orderByFilter($parse) {
@@ -90,12 +90,12 @@ export function orderByFilter($parse) {
90
90
  predicate = predicate.substring(1);
91
91
  }
92
92
  if (predicate !== "") {
93
- get = $parse(predicate);
94
- if (get.constant) {
95
- const key = get();
96
- get = function (value) {
97
- return value[key];
98
- };
93
+ let parsed = $parse(predicate);
94
+ if (parsed.constant) {
95
+ const key = parsed();
96
+ get = (value) => value[key];
97
+ } else {
98
+ get = parsed;
99
99
  }
100
100
  }
101
101
  }
@@ -130,7 +130,7 @@ export function orderByFilter($parse) {
130
130
  }
131
131
 
132
132
  function getPredicateValue(value, index) {
133
- let type = typeof value;
133
+ /** @type {String} */ let type = typeof value;
134
134
  if (value === null) {
135
135
  type = "null";
136
136
  } else if (type === "object") {
@@ -143,18 +143,10 @@ export let uiView = [
143
143
  function getRenderer() {
144
144
  return {
145
145
  enter: function (element, target, cb) {
146
- // if (angular.version.minor > 2) {
147
- //$animate.enter(element, null, target).then(cb);
148
- // } else {
149
- $animate.enter(element, null, target, cb);
150
- // }
146
+ $animate.enter(element, null, target).then(cb);
151
147
  },
152
148
  leave: function (element, cb) {
153
- // if (angular.version.minor > 2) {
154
- //$animate.leave(element).then(cb);
155
- // } else {
156
- $animate.leave(element, cb);
157
- // }
149
+ $animate.leave(element).then(cb);
158
150
  },
159
151
  };
160
152
  }
@@ -273,7 +265,7 @@ export let uiView = [
273
265
  const cloned = $transclude(newScope, function (clone) {
274
266
  clone.data("$uiViewAnim", $uiViewAnim);
275
267
  clone.data("$uiView", $uiViewData);
276
- renderer.enter(clone, $element, function onUIViewEnter() {
268
+ renderer.enter(clone, $element, function () {
277
269
  animEnter.resolve();
278
270
  if (currentScope)
279
271
  currentScope.$emit("$viewContentAnimationEnded");
@@ -5,14 +5,20 @@ import { createProxyFunctions } from "../shared/common";
5
5
  import { minErr } from "../shared/utils";
6
6
 
7
7
  const err = minErr("$stateProvider");
8
+ // Right now this is a collection of all the properties we encounter in tests
8
9
  const validKeys = [
9
10
  "$$state",
10
11
  "__stateObjectCache",
12
+ "abstract",
13
+ "bindings",
11
14
  "controller",
15
+ "controllerAs",
12
16
  "controllerProvider",
13
17
  "component",
18
+ "componentProvider",
14
19
  "data",
15
20
  "includes",
21
+ "lazyLoad",
16
22
  "name",
17
23
  "navigable",
18
24
  "onEnter",
@@ -21,8 +27,10 @@ const validKeys = [
21
27
  "params",
22
28
  "parent",
23
29
  "path",
30
+ "redirectTo",
24
31
  "reloadOnSearch",
25
32
  "resolve",
33
+ "resolveAs",
26
34
  "resolvables",
27
35
  "self",
28
36
  "template",
@@ -10,15 +10,13 @@ import { kebobString } from "../shared/strings";
10
10
  */
11
11
  export class TemplateFactory {
12
12
  constructor() {
13
- /** @hidden */ this.$get = [
13
+ this._useHttp = false;
14
+ this.$get = [
14
15
  "$http",
15
16
  "$templateCache",
16
- "$injector",
17
- ($http, $templateCache, $injector) => {
18
- this.$templateRequest =
19
- $injector.has &&
20
- $injector.has("$templateRequest") &&
21
- $injector.get("$templateRequest");
17
+ "$templateRequest",
18
+ ($http, $templateCache, $templateRequest) => {
19
+ this.$templateRequest = $templateRequest;
22
20
  this.$http = $http;
23
21
  this.$templateCache = $templateCache;
24
22
  return this;
@@ -26,6 +24,14 @@ export class TemplateFactory {
26
24
  ];
27
25
  }
28
26
 
27
+ /**
28
+ * Forces the provider to use $http service directly
29
+ * @param {boolean} value
30
+ */
31
+ useHttpService(value) {
32
+ this._useHttp = value;
33
+ }
34
+
29
35
  /**
30
36
  * Creates a template from a configuration object.
31
37
  *
@@ -358,7 +358,11 @@ export class Transition {
358
358
  : new Resolvable(resolvable);
359
359
  const stateName = typeof state === "string" ? state : state.name;
360
360
  const topath = this._treeChanges.to;
361
- const targetNode = find(topath, (node) => node.state.name === stateName);
361
+ const targetNode = find(topath, (node) => {
362
+ return node.state.name === stateName;
363
+ });
364
+ console.assert(targetNode, `targetNode not found ${stateName}`);
365
+
362
366
  const resolveContext = new ResolveContext(topath);
363
367
  resolveContext.addResolvables([resolvable], targetNode.state);
364
368
  }
@@ -20,6 +20,13 @@ export class UrlRuleFactory {
20
20
  compile(str) {
21
21
  return this.router.urlMatcherFactory.compile(str);
22
22
  }
23
+
24
+ /**
25
+ *
26
+ * @param {*} what
27
+ * @param {*} handler
28
+ * @returns {BaseUrlRule}
29
+ */
23
30
  create(what, handler) {
24
31
  const { isState, isStateDeclaration } = StateObject;
25
32
  const makeRule = pattern([
@@ -193,12 +200,13 @@ UrlRuleFactory.isUrlRule = (obj) =>
193
200
  * A base rule which calls `match`
194
201
  *
195
202
  * The value from the `match` function is passed through to the `handler`.
196
- * @internal
203
+ * @type {angular.BaseUrlRule}
197
204
  */
198
205
  export class BaseUrlRule {
199
206
  constructor(match, handler) {
200
207
  this.match = match;
201
208
  this.type = "RAW";
209
+ this.$id = -1;
202
210
  this.matchPriority = () => 0 - this.$id;
203
211
  this.handler = handler || identity;
204
212
  }
@@ -5,18 +5,11 @@ import { forEach, isUndefined, equals } from "../shared/utils";
5
5
  // This variable should be used *only* inside the cacheState function.
6
6
  let lastCachedState = null;
7
7
 
8
- export function getHash(url) {
9
- const index = url.indexOf("#");
10
- return index === -1 ? "" : url.substr(index);
11
- }
12
-
13
8
  export function trimEmptyHash(url) {
14
9
  return url.replace(/#$/, "");
15
10
  }
16
11
 
17
12
  /**
18
- *
19
- *
20
13
  * @name $browser
21
14
  * @requires $log
22
15
  * @description
@@ -32,8 +25,6 @@ export function trimEmptyHash(url) {
32
25
  */
33
26
  export function Browser($log, $$taskTrackerFactory) {
34
27
  const self = this;
35
- let { location } = window;
36
- let { history } = window;
37
28
  const { setTimeout } = window;
38
29
  const { clearTimeout } = window;
39
30
  const pendingDeferIds = {};
@@ -56,10 +47,8 @@ export function Browser($log, $$taskTrackerFactory) {
56
47
 
57
48
  let cachedState;
58
49
  let lastHistoryState;
59
- let lastBrowserUrl = location.href;
60
- const baseElement = jqLite(
61
- Array.from(window.document.getElementsByTagName("base")),
62
- );
50
+ let lastBrowserUrl = window.location.href;
51
+ const baseElement = jqLite(Array.from(document.getElementsByTagName("base")));
63
52
  let pendingLocation = null;
64
53
  const getCurrentState = function getCurrentState() {
65
54
  return history.state;
@@ -96,10 +85,6 @@ export function Browser($log, $$taskTrackerFactory) {
96
85
  state = null;
97
86
  }
98
87
 
99
- // Android Browser BFCache causes location, history reference to become stale.
100
- if (location !== window.location) location = window.location;
101
- if (history !== window.history) history = window.history;
102
-
103
88
  // setter
104
89
  if (url) {
105
90
  const sameState = lastHistoryState === state;
@@ -129,7 +114,7 @@ export function Browser($log, $$taskTrackerFactory) {
129
114
  // - pendingLocation is needed as browsers don't allow to read out
130
115
  // the new location.href if a reload happened or if there is a bug like in iOS 9 (see
131
116
  // https://openradar.appspot.com/22186109).
132
- return trimEmptyHash(pendingLocation || location.href);
117
+ return trimEmptyHash(pendingLocation || window.location.href);
133
118
  };
134
119
 
135
120
  /**
@@ -0,0 +1,81 @@
1
+ import { StateBuilder } from "../../src/router/state/stateBuilder";
2
+
3
+ describe("Ng1 StateBuilder", function () {
4
+ const parent = { name: "" };
5
+ let builder,
6
+ matcher,
7
+ urlMatcherFactoryProvider = {
8
+ compile: function () {},
9
+ isMatcher: function () {},
10
+ };
11
+
12
+ beforeEach(function () {
13
+ matcher = new StateBuilder({});
14
+ builder = new StateBuilder(matcher, urlMatcherFactoryProvider);
15
+ builder.builder("views", ng1ViewsBuilder);
16
+ });
17
+
18
+ it("should use the state object to build a default view, when no `views` property is found", function () {
19
+ const config = {
20
+ url: "/foo",
21
+ templateUrl: "/foo.html",
22
+ controller: "FooController",
23
+ parent: parent,
24
+ };
25
+ const built = builder.builder("views")(config);
26
+
27
+ expect(built.$default).not.toEqual(config);
28
+ expect(built.$default).toEqual(
29
+ expect.objectContaining({
30
+ templateUrl: "/foo.html",
31
+ controller: "FooController",
32
+ resolveAs: "$resolve",
33
+ }),
34
+ );
35
+ });
36
+
37
+ it("It should use the views object to build views, when defined", function () {
38
+ const config = { a: { foo: "bar", controller: "FooController" } };
39
+ const builtViews = builder.builder("views")({
40
+ parent: parent,
41
+ views: config,
42
+ });
43
+ expect(builtViews.a.foo).toEqual(config.a.foo);
44
+ expect(builtViews.a.controller).toEqual(config.a.controller);
45
+ });
46
+
47
+ it("should not allow a view config with both component and template keys", inject(function (
48
+ $injector,
49
+ ) {
50
+ const config = {
51
+ name: "foo",
52
+ url: "/foo",
53
+ template: "<h1>hey</h1>",
54
+ controller: "FooController",
55
+ parent: parent,
56
+ };
57
+ expect(() => builder.builder("views")(config)).not.toThrow();
58
+ expect(() =>
59
+ builder.builder("views")(
60
+ Object.assign({ component: "fooComponent" }, config),
61
+ ),
62
+ ).toThrow();
63
+ expect(() =>
64
+ builder.builder("views")(
65
+ Object.assign({ componentProvider: () => "fooComponent" }, config),
66
+ ),
67
+ ).toThrow();
68
+ expect(() =>
69
+ builder.builder("views")(Object.assign({ bindings: {} }, config)),
70
+ ).toThrow();
71
+ }));
72
+
73
+ it("should replace a resolve: string value with a function that injects the service of the same name", inject(function (
74
+ $injector,
75
+ ) {
76
+ const config = { resolve: { foo: "bar" } };
77
+ expect(builder.builder("resolvables")).toBeDefined();
78
+ const built = builder.builder("resolvables")(config);
79
+ expect(built[0].deps).toEqual(["bar"]);
80
+ }));
81
+ });
@@ -19,7 +19,6 @@ describe("router services", () => {
19
19
  $transitionsProvider,
20
20
  $stateProvider,
21
21
  ) => {
22
- debugger;
23
22
  $routerProvider = _$routerProvider_;
24
23
  expect($routerProvider["router"]).toBe($routerProvider);
25
24
  providers = {