Angular

We can see a function called processQueue in the Angular framework code:

This function is started with $scope.$apply:

The core code is inside a for loop. The body of the loop is a queue that stores asynchronous processing tasks:

for (var asyncQueuePosition = 0; asyncQueuePosition < asyncQueue.length; asyncQueuePosition++) {

try {

    asyncTask = asyncQueue[asyncQueuePosition];

    fn = asyncTask.fn;

    fn(asyncTask.scope, asyncTask.locals);

} catch (e) {

      $exceptionHandler(e);

}

     lastDirtyWatch = null;

}

Each element in the queue looks like this: a handler function fn, a local variable locals, and a scope object:

$scope.$apply = $scope.$apply = $scope.$apply = $scope.$apply = $scope.$apply = $scope

// It’s safe for asyncQueuePosition to be a local variable here because this loop can’t

// be reentered recursively. Calling $digest from a function passed to $evalAsync would

// lead to a ‘$digest already in progress’ error.

C4C event queue

C4C’s event handler, EventProcessor. Js, has an event queue:

The implementation of this queue is in SAP /client/evt/ OperationQueue.js:

A click in the C4C UI triggers the EventProcessor’s _ProcessQueue. The C4C event queue works the same way Angular does, except that a while loop replaces Angular’s for loop:

Each element in the C4C event queue has the following attributes, which can be compared to Angular event elements:

FFUNC is equivalent to the Angular time element’s fn attribute, and Environment is equivalent to the Angular event element’s scope attribute.

For more of Jerry’s original articles, please follow the official account “Wang Zixi “: