Event processing queues for angular and sap C4C

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.