@microsoft/fast-router 0.2.14 → 0.3.0
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/.eslintrc.json +21 -0
- package/CHANGELOG.json +69 -1
- package/CHANGELOG.md +26 -2
- package/dist/dts/commands.d.ts +7 -7
- package/dist/dts/configuration.d.ts +10 -10
- package/dist/dts/contributors.d.ts +1 -1
- package/dist/dts/events.d.ts +5 -5
- package/dist/dts/fast-router.d.ts +1 -1
- package/dist/dts/index-rollup.d.ts +1 -1
- package/dist/dts/index.d.ts +13 -13
- package/dist/dts/navigation.d.ts +1 -1
- package/dist/dts/phases.d.ts +2 -2
- package/dist/dts/process.d.ts +4 -4
- package/dist/dts/recognizer.d.ts +1 -1
- package/dist/dts/router.d.ts +4 -4
- package/dist/dts/routes.d.ts +5 -5
- package/dist/dts/view.d.ts +1 -1
- package/dist/esm/commands.js +3 -3
- package/dist/esm/configuration.js +9 -9
- package/dist/esm/contributors.js +1 -1
- package/dist/esm/fast-router.js +1 -1
- package/dist/esm/index-rollup.js +1 -1
- package/dist/esm/index.js +13 -13
- package/dist/esm/links.js +1 -1
- package/dist/esm/navigation.js +1 -1
- package/dist/esm/process.js +1 -1
- package/dist/esm/recognizer.js +1 -1
- package/dist/esm/router.js +3 -3
- package/dist/esm/routes.js +3 -3
- package/dist/esm/view.js +1 -1
- package/dist/fast-router.js +420 -342
- package/dist/fast-router.min.js +1 -1
- package/karma.conf.cjs +152 -0
- package/package.json +12 -11
package/dist/fast-router.js
CHANGED
|
@@ -94,6 +94,41 @@ if ($global.trustedTypes === void 0) {
|
|
|
94
94
|
createPolicy: (n, r) => r
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
|
+
|
|
98
|
+
const propConfig = {
|
|
99
|
+
configurable: false,
|
|
100
|
+
enumerable: false,
|
|
101
|
+
writable: false
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
if ($global.FAST === void 0) {
|
|
105
|
+
Reflect.defineProperty($global, "FAST", Object.assign({
|
|
106
|
+
value: Object.create(null)
|
|
107
|
+
}, propConfig));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The FAST global.
|
|
111
|
+
* @internal
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
const FAST = $global.FAST;
|
|
116
|
+
|
|
117
|
+
if (FAST.getById === void 0) {
|
|
118
|
+
const storage = Object.create(null);
|
|
119
|
+
Reflect.defineProperty(FAST, "getById", Object.assign({
|
|
120
|
+
value(id, initialize) {
|
|
121
|
+
let found = storage[id];
|
|
122
|
+
|
|
123
|
+
if (found === void 0) {
|
|
124
|
+
found = initialize ? storage[id] = initialize() : null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return found;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
}, propConfig));
|
|
131
|
+
}
|
|
97
132
|
/**
|
|
98
133
|
* A readonly, empty array.
|
|
99
134
|
* @remarks
|
|
@@ -105,33 +140,75 @@ if ($global.trustedTypes === void 0) {
|
|
|
105
140
|
|
|
106
141
|
const emptyArray = Object.freeze([]);
|
|
107
142
|
|
|
108
|
-
const updateQueue =
|
|
109
|
-
/*
|
|
143
|
+
const updateQueue = $global.FAST.getById(1
|
|
144
|
+
/* updateQueue */
|
|
145
|
+
, () => {
|
|
146
|
+
const tasks = [];
|
|
147
|
+
const pendingErrors = [];
|
|
110
148
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
149
|
+
function throwFirstError() {
|
|
150
|
+
if (pendingErrors.length) {
|
|
151
|
+
throw pendingErrors.shift();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function tryRunTask(task) {
|
|
156
|
+
try {
|
|
157
|
+
task.call();
|
|
158
|
+
} catch (error) {
|
|
159
|
+
pendingErrors.push(error);
|
|
160
|
+
setTimeout(throwFirstError, 0);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
115
163
|
|
|
116
|
-
|
|
164
|
+
function process() {
|
|
165
|
+
const capacity = 1024;
|
|
166
|
+
let index = 0;
|
|
167
|
+
|
|
168
|
+
while (index < tasks.length) {
|
|
169
|
+
tryRunTask(tasks[index]);
|
|
170
|
+
index++; // Prevent leaking memory for long chains of recursive calls to `DOM.queueUpdate`.
|
|
171
|
+
// If we call `DOM.queueUpdate` within a task scheduled by `DOM.queueUpdate`, the queue will
|
|
172
|
+
// grow, but to avoid an O(n) walk for every task we execute, we don't
|
|
173
|
+
// shift tasks off the queue after they have been executed.
|
|
174
|
+
// Instead, we periodically shift 1024 tasks off the queue.
|
|
117
175
|
|
|
118
|
-
|
|
176
|
+
if (index > capacity) {
|
|
177
|
+
// Manually shift all values starting at the index back to the
|
|
178
|
+
// beginning of the queue.
|
|
179
|
+
for (let scan = 0, newLength = tasks.length - index; scan < newLength; scan++) {
|
|
180
|
+
tasks[scan] = tasks[scan + index];
|
|
181
|
+
}
|
|
119
182
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
183
|
+
tasks.length -= index;
|
|
184
|
+
index = 0;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
tasks.length = 0;
|
|
123
189
|
}
|
|
124
|
-
}
|
|
125
190
|
|
|
126
|
-
function
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
191
|
+
function enqueue(callable) {
|
|
192
|
+
if (tasks.length < 1) {
|
|
193
|
+
$global.requestAnimationFrame(process);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
tasks.push(callable);
|
|
132
197
|
}
|
|
133
|
-
}
|
|
134
198
|
|
|
199
|
+
return Object.freeze({
|
|
200
|
+
enqueue,
|
|
201
|
+
process
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
/* eslint-disable */
|
|
205
|
+
|
|
206
|
+
const fastHTMLPolicy = $global.trustedTypes.createPolicy("fast-html", {
|
|
207
|
+
createHTML: html => html
|
|
208
|
+
});
|
|
209
|
+
/* eslint-enable */
|
|
210
|
+
|
|
211
|
+
let htmlPolicy = fastHTMLPolicy;
|
|
135
212
|
const marker = `fast-${Math.random().toString(36).substring(2, 8)}`;
|
|
136
213
|
/** @internal */
|
|
137
214
|
|
|
@@ -229,13 +306,7 @@ const DOM = Object.freeze({
|
|
|
229
306
|
* Schedules DOM update work in the next async batch.
|
|
230
307
|
* @param callable - The callable function or object to queue.
|
|
231
308
|
*/
|
|
232
|
-
queueUpdate
|
|
233
|
-
if (updateQueue.length < 1) {
|
|
234
|
-
window.requestAnimationFrame(DOM.processUpdates);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
updateQueue.push(callable);
|
|
238
|
-
},
|
|
309
|
+
queueUpdate: updateQueue.enqueue,
|
|
239
310
|
|
|
240
311
|
/**
|
|
241
312
|
* Immediately processes all work previously scheduled
|
|
@@ -244,40 +315,13 @@ const DOM = Object.freeze({
|
|
|
244
315
|
* This also forces nextUpdate promises
|
|
245
316
|
* to resolve.
|
|
246
317
|
*/
|
|
247
|
-
processUpdates
|
|
248
|
-
const capacity = 1024;
|
|
249
|
-
let index = 0;
|
|
250
|
-
|
|
251
|
-
while (index < updateQueue.length) {
|
|
252
|
-
tryRunTask(updateQueue[index]);
|
|
253
|
-
index++; // Prevent leaking memory for long chains of recursive calls to `DOM.queueUpdate`.
|
|
254
|
-
// If we call `DOM.queueUpdate` within a task scheduled by `DOM.queueUpdate`, the queue will
|
|
255
|
-
// grow, but to avoid an O(n) walk for every task we execute, we don't
|
|
256
|
-
// shift tasks off the queue after they have been executed.
|
|
257
|
-
// Instead, we periodically shift 1024 tasks off the queue.
|
|
258
|
-
|
|
259
|
-
if (index > capacity) {
|
|
260
|
-
// Manually shift all values starting at the index back to the
|
|
261
|
-
// beginning of the queue.
|
|
262
|
-
for (let scan = 0, newLength = updateQueue.length - index; scan < newLength; scan++) {
|
|
263
|
-
updateQueue[scan] = updateQueue[scan + index];
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
updateQueue.length -= index;
|
|
267
|
-
index = 0;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
updateQueue.length = 0;
|
|
272
|
-
},
|
|
318
|
+
processUpdates: updateQueue.process,
|
|
273
319
|
|
|
274
320
|
/**
|
|
275
321
|
* Resolves with the next DOM update.
|
|
276
322
|
*/
|
|
277
323
|
nextUpdate() {
|
|
278
|
-
return new Promise(
|
|
279
|
-
DOM.queueUpdate(resolve);
|
|
280
|
-
});
|
|
324
|
+
return new Promise(updateQueue.enqueue);
|
|
281
325
|
},
|
|
282
326
|
|
|
283
327
|
/**
|
|
@@ -537,69 +581,25 @@ class PropertyChangeNotifier {
|
|
|
537
581
|
|
|
538
582
|
}
|
|
539
583
|
|
|
540
|
-
const volatileRegex = /(:|&&|\|\||if)/;
|
|
541
|
-
const notifierLookup = new WeakMap();
|
|
542
|
-
const accessorLookup = new WeakMap();
|
|
543
|
-
let watcher = void 0;
|
|
544
|
-
|
|
545
|
-
let createArrayObserver = array => {
|
|
546
|
-
throw new Error("Must call enableArrayObservation before observing arrays.");
|
|
547
|
-
};
|
|
548
|
-
|
|
549
|
-
class DefaultObservableAccessor {
|
|
550
|
-
constructor(name) {
|
|
551
|
-
this.name = name;
|
|
552
|
-
this.field = `_${name}`;
|
|
553
|
-
this.callback = `${name}Changed`;
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
getValue(source) {
|
|
557
|
-
if (watcher !== void 0) {
|
|
558
|
-
watcher.watch(source, this.name);
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
return source[this.field];
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
setValue(source, newValue) {
|
|
565
|
-
const field = this.field;
|
|
566
|
-
const oldValue = source[field];
|
|
567
|
-
|
|
568
|
-
if (oldValue !== newValue) {
|
|
569
|
-
source[field] = newValue;
|
|
570
|
-
const callback = source[this.callback];
|
|
571
|
-
|
|
572
|
-
if (typeof callback === "function") {
|
|
573
|
-
callback.call(source, oldValue, newValue);
|
|
574
|
-
}
|
|
575
|
-
/* eslint-disable-next-line @typescript-eslint/no-use-before-define */
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
getNotifier(source).notify(this.name);
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
}
|
|
583
584
|
/**
|
|
584
585
|
* Common Observable APIs.
|
|
585
586
|
* @public
|
|
586
587
|
*/
|
|
587
588
|
|
|
589
|
+
const Observable = FAST.getById(2
|
|
590
|
+
/* observable */
|
|
591
|
+
, () => {
|
|
592
|
+
const volatileRegex = /(:|&&|\|\||if)/;
|
|
593
|
+
const notifierLookup = new WeakMap();
|
|
594
|
+
const accessorLookup = new WeakMap();
|
|
595
|
+
const queueUpdate = DOM.queueUpdate;
|
|
596
|
+
let watcher = void 0;
|
|
597
|
+
|
|
598
|
+
let createArrayObserver = array => {
|
|
599
|
+
throw new Error("Must call enableArrayObservation before observing arrays.");
|
|
600
|
+
};
|
|
588
601
|
|
|
589
|
-
|
|
590
|
-
/**
|
|
591
|
-
* @internal
|
|
592
|
-
* @param factory - The factory used to create array observers.
|
|
593
|
-
*/
|
|
594
|
-
setArrayObserverFactory(factory) {
|
|
595
|
-
createArrayObserver = factory;
|
|
596
|
-
},
|
|
597
|
-
|
|
598
|
-
/**
|
|
599
|
-
* Gets a notifier for an object or Array.
|
|
600
|
-
* @param source - The object or Array to get the notifier for.
|
|
601
|
-
*/
|
|
602
|
-
getNotifier(source) {
|
|
602
|
+
function getNotifier(source) {
|
|
603
603
|
let found = source.$fastController || notifierLookup.get(source);
|
|
604
604
|
|
|
605
605
|
if (found === void 0) {
|
|
@@ -611,68 +611,9 @@ const Observable = Object.freeze({
|
|
|
611
611
|
}
|
|
612
612
|
|
|
613
613
|
return found;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
/**
|
|
617
|
-
* Records a property change for a source object.
|
|
618
|
-
* @param source - The object to record the change against.
|
|
619
|
-
* @param propertyName - The property to track as changed.
|
|
620
|
-
*/
|
|
621
|
-
track(source, propertyName) {
|
|
622
|
-
if (watcher !== void 0) {
|
|
623
|
-
watcher.watch(source, propertyName);
|
|
624
|
-
}
|
|
625
|
-
},
|
|
626
|
-
|
|
627
|
-
/**
|
|
628
|
-
* Notifies watchers that the currently executing property getter or function is volatile
|
|
629
|
-
* with respect to its observable dependencies.
|
|
630
|
-
*/
|
|
631
|
-
trackVolatile() {
|
|
632
|
-
if (watcher !== void 0) {
|
|
633
|
-
watcher.needsRefresh = true;
|
|
634
|
-
}
|
|
635
|
-
},
|
|
636
|
-
|
|
637
|
-
/**
|
|
638
|
-
* Notifies subscribers of a source object of changes.
|
|
639
|
-
* @param source - the object to notify of changes.
|
|
640
|
-
* @param args - The change args to pass to subscribers.
|
|
641
|
-
*/
|
|
642
|
-
notify(source, args) {
|
|
643
|
-
/* eslint-disable-next-line @typescript-eslint/no-use-before-define */
|
|
644
|
-
getNotifier(source).notify(args);
|
|
645
|
-
},
|
|
646
|
-
|
|
647
|
-
/**
|
|
648
|
-
* Defines an observable property on an object or prototype.
|
|
649
|
-
* @param target - The target object to define the observable on.
|
|
650
|
-
* @param nameOrAccessor - The name of the property to define as observable;
|
|
651
|
-
* or a custom accessor that specifies the property name and accessor implementation.
|
|
652
|
-
*/
|
|
653
|
-
defineProperty(target, nameOrAccessor) {
|
|
654
|
-
if (typeof nameOrAccessor === "string") {
|
|
655
|
-
nameOrAccessor = new DefaultObservableAccessor(nameOrAccessor);
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
this.getAccessors(target).push(nameOrAccessor);
|
|
659
|
-
Reflect.defineProperty(target, nameOrAccessor.name, {
|
|
660
|
-
enumerable: true,
|
|
661
|
-
get: function () {
|
|
662
|
-
return nameOrAccessor.getValue(this);
|
|
663
|
-
},
|
|
664
|
-
set: function (newValue) {
|
|
665
|
-
nameOrAccessor.setValue(this, newValue);
|
|
666
|
-
}
|
|
667
|
-
});
|
|
668
|
-
},
|
|
614
|
+
}
|
|
669
615
|
|
|
670
|
-
|
|
671
|
-
* Finds all the observable accessors defined on the target,
|
|
672
|
-
* including its prototype chain.
|
|
673
|
-
* @param target - The target object to search for accessor on.
|
|
674
|
-
*/
|
|
675
|
-
getAccessors(target) {
|
|
616
|
+
function getAccessors(target) {
|
|
676
617
|
let accessors = accessorLookup.get(target);
|
|
677
618
|
|
|
678
619
|
if (accessors === void 0) {
|
|
@@ -693,33 +634,253 @@ const Observable = Object.freeze({
|
|
|
693
634
|
}
|
|
694
635
|
|
|
695
636
|
return accessors;
|
|
696
|
-
}
|
|
637
|
+
}
|
|
697
638
|
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
639
|
+
class DefaultObservableAccessor {
|
|
640
|
+
constructor(name) {
|
|
641
|
+
this.name = name;
|
|
642
|
+
this.field = `_${name}`;
|
|
643
|
+
this.callback = `${name}Changed`;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
getValue(source) {
|
|
647
|
+
if (watcher !== void 0) {
|
|
648
|
+
watcher.watch(source, this.name);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
return source[this.field];
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
setValue(source, newValue) {
|
|
655
|
+
const field = this.field;
|
|
656
|
+
const oldValue = source[field];
|
|
657
|
+
|
|
658
|
+
if (oldValue !== newValue) {
|
|
659
|
+
source[field] = newValue;
|
|
660
|
+
const callback = source[this.callback];
|
|
661
|
+
|
|
662
|
+
if (typeof callback === "function") {
|
|
663
|
+
callback.call(source, oldValue, newValue);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
getNotifier(source).notify(this.name);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
class BindingObserverImplementation extends SubscriberSet {
|
|
673
|
+
constructor(binding, initialSubscriber, isVolatileBinding = false) {
|
|
674
|
+
super(binding, initialSubscriber);
|
|
675
|
+
this.binding = binding;
|
|
676
|
+
this.isVolatileBinding = isVolatileBinding;
|
|
677
|
+
this.needsRefresh = true;
|
|
678
|
+
this.needsQueue = true;
|
|
679
|
+
this.first = this;
|
|
680
|
+
this.last = null;
|
|
681
|
+
this.propertySource = void 0;
|
|
682
|
+
this.propertyName = void 0;
|
|
683
|
+
this.notifier = void 0;
|
|
684
|
+
this.next = void 0;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
observe(source, context) {
|
|
688
|
+
if (this.needsRefresh && this.last !== null) {
|
|
689
|
+
this.disconnect();
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
const previousWatcher = watcher;
|
|
693
|
+
watcher = this.needsRefresh ? this : void 0;
|
|
694
|
+
this.needsRefresh = this.isVolatileBinding;
|
|
695
|
+
const result = this.binding(source, context);
|
|
696
|
+
watcher = previousWatcher;
|
|
697
|
+
return result;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
disconnect() {
|
|
701
|
+
if (this.last !== null) {
|
|
702
|
+
let current = this.first;
|
|
703
|
+
|
|
704
|
+
while (current !== void 0) {
|
|
705
|
+
current.notifier.unsubscribe(this, current.propertyName);
|
|
706
|
+
current = current.next;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
this.last = null;
|
|
710
|
+
this.needsRefresh = this.needsQueue = true;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
watch(propertySource, propertyName) {
|
|
715
|
+
const prev = this.last;
|
|
716
|
+
const notifier = getNotifier(propertySource);
|
|
717
|
+
const current = prev === null ? this.first : {};
|
|
718
|
+
current.propertySource = propertySource;
|
|
719
|
+
current.propertyName = propertyName;
|
|
720
|
+
current.notifier = notifier;
|
|
721
|
+
notifier.subscribe(this, propertyName);
|
|
722
|
+
|
|
723
|
+
if (prev !== null) {
|
|
724
|
+
if (!this.needsRefresh) {
|
|
725
|
+
// Declaring the variable prior to assignment below circumvents
|
|
726
|
+
// a bug in Angular's optimization process causing infinite recursion
|
|
727
|
+
// of this watch() method. Details https://github.com/microsoft/fast/issues/4969
|
|
728
|
+
let prevValue;
|
|
729
|
+
watcher = void 0;
|
|
730
|
+
/* eslint-disable-next-line */
|
|
731
|
+
|
|
732
|
+
prevValue = prev.propertySource[prev.propertyName];
|
|
733
|
+
watcher = this;
|
|
734
|
+
|
|
735
|
+
if (propertySource === prevValue) {
|
|
736
|
+
this.needsRefresh = true;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
prev.next = current;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
this.last = current;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
handleChange() {
|
|
747
|
+
if (this.needsQueue) {
|
|
748
|
+
this.needsQueue = false;
|
|
749
|
+
queueUpdate(this);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
call() {
|
|
754
|
+
if (this.last !== null) {
|
|
755
|
+
this.needsQueue = true;
|
|
756
|
+
this.notify(this);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
records() {
|
|
761
|
+
let next = this.first;
|
|
762
|
+
return {
|
|
763
|
+
next: () => {
|
|
764
|
+
const current = next;
|
|
765
|
+
|
|
766
|
+
if (current === undefined) {
|
|
767
|
+
return {
|
|
768
|
+
value: void 0,
|
|
769
|
+
done: true
|
|
770
|
+
};
|
|
771
|
+
} else {
|
|
772
|
+
next = next.next;
|
|
773
|
+
return {
|
|
774
|
+
value: current,
|
|
775
|
+
done: false
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
},
|
|
779
|
+
[Symbol.iterator]: function () {
|
|
780
|
+
return this;
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
}
|
|
709
784
|
|
|
710
|
-
/**
|
|
711
|
-
* Determines whether a binding expression is volatile and needs to have its dependency list re-evaluated
|
|
712
|
-
* on every evaluation of the value.
|
|
713
|
-
* @param binding - The binding to inspect.
|
|
714
|
-
*/
|
|
715
|
-
isVolatileBinding(binding) {
|
|
716
|
-
return volatileRegex.test(binding.toString());
|
|
717
785
|
}
|
|
718
786
|
|
|
787
|
+
return Object.freeze({
|
|
788
|
+
/**
|
|
789
|
+
* @internal
|
|
790
|
+
* @param factory - The factory used to create array observers.
|
|
791
|
+
*/
|
|
792
|
+
setArrayObserverFactory(factory) {
|
|
793
|
+
createArrayObserver = factory;
|
|
794
|
+
},
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Gets a notifier for an object or Array.
|
|
798
|
+
* @param source - The object or Array to get the notifier for.
|
|
799
|
+
*/
|
|
800
|
+
getNotifier,
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* Records a property change for a source object.
|
|
804
|
+
* @param source - The object to record the change against.
|
|
805
|
+
* @param propertyName - The property to track as changed.
|
|
806
|
+
*/
|
|
807
|
+
track(source, propertyName) {
|
|
808
|
+
if (watcher !== void 0) {
|
|
809
|
+
watcher.watch(source, propertyName);
|
|
810
|
+
}
|
|
811
|
+
},
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* Notifies watchers that the currently executing property getter or function is volatile
|
|
815
|
+
* with respect to its observable dependencies.
|
|
816
|
+
*/
|
|
817
|
+
trackVolatile() {
|
|
818
|
+
if (watcher !== void 0) {
|
|
819
|
+
watcher.needsRefresh = true;
|
|
820
|
+
}
|
|
821
|
+
},
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* Notifies subscribers of a source object of changes.
|
|
825
|
+
* @param source - the object to notify of changes.
|
|
826
|
+
* @param args - The change args to pass to subscribers.
|
|
827
|
+
*/
|
|
828
|
+
notify(source, args) {
|
|
829
|
+
getNotifier(source).notify(args);
|
|
830
|
+
},
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* Defines an observable property on an object or prototype.
|
|
834
|
+
* @param target - The target object to define the observable on.
|
|
835
|
+
* @param nameOrAccessor - The name of the property to define as observable;
|
|
836
|
+
* or a custom accessor that specifies the property name and accessor implementation.
|
|
837
|
+
*/
|
|
838
|
+
defineProperty(target, nameOrAccessor) {
|
|
839
|
+
if (typeof nameOrAccessor === "string") {
|
|
840
|
+
nameOrAccessor = new DefaultObservableAccessor(nameOrAccessor);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
getAccessors(target).push(nameOrAccessor);
|
|
844
|
+
Reflect.defineProperty(target, nameOrAccessor.name, {
|
|
845
|
+
enumerable: true,
|
|
846
|
+
get: function () {
|
|
847
|
+
return nameOrAccessor.getValue(this);
|
|
848
|
+
},
|
|
849
|
+
set: function (newValue) {
|
|
850
|
+
nameOrAccessor.setValue(this, newValue);
|
|
851
|
+
}
|
|
852
|
+
});
|
|
853
|
+
},
|
|
854
|
+
|
|
855
|
+
/**
|
|
856
|
+
* Finds all the observable accessors defined on the target,
|
|
857
|
+
* including its prototype chain.
|
|
858
|
+
* @param target - The target object to search for accessor on.
|
|
859
|
+
*/
|
|
860
|
+
getAccessors,
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* Creates a {@link BindingObserver} that can watch the
|
|
864
|
+
* provided {@link Binding} for changes.
|
|
865
|
+
* @param binding - The binding to observe.
|
|
866
|
+
* @param initialSubscriber - An initial subscriber to changes in the binding value.
|
|
867
|
+
* @param isVolatileBinding - Indicates whether the binding's dependency list must be re-evaluated on every value evaluation.
|
|
868
|
+
*/
|
|
869
|
+
binding(binding, initialSubscriber, isVolatileBinding = this.isVolatileBinding(binding)) {
|
|
870
|
+
return new BindingObserverImplementation(binding, initialSubscriber, isVolatileBinding);
|
|
871
|
+
},
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* Determines whether a binding expression is volatile and needs to have its dependency list re-evaluated
|
|
875
|
+
* on every evaluation of the value.
|
|
876
|
+
* @param binding - The binding to inspect.
|
|
877
|
+
*/
|
|
878
|
+
isVolatileBinding(binding) {
|
|
879
|
+
return volatileRegex.test(binding.toString());
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
});
|
|
719
883
|
});
|
|
720
|
-
const getNotifier = Observable.getNotifier;
|
|
721
|
-
const trackVolatile = Observable.trackVolatile;
|
|
722
|
-
const queueUpdate = DOM.queueUpdate;
|
|
723
884
|
/**
|
|
724
885
|
* Decorator: Defines an observable property on the target.
|
|
725
886
|
* @param target - The target to define the observable on.
|
|
@@ -741,20 +902,26 @@ function observable(target, nameOrAccessor) {
|
|
|
741
902
|
function volatile(target, name, descriptor) {
|
|
742
903
|
return Object.assign({}, descriptor, {
|
|
743
904
|
get: function () {
|
|
744
|
-
trackVolatile();
|
|
905
|
+
Observable.trackVolatile();
|
|
745
906
|
return descriptor.get.apply(this);
|
|
746
907
|
}
|
|
747
908
|
});
|
|
748
909
|
}
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
910
|
+
const contextEvent = FAST.getById(3
|
|
911
|
+
/* contextEvent */
|
|
912
|
+
, () => {
|
|
913
|
+
let current = null;
|
|
914
|
+
return {
|
|
915
|
+
get() {
|
|
916
|
+
return current;
|
|
917
|
+
},
|
|
754
918
|
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
}
|
|
919
|
+
set(event) {
|
|
920
|
+
current = event;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
};
|
|
924
|
+
});
|
|
758
925
|
/**
|
|
759
926
|
* Provides additional contextual information available to behaviors and expressions.
|
|
760
927
|
* @public
|
|
@@ -788,7 +955,7 @@ class ExecutionContext {
|
|
|
788
955
|
|
|
789
956
|
|
|
790
957
|
get event() {
|
|
791
|
-
return
|
|
958
|
+
return contextEvent.get();
|
|
792
959
|
}
|
|
793
960
|
/**
|
|
794
961
|
* Indicates whether the current item within a repeat context
|
|
@@ -835,6 +1002,16 @@ class ExecutionContext {
|
|
|
835
1002
|
get isLast() {
|
|
836
1003
|
return this.index === this.length - 1;
|
|
837
1004
|
}
|
|
1005
|
+
/**
|
|
1006
|
+
* Sets the event for the current execution context.
|
|
1007
|
+
* @param event - The event to set.
|
|
1008
|
+
* @internal
|
|
1009
|
+
*/
|
|
1010
|
+
|
|
1011
|
+
|
|
1012
|
+
static setEvent(event) {
|
|
1013
|
+
contextEvent.set(event);
|
|
1014
|
+
}
|
|
838
1015
|
|
|
839
1016
|
}
|
|
840
1017
|
Observable.defineProperty(ExecutionContext.prototype, "index");
|
|
@@ -846,127 +1023,6 @@ Observable.defineProperty(ExecutionContext.prototype, "length");
|
|
|
846
1023
|
|
|
847
1024
|
const defaultExecutionContext = Object.seal(new ExecutionContext());
|
|
848
1025
|
|
|
849
|
-
class BindingObserverImplementation extends SubscriberSet {
|
|
850
|
-
constructor(binding, initialSubscriber, isVolatileBinding = false) {
|
|
851
|
-
super(binding, initialSubscriber);
|
|
852
|
-
this.binding = binding;
|
|
853
|
-
this.isVolatileBinding = isVolatileBinding;
|
|
854
|
-
this.needsRefresh = true;
|
|
855
|
-
this.needsQueue = true;
|
|
856
|
-
this.first = this;
|
|
857
|
-
this.last = null;
|
|
858
|
-
this.propertySource = void 0;
|
|
859
|
-
this.propertyName = void 0;
|
|
860
|
-
this.notifier = void 0;
|
|
861
|
-
this.next = void 0;
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
observe(source, context) {
|
|
865
|
-
if (this.needsRefresh && this.last !== null) {
|
|
866
|
-
this.disconnect();
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
const previousWatcher = watcher;
|
|
870
|
-
watcher = this.needsRefresh ? this : void 0;
|
|
871
|
-
this.needsRefresh = this.isVolatileBinding;
|
|
872
|
-
const result = this.binding(source, context);
|
|
873
|
-
watcher = previousWatcher;
|
|
874
|
-
return result;
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
disconnect() {
|
|
878
|
-
if (this.last !== null) {
|
|
879
|
-
let current = this.first;
|
|
880
|
-
|
|
881
|
-
while (current !== void 0) {
|
|
882
|
-
current.notifier.unsubscribe(this, current.propertyName);
|
|
883
|
-
current = current.next;
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
this.last = null;
|
|
887
|
-
this.needsRefresh = this.needsQueue = true;
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
/** @internal */
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
watch(propertySource, propertyName) {
|
|
894
|
-
const prev = this.last;
|
|
895
|
-
const notifier = getNotifier(propertySource);
|
|
896
|
-
const current = prev === null ? this.first : {};
|
|
897
|
-
current.propertySource = propertySource;
|
|
898
|
-
current.propertyName = propertyName;
|
|
899
|
-
current.notifier = notifier;
|
|
900
|
-
notifier.subscribe(this, propertyName);
|
|
901
|
-
|
|
902
|
-
if (prev !== null) {
|
|
903
|
-
if (!this.needsRefresh) {
|
|
904
|
-
// Declaring the variable prior to assignment below circumvents
|
|
905
|
-
// a bug in Angular's optimization process causing infinite recursion
|
|
906
|
-
// of this watch() method. Details https://github.com/microsoft/fast/issues/4969
|
|
907
|
-
let prevValue;
|
|
908
|
-
watcher = void 0;
|
|
909
|
-
/* eslint-disable-next-line */
|
|
910
|
-
|
|
911
|
-
prevValue = prev.propertySource[prev.propertyName];
|
|
912
|
-
watcher = this;
|
|
913
|
-
|
|
914
|
-
if (propertySource === prevValue) {
|
|
915
|
-
this.needsRefresh = true;
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
prev.next = current;
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
this.last = current;
|
|
923
|
-
}
|
|
924
|
-
/** @internal */
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
handleChange() {
|
|
928
|
-
if (this.needsQueue) {
|
|
929
|
-
this.needsQueue = false;
|
|
930
|
-
queueUpdate(this);
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
/** @internal */
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
call() {
|
|
937
|
-
if (this.last !== null) {
|
|
938
|
-
this.needsQueue = true;
|
|
939
|
-
this.notify(this);
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
records() {
|
|
944
|
-
let next = this.first;
|
|
945
|
-
return {
|
|
946
|
-
next: () => {
|
|
947
|
-
const current = next;
|
|
948
|
-
|
|
949
|
-
if (current === undefined) {
|
|
950
|
-
return {
|
|
951
|
-
value: void 0,
|
|
952
|
-
done: true
|
|
953
|
-
};
|
|
954
|
-
} else {
|
|
955
|
-
next = next.next;
|
|
956
|
-
return {
|
|
957
|
-
value: current,
|
|
958
|
-
done: false
|
|
959
|
-
};
|
|
960
|
-
}
|
|
961
|
-
},
|
|
962
|
-
[Symbol.iterator]: function () {
|
|
963
|
-
return this;
|
|
964
|
-
}
|
|
965
|
-
};
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
}
|
|
969
|
-
|
|
970
1026
|
/**
|
|
971
1027
|
* Instructs the template engine to apply behavior to a node.
|
|
972
1028
|
* @public
|
|
@@ -1329,9 +1385,9 @@ class BindingBehavior {
|
|
|
1329
1385
|
|
|
1330
1386
|
|
|
1331
1387
|
handleEvent(event) {
|
|
1332
|
-
|
|
1388
|
+
ExecutionContext.setEvent(event);
|
|
1333
1389
|
const result = this.binding(this.source, this.context);
|
|
1334
|
-
|
|
1390
|
+
ExecutionContext.setEvent(null);
|
|
1335
1391
|
|
|
1336
1392
|
if (result !== true) {
|
|
1337
1393
|
event.preventDefault();
|
|
@@ -2327,7 +2383,26 @@ const defaultShadowOptions = {
|
|
|
2327
2383
|
mode: "open"
|
|
2328
2384
|
};
|
|
2329
2385
|
const defaultElementOptions = {};
|
|
2330
|
-
const
|
|
2386
|
+
const fastRegistry = FAST.getById(4
|
|
2387
|
+
/* elementRegistry */
|
|
2388
|
+
, () => {
|
|
2389
|
+
const typeToDefinition = new Map();
|
|
2390
|
+
return Object.freeze({
|
|
2391
|
+
register(definition) {
|
|
2392
|
+
if (typeToDefinition.has(definition.type)) {
|
|
2393
|
+
return false;
|
|
2394
|
+
}
|
|
2395
|
+
|
|
2396
|
+
typeToDefinition.set(definition.type, definition);
|
|
2397
|
+
return true;
|
|
2398
|
+
},
|
|
2399
|
+
|
|
2400
|
+
getByType(key) {
|
|
2401
|
+
return typeToDefinition.get(key);
|
|
2402
|
+
}
|
|
2403
|
+
|
|
2404
|
+
});
|
|
2405
|
+
});
|
|
2331
2406
|
/**
|
|
2332
2407
|
* Defines metadata for a FASTElement.
|
|
2333
2408
|
* @public
|
|
@@ -2370,6 +2445,14 @@ class FASTElementDefinition {
|
|
|
2370
2445
|
this.elementOptions = nameOrConfig.elementOptions === void 0 ? defaultElementOptions : Object.assign(Object.assign({}, defaultElementOptions), nameOrConfig.elementOptions);
|
|
2371
2446
|
this.styles = nameOrConfig.styles === void 0 ? void 0 : Array.isArray(nameOrConfig.styles) ? ElementStyles.create(nameOrConfig.styles) : nameOrConfig.styles instanceof ElementStyles ? nameOrConfig.styles : ElementStyles.create([nameOrConfig.styles]);
|
|
2372
2447
|
}
|
|
2448
|
+
/**
|
|
2449
|
+
* Indicates if this element has been defined in at least one registry.
|
|
2450
|
+
*/
|
|
2451
|
+
|
|
2452
|
+
|
|
2453
|
+
get isDefined() {
|
|
2454
|
+
return !!fastRegistry.getByType(this.type);
|
|
2455
|
+
}
|
|
2373
2456
|
/**
|
|
2374
2457
|
* Defines a custom element based on this definition.
|
|
2375
2458
|
* @param registry - The element registry to define the element in.
|
|
@@ -2379,7 +2462,7 @@ class FASTElementDefinition {
|
|
|
2379
2462
|
define(registry = customElements) {
|
|
2380
2463
|
const type = this.type;
|
|
2381
2464
|
|
|
2382
|
-
if (
|
|
2465
|
+
if (fastRegistry.register(this)) {
|
|
2383
2466
|
const attributes = this.attributes;
|
|
2384
2467
|
const proto = type.prototype;
|
|
2385
2468
|
|
|
@@ -2391,8 +2474,6 @@ class FASTElementDefinition {
|
|
|
2391
2474
|
value: this.observedAttributes,
|
|
2392
2475
|
enumerable: true
|
|
2393
2476
|
});
|
|
2394
|
-
fastDefinitions.set(type, this);
|
|
2395
|
-
this.isDefined = true;
|
|
2396
2477
|
}
|
|
2397
2478
|
|
|
2398
2479
|
if (!registry.get(this.name)) {
|
|
@@ -2401,17 +2482,14 @@ class FASTElementDefinition {
|
|
|
2401
2482
|
|
|
2402
2483
|
return this;
|
|
2403
2484
|
}
|
|
2404
|
-
/**
|
|
2405
|
-
* Gets the element definition associated with the specified type.
|
|
2406
|
-
* @param type - The custom element type to retrieve the definition for.
|
|
2407
|
-
*/
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
static forType(type) {
|
|
2411
|
-
return fastDefinitions.get(type);
|
|
2412
|
-
}
|
|
2413
2485
|
|
|
2414
2486
|
}
|
|
2487
|
+
/**
|
|
2488
|
+
* Gets the element definition associated with the specified type.
|
|
2489
|
+
* @param type - The custom element type to retrieve the definition for.
|
|
2490
|
+
*/
|
|
2491
|
+
|
|
2492
|
+
FASTElementDefinition.forType = fastRegistry.getByType;
|
|
2415
2493
|
|
|
2416
2494
|
const shadowRoots = new WeakMap();
|
|
2417
2495
|
const defaultEventOptions = {
|
|
@@ -6698,4 +6776,4 @@ class RouterConfiguration {
|
|
|
6698
6776
|
let FASTRouter = class FASTRouter extends Router.from(FASTElement) {};
|
|
6699
6777
|
FASTRouter = __decorate([customElement("fast-router")], FASTRouter);
|
|
6700
6778
|
|
|
6701
|
-
export { $global, AttachedBehaviorHTMLDirective, AttributeDefinition, BindingBehavior, CSSDirective, ChildrenBehavior, ConfigurableRoute, Controller, DOM, DefaultLinkHandler, DefaultNavigationProcess, DefaultNavigationQueue, DefaultRouteRecognizer, DefaultRouter, ElementStyles, Endpoint, ExecutionContext, FASTElement, FASTElementDefinition, FASTElementLayout, FASTRouter, HTMLBindingDirective, HTMLDirective, HTMLView, Ignore, Layout, NavigationHandler, NavigationMessage, Observable, PropertyChangeNotifier, QueryString, RecognizedRoute, Redirect, RefBehavior, Render, RepeatBehavior, RepeatDirective, Route, RouteCollection, Router, RouterConfiguration, RouterExecutionContext, SlottedBehavior, SubscriberSet, TargetedHTMLDirective, Transition, ViewTemplate, attr, booleanConverter, childRouteParameter, children, compileTemplate, css, cssPartial, customElement, defaultExecutionContext, elements, emptyArray, enableArrayObservation, html, isFASTElementHost, isNavigationPhaseContributor, navigationContributor, nullableNumberConverter, observable, ref, repeat,
|
|
6779
|
+
export { $global, AttachedBehaviorHTMLDirective, AttributeDefinition, BindingBehavior, CSSDirective, ChildrenBehavior, ConfigurableRoute, Controller, DOM, DefaultLinkHandler, DefaultNavigationProcess, DefaultNavigationQueue, DefaultRouteRecognizer, DefaultRouter, ElementStyles, Endpoint, ExecutionContext, FAST, FASTElement, FASTElementDefinition, FASTElementLayout, FASTRouter, HTMLBindingDirective, HTMLDirective, HTMLView, Ignore, Layout, NavigationHandler, NavigationMessage, Observable, PropertyChangeNotifier, QueryString, RecognizedRoute, Redirect, RefBehavior, Render, RepeatBehavior, RepeatDirective, Route, RouteCollection, Router, RouterConfiguration, RouterExecutionContext, SlottedBehavior, SubscriberSet, TargetedHTMLDirective, Transition, ViewTemplate, attr, booleanConverter, childRouteParameter, children, compileTemplate, css, cssPartial, customElement, defaultExecutionContext, elements, emptyArray, enableArrayObservation, html, isFASTElementHost, isNavigationPhaseContributor, navigationContributor, nullableNumberConverter, observable, ref, repeat, slotted, volatile, when };
|