MCPcopy Create free account
hub / github.com/angular-ui/ui-router / oneTimeWatchDelegate

Function oneTimeWatchDelegate

test/angular/1.7/angular.js:17467–17502  ·  view source on GitHub ↗
(scope, listener, objectEquality, parsedExpression, prettyPrintExpression)

Source from the content-addressed store, hash-verified

17465 }
17466
17467 function oneTimeWatchDelegate(scope, listener, objectEquality, parsedExpression, prettyPrintExpression) {
17468 var isDone = parsedExpression.literal ? isAllDefined : isDefined;
17469 var unwatch, lastValue;
17470
17471 var exp = parsedExpression.$$intercepted || parsedExpression;
17472 var post = parsedExpression.$$interceptor || identity;
17473
17474 var useInputs = parsedExpression.inputs && !exp.inputs;
17475
17476 // Propogate the literal/inputs/constant attributes
17477 // ... but not oneTime since we are handling it
17478 oneTimeWatch.literal = parsedExpression.literal;
17479 oneTimeWatch.constant = parsedExpression.constant;
17480 oneTimeWatch.inputs = parsedExpression.inputs;
17481
17482 // Allow other delegates to run on this wrapped expression
17483 addWatchDelegate(oneTimeWatch);
17484
17485 unwatch = scope.$watch(oneTimeWatch, listener, objectEquality, prettyPrintExpression);
17486
17487 return unwatch;
17488
17489 function unwatchIfDone() {
17490 if (isDone(lastValue)) {
17491 unwatch();
17492 }
17493 }
17494
17495 function oneTimeWatch(scope, locals, assign, inputs) {
17496 lastValue = useInputs && inputs ? inputs[0] : exp(scope, locals, assign, inputs);
17497 if (isDone(lastValue)) {
17498 scope.$$postDigest(unwatchIfDone);
17499 }
17500 return post(lastValue);
17501 }
17502 }
17503
17504 function isAllDefined(value) {
17505 var allDefined = true;

Callers

nothing calls this directly

Calls 1

addWatchDelegateFunction · 0.85

Tested by

no test coverage detected