@angular-wave/angular.ts 0.0.33 → 0.0.35

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@angular-wave/angular.ts",
3
3
  "license": "MIT",
4
- "version": "0.0.33",
4
+ "version": "0.0.35",
5
5
  "type": "module",
6
6
  "main": "dist/angular-ts.esm.js",
7
7
  "browser": "dist/angular-ts.umd.js",
@@ -21,6 +21,13 @@ export const ScopePhase = {
21
21
  DIGEST: 2,
22
22
  };
23
23
 
24
+ /**
25
+ * @typedef {Object} AsyncQueueTask
26
+ * @property {Scope} scope
27
+ * @property {Function} fn
28
+ * @property {Object} locals
29
+ */
30
+
24
31
  /**
25
32
  *
26
33
  * The default number of `$digest` iterations the scope should attempt to execute before giving up and
@@ -34,6 +41,8 @@ export const ScopePhase = {
34
41
  export const TTL = 10;
35
42
 
36
43
  const $rootScopeMinErr = minErr("$rootScope");
44
+
45
+ /** @type {AsyncQueueTask[]} */
37
46
  const $$asyncQueue = [];
38
47
  const $$postDigestQueue = [];
39
48
  const $$applyAsyncQueue = [];
@@ -122,9 +131,9 @@ export function getQueues() {
122
131
  };
123
132
  }
124
133
 
125
- /**
126
- * @type {angular.IScope}
127
- */
134
+ // /**
135
+ // * @type {angular.Scope}
136
+ // */
128
137
  class Scope {
129
138
  constructor() {
130
139
  /**
@@ -136,35 +145,68 @@ class Scope {
136
145
  this.$$phase = ScopePhase.NONE;
137
146
 
138
147
  /**
139
- * @type {?angular.IScope} Reference to the parent scope.
148
+ * @type {?Scope} Reference to the parent scope.
140
149
  */
141
150
  this.$parent = null;
142
151
 
143
152
  /**
144
- * @type {?angular.IScope}
153
+ * @type {?Scope}
145
154
  */
146
155
  this.$root = this;
147
156
 
148
- this.$$watchers = null;
157
+ /** @type {Array} */
158
+ this.$$watchers = [];
159
+
160
+ /**
161
+ * @type {number}
162
+ */
163
+ this.$$digestWatchIndex = -1;
164
+
165
+ /**
166
+ * @type {?Scope}
167
+ */
149
168
  this.$$nextSibling = null;
169
+
170
+ /**
171
+ * @type {?Scope}
172
+ */
150
173
  this.$$prevSibling = null;
174
+
175
+ /**
176
+ * @type {?Scope}
177
+ */
151
178
  this.$$childHead = null;
179
+
180
+ /**
181
+ * @type {?Scope}
182
+ */
152
183
  this.$$childTail = null;
184
+
185
+ /** @type {boolean} */
153
186
  this.$$destroyed = false;
187
+
188
+ // TODO use maps
189
+ /** @type {boolean} */
154
190
  this.$$suspended = false;
191
+
192
+ // TODO use maps
193
+ /** @type {object} */
155
194
  this.$$listeners = {};
195
+
196
+ /** @type {object} */
156
197
  this.$$listenerCount = {};
198
+
199
+ /** @type {number} */
157
200
  this.$$watchersCount = 0;
158
201
  this.$$isolateBindings = null;
159
202
 
160
203
  /**
161
- * @type {Scope}
204
+ * @type {?Scope}
162
205
  */
163
206
  this.$$ChildScope = null;
164
207
  }
165
208
 
166
209
  /**
167
- * @description
168
210
  * Creates a new child {@link Scope}.
169
211
  *
170
212
  * The parent scope will propagate the {@link ng.$rootScope.Scope#$digest $digest()} event.
@@ -179,24 +221,25 @@ class Scope {
179
221
  * When creating widgets, it is useful for the widget to not accidentally read parent
180
222
  * state.
181
223
  *
182
- * @param {?angular.IScope} [parent=this] The {@link ng.$rootScope.Scope `Scope`} that will be the `$parent`
224
+ * @param {?Scope} [parent=this] The {@link ng.$rootScope.Scope `Scope`} that will be the `$parent`
183
225
  * of the newly created scope. Defaults to `this` scope if not provided.
184
226
  * This is used when creating a transclude scope to correctly place it
185
227
  * in the scope hierarchy while maintaining the correct prototypical
186
228
  * inheritance.
187
229
  *
188
- * @returns {angular.IScope} The newly created child scope.
230
+ * @returns {Scope} The newly created child scope.
189
231
  *
190
232
  */
191
233
  $new(isolate, parent) {
234
+ /** @type {Scope} */
192
235
  let child;
193
236
  if (isolate) {
194
237
  child = new Scope();
195
- child.$root = this.$root;
238
+ child.$root = rootScope;
196
239
  } else {
197
240
  child = Object.create(this);
198
241
  child.$id = nextUid();
199
- child.$$watchers = null;
242
+ child.$$watchers = [];
200
243
  child.$$nextSibling = null;
201
244
  child.$$childHead = null;
202
245
  child.$$childTail = null;
@@ -206,6 +249,7 @@ class Scope {
206
249
  child.$$ChildScope = null;
207
250
  child.$$suspended = false;
208
251
  }
252
+
209
253
  child.$parent = parent || this;
210
254
  child.$$prevSibling = child.$parent.$$childTail;
211
255
  if (child.$parent.$$childHead) {
@@ -222,9 +266,13 @@ class Scope {
222
266
  // when the parent scope is destroyed.
223
267
  // The listener needs to be added after the parent is set
224
268
  if (isolate || parent !== this) {
225
- child.$on("$destroy", ($event) => {
226
- $event.currentScope.$$destroyed = true;
227
- });
269
+ child.$on(
270
+ "$destroy",
271
+ /** @param {angular.IAngularEvent} $event */
272
+ ($event) => {
273
+ $event.currentScope.$$destroyed = true;
274
+ },
275
+ );
228
276
  }
229
277
  return child;
230
278
  }
@@ -352,8 +400,7 @@ class Scope {
352
400
  if (get.$$watchDelegate) {
353
401
  return get.$$watchDelegate(this, fn, objectEquality, get, watchExp);
354
402
  }
355
- const scope = this;
356
- let array = scope.$$watchers;
403
+
357
404
  const watcher = {
358
405
  fn,
359
406
  last: initWatchVal,
@@ -364,23 +411,21 @@ class Scope {
364
411
 
365
412
  lastDirtyWatch = null;
366
413
 
367
- if (!array) {
368
- array = scope.$$watchers = [];
369
- array.$$digestWatchIndex = -1;
414
+ if (this.$$watchers.length == 0) {
415
+ this.$$digestWatchIndex = -1;
370
416
  }
371
417
  // we use unshift since we use a while loop in $digest for speed.
372
418
  // the while loop reads in reverse order.
373
- array.unshift(watcher);
374
- array.$$digestWatchIndex++;
419
+ this.$$watchers.unshift(watcher);
420
+ this.$$digestWatchIndex++;
375
421
  this.incrementWatchersCount(1);
376
- const self = this;
377
422
 
378
- return function deregisterWatch() {
379
- const index = arrayRemove(array, watcher);
423
+ return () => {
424
+ const index = arrayRemove(this.$$watchers, watcher);
380
425
  if (index >= 0) {
381
- self.incrementWatchersCount(-1);
382
- if (index < array.$$digestWatchIndex) {
383
- array.$$digestWatchIndex--;
426
+ this.incrementWatchersCount(-1);
427
+ if (index < this.$$digestWatchIndex) {
428
+ this.$$digestWatchIndex--;
384
429
  }
385
430
  }
386
431
  lastDirtyWatch = null;
@@ -715,7 +760,7 @@ class Scope {
715
760
  let ttl = TTL;
716
761
  let next;
717
762
  /**
718
- * @type {angular.IScope}
763
+ * @type {Scope}
719
764
  */
720
765
  let current;
721
766
  const target = $$asyncQueue.length ? this.$root : this;
@@ -731,7 +776,7 @@ class Scope {
731
776
  if (this === this.$root && applyAsyncId !== null) {
732
777
  // If this is the root scope, and $applyAsync has scheduled a deferred $apply(), then
733
778
  // cancel the scheduled $apply and flush the queue of expressions to be evaluated.
734
- $browser.defer.cancel(applyAsyncId);
779
+ $browser.cancel(applyAsyncId);
735
780
  flushApplyAsync();
736
781
  applyAsyncId = null;
737
782
  }
@@ -765,10 +810,10 @@ class Scope {
765
810
  // "traverse the scopes" loop
766
811
  if ((watchers = !current.$$suspended && current.$$watchers)) {
767
812
  // process our watches
768
- watchers.$$digestWatchIndex = watchers.length;
769
- while (watchers.$$digestWatchIndex--) {
813
+ current.$$digestWatchIndex = watchers.length;
814
+ while (current.$$digestWatchIndex--) {
770
815
  try {
771
- watch = watchers[watchers.$$digestWatchIndex];
816
+ watch = watchers[current.$$digestWatchIndex];
772
817
  // Most common watches are on primitives, in which case we can short
773
818
  // circuit it with === operator, only when === fails do we use .equals
774
819
  if (watch) {
@@ -1072,7 +1117,7 @@ class Scope {
1072
1117
  expect(scope.$eval(function(scope){ return scope.a + scope.b; })).toEqual(3);
1073
1118
  * ```
1074
1119
  *
1075
- * @param {(string|function())=} expr An AngularJS expression to be executed.
1120
+ * @param {string|function(Scope): any} [expr] An AngularJS expression to be executed.
1076
1121
  *
1077
1122
  * - `string`: execute using the rules as defined in {@link guide/expression expression}.
1078
1123
  * - `function(scope)`: execute the function with the current `scope` parameter.
@@ -1180,7 +1225,7 @@ class Scope {
1180
1225
  * expression was executed using the {@link ng.$rootScope.Scope#$digest $digest()} method.
1181
1226
  *
1182
1227
  *
1183
- * @param {(string|function())=} expr An AngularJS expression to be executed.
1228
+ * @param {string|function(Scope): any} [expr] An AngularJS expression to be executed.
1184
1229
  *
1185
1230
  * - `string`: execute using the rules as defined in {@link guide/expression expression}.
1186
1231
  * - `function(scope)`: execute the function with current `scope` parameter.
@@ -1261,7 +1306,7 @@ class Scope {
1261
1306
  * - `defaultPrevented` - `{boolean}`: true if `preventDefault` was called.
1262
1307
  *
1263
1308
  * @param {string} name Event name to listen on.
1264
- * @param {function(event, ...args)} listener Function to call when the event is emitted.
1309
+ * @param {function(angular.IAngularEvent): any} listener Function to call when the event is emitted.
1265
1310
  * @returns {function()} Returns a deregistration function for this listener.
1266
1311
  */
1267
1312
  $on(name, listener) {
@@ -103,7 +103,7 @@ export function $timeout($rootScope, $browser, $q, $$q, $exceptionHandler) {
103
103
  deferred.reject("canceled");
104
104
  delete deferreds[id];
105
105
 
106
- return $browser.defer.cancel(id);
106
+ return $browser.cancel(id);
107
107
  };
108
108
 
109
109
  return timeout;
@@ -727,7 +727,7 @@ function baseInputType(scope, element, attr, ctrl, $browser) {
727
727
 
728
728
  let listener = function (ev) {
729
729
  if (timeout) {
730
- $browser.defer.cancel(timeout);
730
+ $browser.cancel(timeout);
731
731
  timeout = null;
732
732
  }
733
733
  if (composing) return;
@@ -6,7 +6,6 @@
6
6
  *
7
7
  * The optional [[$resolve]] service is also documented here.
8
8
  *
9
- * @preferred @publicapi @module ng1
10
9
  */
11
10
  import { services } from "./common/coreservices";
12
11
  import { unnestR } from "../shared/common";
@@ -243,7 +243,7 @@ export function Browser($log, $$taskTrackerFactory) {
243
243
  * @param {function()} fn A function, who's execution should be deferred.
244
244
  * @param {number=} [delay=0] Number of milliseconds to defer the function execution.
245
245
  * @param {string=} [taskType=DEFAULT_TASK_TYPE] The type of task that is deferred.
246
- * @returns {*} DeferId that can be used to cancel the task via `$browser.defer.cancel()`.
246
+ * @returns {*} DeferId that can be used to cancel the task via `$browser.cancel()`.
247
247
  *
248
248
  * @description
249
249
  * Executes a fn asynchronously via `setTimeout(fn, delay)`.
@@ -270,7 +270,7 @@ export function Browser($log, $$taskTrackerFactory) {
270
270
  };
271
271
 
272
272
  /**
273
- * @name $browser#defer.cancel
273
+ * @name $browser#cancel
274
274
  *
275
275
  * @description
276
276
  * Cancels a deferred task identified with `deferId`.
@@ -279,7 +279,7 @@ export function Browser($log, $$taskTrackerFactory) {
279
279
  * @returns {boolean} Returns `true` if the task hasn't executed yet and was successfully
280
280
  * canceled.
281
281
  */
282
- self.defer.cancel = function (deferId) {
282
+ self.cancel = function (deferId) {
283
283
  if (Object.prototype.hasOwnProperty.call(pendingDeferIds, deferId)) {
284
284
  const taskType = pendingDeferIds[deferId];
285
285
  delete pendingDeferIds[deferId];
@@ -1,3 +1,4 @@
1
+ import { ScopePhase } from "../core/root-scope";
1
2
  import { urlIsAllowedOriginFactory } from "../core/urlUtils";
2
3
  import {
3
4
  minErr,
@@ -3486,6 +3486,19 @@ describe("parser", () => {
3486
3486
  });
3487
3487
 
3488
3488
  describe("with primitive input", () => {
3489
+ beforeEach(() => {
3490
+ createInjector([
3491
+ "ng",
3492
+ function ($filterProvider) {
3493
+ filterProvider = $filterProvider;
3494
+ },
3495
+ ]).invoke((_$rootScope_, _$parse_) => {
3496
+ scope = _$rootScope_;
3497
+ $parse = _$parse_;
3498
+ });
3499
+ logs = [];
3500
+ });
3501
+
3489
3502
  it("should not be reevaluated when passed literals", () => {
3490
3503
  let filterCalls = 0;
3491
3504
  filterProvider.register(
@@ -2630,7 +2630,7 @@ describe("Scope", function () {
2630
2630
  const scope = $rootScope.$new();
2631
2631
  let id = scope.$applyAsync('x = "CODE ORANGE"');
2632
2632
 
2633
- $browser.defer.cancel(id);
2633
+ $browser.cancel(id);
2634
2634
  setTimeout(() => {
2635
2635
  expect(scope.x).toBe("CODE ORANGE");
2636
2636
  expect($rootScope.x).toBeUndefined();
@@ -2644,8 +2644,8 @@ describe("Scope", function () {
2644
2644
  let id1 = $rootScope.$applyAsync('x.push("expr1")');
2645
2645
  let id2 = $rootScope.$applyAsync('x.push("expr2")');
2646
2646
 
2647
- $browser.defer.cancel(id1);
2648
- $browser.defer.cancel(id2);
2647
+ $browser.cancel(id1);
2648
+ $browser.cancel(id2);
2649
2649
  setTimeout(() => {
2650
2650
  expect($rootScope.x).toEqual(["expr1", "expr2"]);
2651
2651
  });
@@ -2660,7 +2660,7 @@ describe("Scope", function () {
2660
2660
  expect($browser.deferredFns.length).toBe(0);
2661
2661
  });
2662
2662
 
2663
- $browser.defer.cancel(id);
2663
+ $browser.cancel(id);
2664
2664
  setTimeout(() => {
2665
2665
  expect($rootScope.x).toEqual(["expr1", "expr2"]);
2666
2666
  });
@@ -2672,7 +2672,7 @@ describe("Scope", function () {
2672
2672
  throw "OOPS";
2673
2673
  });
2674
2674
 
2675
- $browser.defer.cancel(id);
2675
+ $browser.cancel(id);
2676
2676
  expect(logs).toEqual([]);
2677
2677
  setTimeout(() => expect(logs[0]).toEqual("OOPS"));
2678
2678
  });
@@ -2683,14 +2683,14 @@ describe("Scope", function () {
2683
2683
  });
2684
2684
  let id2 = $rootScope.$applyAsync('x = "All good!"');
2685
2685
 
2686
- $browser.defer.cancel(id);
2687
- $browser.defer.cancel(id2);
2686
+ $browser.cancel(id);
2687
+ $browser.cancel(id2);
2688
2688
  setTimeout(() => expect($rootScope.x).toBe("All good!"));
2689
2689
  expect($rootScope.x).toBeUndefined();
2690
2690
  });
2691
2691
 
2692
2692
  it("should be cancelled if a $rootScope digest occurs before the next tick", () => {
2693
- const cancel = spyOn($browser.defer, "cancel").and.callThrough();
2693
+ const cancel = spyOn($browser, "cancel").and.callThrough();
2694
2694
  const expression = jasmine.createSpy("expr");
2695
2695
 
2696
2696
  $rootScope.$applyAsync(expression);
@@ -325,7 +325,7 @@ describe("$timeout", () => {
325
325
  });
326
326
 
327
327
  it("should forget references to relevant deferred", () => {
328
- // $browser.defer.cancel is only called on cancel if the deferred object is still referenced
328
+ // $browser.cancel is only called on cancel if the deferred object is still referenced
329
329
  const cancelSpy = spyOn($browser.defer, "cancel").and.callThrough();
330
330
 
331
331
  const promise = $timeout(() => {}, 0, false);