@tko/computed 4.0.0-alpha7.3 → 4.0.0-beta1.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.
@@ -1,661 +0,0 @@
1
- /*!
2
- * TKO Computed Observables 🥊 @tko/computed@4.0.0-alpha7.3
3
- * (c) The Knockout.js Team - https://tko.io
4
- * License: MIT (http://www.opensource.org/licenses/mit-license.php)
5
- */
6
-
7
- import { addDisposeCallback, arrayForEach, createSymbolOrString, domNodeIsAttachedToDocument, extend, options, hasOwnProperty, objectForEach, removeDisposeCallback, safeSetTimeout } from '@tko/utils';
8
- import { dependencyDetection, extenders, valuesArePrimitiveAndEqual, observable, subscribable, LATEST_VALUE, observableArray, unwrap } from '@tko/observable';
9
-
10
- //
11
-
12
- const computedState = createSymbolOrString('_state');
13
- const DISPOSED_STATE = {
14
- dependencyTracking: null,
15
- dependenciesCount: 0,
16
- isDisposed: true,
17
- isStale: false,
18
- isDirty: false,
19
- isSleeping: false,
20
- disposeWhenNodeIsRemoved: null,
21
- readFunction: null,
22
- _options: null
23
- };
24
-
25
- function computed (evaluatorFunctionOrOptions, evaluatorFunctionTarget, options$$1) {
26
- if (typeof evaluatorFunctionOrOptions === 'object') {
27
- // Single-parameter syntax - everything is on this "options" param
28
- options$$1 = evaluatorFunctionOrOptions;
29
- } else {
30
- // Multi-parameter syntax - construct the options according to the params passed
31
- options$$1 = options$$1 || {};
32
- if (evaluatorFunctionOrOptions) {
33
- options$$1.read = evaluatorFunctionOrOptions;
34
- }
35
- }
36
- if (typeof options$$1.read !== 'function') {
37
- throw Error('Pass a function that returns the value of the computed')
38
- }
39
-
40
- var writeFunction = options$$1.write;
41
- var state = {
42
- latestValue: undefined,
43
- isStale: true,
44
- isDirty: true,
45
- isBeingEvaluated: false,
46
- suppressDisposalUntilDisposeWhenReturnsFalse: false,
47
- isDisposed: false,
48
- pure: false,
49
- isSleeping: false,
50
- readFunction: options$$1.read,
51
- evaluatorFunctionTarget: evaluatorFunctionTarget || options$$1.owner,
52
- disposeWhenNodeIsRemoved: options$$1.disposeWhenNodeIsRemoved || options$$1.disposeWhenNodeIsRemoved || null,
53
- disposeWhen: options$$1.disposeWhen || options$$1.disposeWhen,
54
- domNodeDisposalCallback: null,
55
- dependencyTracking: {},
56
- dependenciesCount: 0,
57
- evaluationTimeoutInstance: null
58
- };
59
-
60
- function computedObservable () {
61
- if (arguments.length > 0) {
62
- if (typeof writeFunction === 'function') {
63
- // Writing a value
64
- writeFunction.apply(state.evaluatorFunctionTarget, arguments);
65
- } else {
66
- throw new Error("Cannot write a value to a computed unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters.")
67
- }
68
- return this // Permits chained assignments
69
- } else {
70
- // Reading the value
71
- if (!state.isDisposed) {
72
- dependencyDetection.registerDependency(computedObservable);
73
- }
74
- if (state.isDirty || (state.isSleeping && computedObservable.haveDependenciesChanged())) {
75
- computedObservable.evaluateImmediate();
76
- }
77
- return state.latestValue
78
- }
79
- }
80
-
81
- computedObservable[computedState] = state;
82
- computedObservable.isWriteable = typeof writeFunction === 'function';
83
-
84
- subscribable.fn.init(computedObservable);
85
-
86
- // Inherit from 'computed'
87
- Object.setPrototypeOf(computedObservable, computed.fn);
88
-
89
- if (options$$1.pure) {
90
- state.pure = true;
91
- state.isSleeping = true; // Starts off sleeping; will awake on the first subscription
92
- extend(computedObservable, pureComputedOverrides);
93
- } else if (options$$1.deferEvaluation) {
94
- extend(computedObservable, deferEvaluationOverrides);
95
- }
96
-
97
- if (options.deferUpdates) {
98
- extenders.deferred(computedObservable, true);
99
- }
100
-
101
- if (options.debug) {
102
- // #1731 - Aid debugging by exposing the computed's options
103
- computedObservable._options = options$$1;
104
- }
105
-
106
- if (state.disposeWhenNodeIsRemoved) {
107
- // Since this computed is associated with a DOM node, and we don't want to dispose the computed
108
- // until the DOM node is *removed* from the document (as opposed to never having been in the document),
109
- // we'll prevent disposal until "disposeWhen" first returns false.
110
- state.suppressDisposalUntilDisposeWhenReturnsFalse = true;
111
-
112
- // disposeWhenNodeIsRemoved: true can be used to opt into the "only dispose after first false result"
113
- // behavior even if there's no specific node to watch. In that case, clear the option so we don't try
114
- // to watch for a non-node's disposal. This technique is intended for KO's internal use only and shouldn't
115
- // be documented or used by application code, as it's likely to change in a future version of KO.
116
- if (!state.disposeWhenNodeIsRemoved.nodeType) {
117
- state.disposeWhenNodeIsRemoved = null;
118
- }
119
- }
120
-
121
- // Evaluate, unless sleeping or deferEvaluation is true
122
- if (!state.isSleeping && !options$$1.deferEvaluation) {
123
- computedObservable.evaluateImmediate();
124
- }
125
-
126
- // Attach a DOM node disposal callback so that the computed will be proactively disposed as soon as the node is
127
- // removed using ko.removeNode. But skip if isActive is false (there will never be any dependencies to dispose).
128
- if (state.disposeWhenNodeIsRemoved && computedObservable.isActive()) {
129
- addDisposeCallback(state.disposeWhenNodeIsRemoved, state.domNodeDisposalCallback = function () {
130
- computedObservable.dispose();
131
- });
132
- }
133
-
134
- return computedObservable
135
- }
136
-
137
- // Utility function that disposes a given dependencyTracking entry
138
- function computedDisposeDependencyCallback (id, entryToDispose) {
139
- if (entryToDispose !== null && entryToDispose.dispose) {
140
- entryToDispose.dispose();
141
- }
142
- }
143
-
144
- // This function gets called each time a dependency is detected while evaluating a computed.
145
- // It's factored out as a shared function to avoid creating unnecessary function instances during evaluation.
146
- function computedBeginDependencyDetectionCallback (subscribable$$1, id) {
147
- var computedObservable = this.computedObservable,
148
- state = computedObservable[computedState];
149
- if (!state.isDisposed) {
150
- if (this.disposalCount && this.disposalCandidates[id]) {
151
- // Don't want to dispose this subscription, as it's still being used
152
- computedObservable.addDependencyTracking(id, subscribable$$1, this.disposalCandidates[id]);
153
- this.disposalCandidates[id] = null; // No need to actually delete the property - disposalCandidates is a transient object anyway
154
- --this.disposalCount;
155
- } else if (!state.dependencyTracking[id]) {
156
- // Brand new subscription - add it
157
- computedObservable.addDependencyTracking(id, subscribable$$1, state.isSleeping ? { _target: subscribable$$1 } : computedObservable.subscribeToDependency(subscribable$$1));
158
- }
159
- // If the observable we've accessed has a pending notification, ensure
160
- // we get notified of the actual final value (bypass equality checks)
161
- if (subscribable$$1._notificationIsPending) {
162
- subscribable$$1._notifyNextChangeIfValueIsDifferent();
163
- }
164
- }
165
- }
166
-
167
- computed.fn = {
168
- equalityComparer: valuesArePrimitiveAndEqual,
169
- getDependenciesCount () {
170
- return this[computedState].dependenciesCount
171
- },
172
-
173
- getDependencies () {
174
- const dependencyTracking = this[computedState].dependencyTracking;
175
- const dependentObservables = [];
176
-
177
- objectForEach(dependencyTracking, function (id, dependency) {
178
- dependentObservables[dependency._order] = dependency._target;
179
- });
180
-
181
- return dependentObservables
182
- },
183
-
184
- addDependencyTracking (id, target, trackingObj) {
185
- if (this[computedState].pure && target === this) {
186
- throw Error("A 'pure' computed must not be called recursively")
187
- }
188
-
189
- this[computedState].dependencyTracking[id] = trackingObj;
190
- trackingObj._order = this[computedState].dependenciesCount++;
191
- trackingObj._version = target.getVersion();
192
- },
193
- haveDependenciesChanged () {
194
- var id, dependency, dependencyTracking = this[computedState].dependencyTracking;
195
- for (id in dependencyTracking) {
196
- if (hasOwnProperty(dependencyTracking, id)) {
197
- dependency = dependencyTracking[id];
198
- if ((this._evalDelayed && dependency._target._notificationIsPending) || dependency._target.hasChanged(dependency._version)) {
199
- return true
200
- }
201
- }
202
- }
203
- },
204
- markDirty () {
205
- // Process "dirty" events if we can handle delayed notifications
206
- if (this._evalDelayed && !this[computedState].isBeingEvaluated) {
207
- this._evalDelayed(false /* notifyChange */);
208
- }
209
- },
210
- isActive () {
211
- const state = this[computedState];
212
- return state.isDirty || state.dependenciesCount > 0
213
- },
214
- respondToChange () {
215
- // Ignore "change" events if we've already scheduled a delayed notification
216
- if (!this._notificationIsPending) {
217
- this.evaluatePossiblyAsync();
218
- } else if (this[computedState].isDirty) {
219
- this[computedState].isStale = true;
220
- }
221
- },
222
- subscribeToDependency (target) {
223
- if (target._deferUpdates) {
224
- var dirtySub = target.subscribe(this.markDirty, this, 'dirty'),
225
- changeSub = target.subscribe(this.respondToChange, this);
226
- return {
227
- _target: target,
228
- dispose () {
229
- dirtySub.dispose();
230
- changeSub.dispose();
231
- }
232
- }
233
- } else {
234
- return target.subscribe(this.evaluatePossiblyAsync, this)
235
- }
236
- },
237
- evaluatePossiblyAsync () {
238
- var computedObservable = this,
239
- throttleEvaluationTimeout = computedObservable.throttleEvaluation;
240
- if (throttleEvaluationTimeout && throttleEvaluationTimeout >= 0) {
241
- clearTimeout(this[computedState].evaluationTimeoutInstance);
242
- this[computedState].evaluationTimeoutInstance = safeSetTimeout(function () {
243
- computedObservable.evaluateImmediate(true /* notifyChange */);
244
- }, throttleEvaluationTimeout);
245
- } else if (computedObservable._evalDelayed) {
246
- computedObservable._evalDelayed(true /* notifyChange */);
247
- } else {
248
- computedObservable.evaluateImmediate(true /* notifyChange */);
249
- }
250
- },
251
- evaluateImmediate (notifyChange) {
252
- var computedObservable = this,
253
- state = computedObservable[computedState],
254
- disposeWhen = state.disposeWhen,
255
- changed = false;
256
-
257
- if (state.isBeingEvaluated) {
258
- // If the evaluation of a ko.computed causes side effects, it's possible that it will trigger its own re-evaluation.
259
- // This is not desirable (it's hard for a developer to realise a chain of dependencies might cause this, and they almost
260
- // certainly didn't intend infinite re-evaluations). So, for predictability, we simply prevent ko.computeds from causing
261
- // their own re-evaluation. Further discussion at https://github.com/SteveSanderson/knockout/pull/387
262
- return
263
- }
264
-
265
- // Do not evaluate (and possibly capture new dependencies) if disposed
266
- if (state.isDisposed) {
267
- return
268
- }
269
-
270
- if (state.disposeWhenNodeIsRemoved && !domNodeIsAttachedToDocument(state.disposeWhenNodeIsRemoved) || disposeWhen && disposeWhen()) {
271
- // See comment above about suppressDisposalUntilDisposeWhenReturnsFalse
272
- if (!state.suppressDisposalUntilDisposeWhenReturnsFalse) {
273
- computedObservable.dispose();
274
- return
275
- }
276
- } else {
277
- // It just did return false, so we can stop suppressing now
278
- state.suppressDisposalUntilDisposeWhenReturnsFalse = false;
279
- }
280
-
281
- state.isBeingEvaluated = true;
282
- try {
283
- changed = this.evaluateImmediate_CallReadWithDependencyDetection(notifyChange);
284
- } finally {
285
- state.isBeingEvaluated = false;
286
- }
287
-
288
- return changed
289
- },
290
- evaluateImmediate_CallReadWithDependencyDetection (notifyChange) {
291
- // This function is really just part of the evaluateImmediate logic. You would never call it from anywhere else.
292
- // Factoring it out into a separate function means it can be independent of the try/catch block in evaluateImmediate,
293
- // which contributes to saving about 40% off the CPU overhead of computed evaluation (on V8 at least).
294
-
295
- var computedObservable = this,
296
- state = computedObservable[computedState],
297
- changed = false;
298
-
299
- // Initially, we assume that none of the subscriptions are still being used (i.e., all are candidates for disposal).
300
- // Then, during evaluation, we cross off any that are in fact still being used.
301
- var isInitial = state.pure ? undefined : !state.dependenciesCount, // If we're evaluating when there are no previous dependencies, it must be the first time
302
- dependencyDetectionContext = {
303
- computedObservable: computedObservable,
304
- disposalCandidates: state.dependencyTracking,
305
- disposalCount: state.dependenciesCount
306
- };
307
-
308
- dependencyDetection.begin({
309
- callbackTarget: dependencyDetectionContext,
310
- callback: computedBeginDependencyDetectionCallback,
311
- computed: computedObservable,
312
- isInitial: isInitial
313
- });
314
-
315
- state.dependencyTracking = {};
316
- state.dependenciesCount = 0;
317
-
318
- var newValue = this.evaluateImmediate_CallReadThenEndDependencyDetection(state, dependencyDetectionContext);
319
-
320
- if (!state.dependenciesCount) {
321
- computedObservable.dispose();
322
- changed = true; // When evaluation causes a disposal, make sure all dependent computeds get notified so they'll see the new state
323
- } else {
324
- changed = computedObservable.isDifferent(state.latestValue, newValue);
325
- }
326
-
327
- if (changed) {
328
- if (!state.isSleeping) {
329
- computedObservable.notifySubscribers(state.latestValue, 'beforeChange');
330
- } else {
331
- computedObservable.updateVersion();
332
- }
333
-
334
- state.latestValue = newValue;
335
- if (options.debug) { computedObservable._latestValue = newValue; }
336
-
337
- computedObservable.notifySubscribers(state.latestValue, 'spectate');
338
-
339
- if (!state.isSleeping && notifyChange) {
340
- computedObservable.notifySubscribers(state.latestValue);
341
- }
342
-
343
- if (computedObservable._recordUpdate) {
344
- computedObservable._recordUpdate();
345
- }
346
- }
347
-
348
- if (isInitial) {
349
- computedObservable.notifySubscribers(state.latestValue, 'awake');
350
- }
351
-
352
- return changed
353
- },
354
- evaluateImmediate_CallReadThenEndDependencyDetection (state, dependencyDetectionContext) {
355
- // This function is really part of the evaluateImmediate_CallReadWithDependencyDetection logic.
356
- // You'd never call it from anywhere else. Factoring it out means that evaluateImmediate_CallReadWithDependencyDetection
357
- // can be independent of try/finally blocks, which contributes to saving about 40% off the CPU
358
- // overhead of computed evaluation (on V8 at least).
359
-
360
- try {
361
- var readFunction = state.readFunction;
362
- return state.evaluatorFunctionTarget ? readFunction.call(state.evaluatorFunctionTarget) : readFunction()
363
- } finally {
364
- dependencyDetection.end();
365
-
366
- // For each subscription no longer being used, remove it from the active subscriptions list and dispose it
367
- if (dependencyDetectionContext.disposalCount && !state.isSleeping) {
368
- objectForEach(dependencyDetectionContext.disposalCandidates, computedDisposeDependencyCallback);
369
- }
370
-
371
- state.isStale = state.isDirty = false;
372
- }
373
- },
374
- peek (forceEvaluate) {
375
- // Peek won't ordinarily re-evaluate, except while the computed is sleeping
376
- // or to get the initial value when "deferEvaluation" is set.
377
- const state = this[computedState];
378
- if ((state.isDirty && (forceEvaluate || !state.dependenciesCount)) || (state.isSleeping && this.haveDependenciesChanged())) {
379
- this.evaluateImmediate();
380
- }
381
- return state.latestValue
382
- },
383
-
384
- get [LATEST_VALUE] () {
385
- return this.peek()
386
- },
387
-
388
- limit (limitFunction) {
389
- const state = this[computedState];
390
- // Override the limit function with one that delays evaluation as well
391
- subscribable.fn.limit.call(this, limitFunction);
392
- Object.assign(this, {
393
- _evalIfChanged () {
394
- if (!this[computedState].isSleeping) {
395
- if (this[computedState].isStale) {
396
- this.evaluateImmediate();
397
- } else {
398
- this[computedState].isDirty = false;
399
- }
400
- }
401
- return state.latestValue
402
- },
403
- _evalDelayed (isChange) {
404
- this._limitBeforeChange(state.latestValue);
405
-
406
- // Mark as dirty
407
- state.isDirty = true;
408
- if (isChange) {
409
- state.isStale = true;
410
- }
411
-
412
- // Pass the observable to the "limit" code, which will evaluate it when
413
- // it's time to do the notification.
414
- this._limitChange(this, !isChange /* isDirty */);
415
- }
416
- });
417
- },
418
- dispose () {
419
- var state = this[computedState];
420
- if (!state.isSleeping && state.dependencyTracking) {
421
- objectForEach(state.dependencyTracking, function (id, dependency) {
422
- if (dependency.dispose) {
423
- dependency.dispose();
424
- }
425
- });
426
- }
427
- if (state.disposeWhenNodeIsRemoved && state.domNodeDisposalCallback) {
428
- removeDisposeCallback(state.disposeWhenNodeIsRemoved, state.domNodeDisposalCallback);
429
- }
430
- Object.assign(state, DISPOSED_STATE);
431
- }
432
- };
433
-
434
- var pureComputedOverrides = {
435
- beforeSubscriptionAdd (event) {
436
- // If asleep, wake up the computed by subscribing to any dependencies.
437
- var computedObservable = this,
438
- state = computedObservable[computedState];
439
- if (!state.isDisposed && state.isSleeping && event === 'change') {
440
- state.isSleeping = false;
441
- if (state.isStale || computedObservable.haveDependenciesChanged()) {
442
- state.dependencyTracking = null;
443
- state.dependenciesCount = 0;
444
- if (computedObservable.evaluateImmediate()) {
445
- computedObservable.updateVersion();
446
- }
447
- } else {
448
- // First put the dependencies in order
449
- var dependenciesOrder = [];
450
- objectForEach(state.dependencyTracking, function (id, dependency) {
451
- dependenciesOrder[dependency._order] = id;
452
- });
453
- // Next, subscribe to each one
454
- arrayForEach(dependenciesOrder, function (id, order) {
455
- var dependency = state.dependencyTracking[id],
456
- subscription = computedObservable.subscribeToDependency(dependency._target);
457
- subscription._order = order;
458
- subscription._version = dependency._version;
459
- state.dependencyTracking[id] = subscription;
460
- });
461
-
462
- // Waking dependencies may have triggered effects
463
- if (computedObservable.haveDependenciesChanged()) {
464
- if (computedObservable.evaluateImmediate()) {
465
- computedObservable.updateVersion();
466
- }
467
- }
468
- }
469
-
470
- if (!state.isDisposed) { // test since evaluating could trigger disposal
471
- computedObservable.notifySubscribers(state.latestValue, 'awake');
472
- }
473
- }
474
- },
475
- afterSubscriptionRemove (event) {
476
- var state = this[computedState];
477
- if (!state.isDisposed && event === 'change' && !this.hasSubscriptionsForEvent('change')) {
478
- objectForEach(state.dependencyTracking, function (id, dependency) {
479
- if (dependency.dispose) {
480
- state.dependencyTracking[id] = {
481
- _target: dependency._target,
482
- _order: dependency._order,
483
- _version: dependency._version
484
- };
485
- dependency.dispose();
486
- }
487
- });
488
- state.isSleeping = true;
489
- this.notifySubscribers(undefined, 'asleep');
490
- }
491
- },
492
- getVersion () {
493
- // Because a pure computed is not automatically updated while it is sleeping, we can't
494
- // simply return the version number. Instead, we check if any of the dependencies have
495
- // changed and conditionally re-evaluate the computed observable.
496
- var state = this[computedState];
497
- if (state.isSleeping && (state.isStale || this.haveDependenciesChanged())) {
498
- this.evaluateImmediate();
499
- }
500
- return subscribable.fn.getVersion.call(this)
501
- }
502
- };
503
-
504
- var deferEvaluationOverrides = {
505
- beforeSubscriptionAdd (event) {
506
- // This will force a computed with deferEvaluation to evaluate when the first subscription is registered.
507
- if (event === 'change' || event === 'beforeChange') {
508
- this.peek();
509
- }
510
- }
511
- };
512
-
513
- Object.setPrototypeOf(computed.fn, subscribable.fn);
514
-
515
- // Set the proto values for ko.computed
516
- var protoProp = observable.protoProperty; // == "__ko_proto__"
517
- computed.fn[protoProp] = computed;
518
-
519
- /* This is used by ko.isObservable */
520
- observable.observablePrototypes.add(computed);
521
-
522
- function isComputed (instance) {
523
- return (typeof instance === 'function' && instance[protoProp] === computed)
524
- }
525
-
526
- function isPureComputed (instance) {
527
- return isComputed(instance) && instance[computedState] && instance[computedState].pure
528
- }
529
-
530
- function pureComputed (evaluatorFunctionOrOptions, evaluatorFunctionTarget) {
531
- if (typeof evaluatorFunctionOrOptions === 'function') {
532
- return computed(evaluatorFunctionOrOptions, evaluatorFunctionTarget, {'pure': true})
533
- } else {
534
- evaluatorFunctionOrOptions = extend({}, evaluatorFunctionOrOptions); // make a copy of the parameter object
535
- evaluatorFunctionOrOptions.pure = true;
536
- return computed(evaluatorFunctionOrOptions, evaluatorFunctionTarget)
537
- }
538
- }
539
-
540
- function throttleExtender (target, timeout) {
541
- // Throttling means two things:
542
-
543
- // (1) For dependent observables, we throttle *evaluations* so that, no matter how fast its dependencies
544
- // notify updates, the target doesn't re-evaluate (and hence doesn't notify) faster than a certain rate
545
- target.throttleEvaluation = timeout;
546
-
547
- // (2) For writable targets (observables, or writable dependent observables), we throttle *writes*
548
- // so the target cannot change value synchronously or faster than a certain rate
549
- var writeTimeoutInstance = null;
550
- return computed({
551
- read: target,
552
- write: function (value) {
553
- clearTimeout(writeTimeoutInstance);
554
- writeTimeoutInstance = setTimeout(function () {
555
- target(value);
556
- }, timeout);
557
- }
558
- })
559
- }
560
-
561
- extenders.throttle = throttleExtender;
562
-
563
- /**
564
- * Create an ES
565
- */
566
-
567
- const PROXY_SYM = Symbol('Knockout Proxied Object');
568
- const MIRROR_SYM = Symbol('Knockout Proxied Observables');
569
-
570
- function makeComputed (proxy, fn) {
571
- return computed({
572
- owner: proxy,
573
- read: fn,
574
- write: fn,
575
- pure: 'pure' in fn ? fn.pure : true,
576
- deferEvaluation: 'deferEvaluation' in fn ? fn.deferEvaluation : true
577
- }).extend({ deferred: true })
578
- }
579
-
580
- function setOrCreate (mirror, prop, value, proxy) {
581
- if (!mirror[prop]) {
582
- const ctr = Array.isArray(value) ? observableArray
583
- : typeof value === 'function' ? makeComputed.bind(null, proxy)
584
- : observable;
585
- mirror[prop] = ctr(value);
586
- } else {
587
- mirror[prop](value);
588
- }
589
- }
590
-
591
- function assignOrUpdate(mirror, object, proxy) {
592
- for (const key of Object.keys(object)) {
593
- setOrCreate(mirror, key, object[key], proxy);
594
- }
595
- return object
596
- }
597
-
598
- function proxy (object) {
599
- const mirror = { [PROXY_SYM]: object };
600
- mirror[MIRROR_SYM] = mirror;
601
- const proxy = new Proxy(function () {}, {
602
- has (target, prop) { return prop in mirror },
603
- get (target, prop) { return unwrap(mirror[prop]) },
604
- set (target, prop, value, receiver) {
605
- setOrCreate(mirror, prop, value, proxy);
606
- object[prop] = value;
607
- return true
608
- },
609
- deleteProperty (property) {
610
- delete mirror[property];
611
- return delete object[property]
612
- },
613
- apply (target, thisArg, [props]) {
614
- if (props) {
615
- assignOrUpdate(mirror, props, proxy);
616
- return Object.assign(object, props)
617
- }
618
- return object
619
- },
620
- getPrototypeOf () { return Object.getPrototypeOf(object) },
621
- setPrototypeOf (target, proto) { return Object.setPrototypeOf(object, proto) },
622
- defineProperty (target, prop, desc) { return Object.defineProperty(object, prop, desc) },
623
- preventExtensions () { return Object.preventExtensions(object) },
624
- isExtensible () { return Object.isExtensible(object) },
625
- ownKeys () {
626
- return [...Object.getOwnPropertyNames(object),
627
- ...Object.getOwnPropertySymbols(object)]
628
- }
629
- });
630
- assignOrUpdate(mirror, object, proxy);
631
- return proxy
632
- }
633
-
634
- function getObservable (proxied, prop) { return proxied[MIRROR_SYM][prop] }
635
- function peek (proxied, prop) { return getObservable(proxied, prop).peek() }
636
- function isProxied (proxied) { return PROXY_SYM in proxied }
637
-
638
- Object.assign(proxy, { getObservable, peek, isProxied });
639
-
640
- function kowhen (predicate, context, resolve) {
641
- const observable$$1 = pureComputed(predicate, context).extend({notify: 'always'});
642
- const subscription = observable$$1.subscribe(value => {
643
- if (value) {
644
- subscription.dispose();
645
- resolve(value);
646
- }
647
- });
648
- // In case the initial value is true, process it right away
649
- observable$$1.notifySubscribers(observable$$1.peek());
650
- return subscription
651
- }
652
-
653
- function when (predicate, callback, context) {
654
- const whenFn = kowhen.bind(null, predicate, context);
655
- return callback ? whenFn(callback.bind(context)) : new Promise(whenFn)
656
- }
657
-
658
- //
659
-
660
- export { computed, isComputed, isPureComputed, pureComputed, throttleExtender, proxy, when };
661
- //# sourceMappingURL=computed.es6.js.map