Angular
We can see a function named Processqueue in the code of the angular framework:
This function is initiated by the $scope. $apply:
The core code is in a for loop, and the loop body is a queue asyncqueueposition 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 is like this: a handler function, FN, a local variable locals, and a scope object:
This annotation is also useful: once angular discovers that the JavaScript execution sequence triggered by the $scope. $apply appears again in the $scope. $apply nested call that throws an error message: $digest already in progress
It's safe for asyncqueueposition-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 event handler, Eventprocessor.js has an event queue:
The implementation of this queue is in the operationqueue.js of sap/client/evt/:
Just do a click in the C4c UI, and the _PROCESSQUEUE,C4C event queue that can trigger Eventprocessor is the same as the angular idea, except that a while loop replaces the angular for loop:
Each element in the C4C event queue has the following attributes, which can be compared with the angular event element:
Ffunc is equivalent to the FN property of the angular time element, environment equivalent to the scope property of the angular event element.
To get more original Jerry's articles, please follow the public number "Wang Zixi":
Event processing queues for angular and sap C4C