Best JavaScript code snippet using storybook-root
producer-consumer.js
Source:producer-consumer.js
1$(document).ready(function() {2 var topic="Producer Consumer";3 $('#side_top_navbar').load('../base.html', function(){4 $('.left').html(topic);5 });6 // Selectors7 var $stepn = $('#step-n');8 var $stepnext = $('#step-next');9 var $stepprev = $('#step-prev');10 var $producer = $('#producer');11 var $consumers = $('#consumers');12 var $consumer = $('#consumer');13 var $currentconsumer = $("#consumer-current");14 var $currentproducer = $("#producer-current");15 var $mutex = $('#mutex');16 var $empty = $('#empty');17 var $status = $('#status');18 var $fill = $('#fill');19 var $buffer = $('#buffer');20 // number of persons21 var persons = 6;22 // Initializes number of current step23 var step = 1;24 // JSON object for the steps of simulation25 var steps = [26 {27 producer: 2,28 consumer: 2,29 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],30 mutex: 0,31 empty: 3,32 fill: 0,33 chair: '',34 status: 'System is ready',35 active: 0,36 current_consumer: "",37 current_producer: "",38 status_producer: 2,39 status_consumer: 240 },41 {42 producer: 0,43 consumer: 2,44 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #2', 'Producer #3'],45 mutex: 1,46 empty: 2,47 fill: 0,48 chair: 'Producer #1',49 status: 'Producer #1 arrives, decrements the empty and locks the mutex',50 active: 0,51 current_consumer: "",52 current_producer: "1",53 status_producer: 0,54 status_consumer: 255 },56 {57 producer: 1,58 consumer: 2,59 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #2', 'Producer #3'],60 mutex: 1,61 empty: 2,62 fill: 0,63 chair: 'Producer #1',64 status: 'Producer #1 produces the item.',65 active: 0,66 current_consumer: "",67 current_producer: "1",68 status_producer: 1,69 status_consumer: 270 },71 {72 producer: 0,73 consumer: 2,74 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #2', 'Producer #3'],75 mutex: 0,76 empty: 2,77 fill: 1,78 chair: 'Producer #1',79 status: 'Producer #1 releases the mutex and increments the fill',80 active: 0,81 current_consumer: "",82 current_producer: "1",83 status_producer: 0,84 status_consumer: 285 },86 {87 producer: 2,88 consumer: 2,89 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],90 mutex: 0,91 empty: 2,92 fill: 1,93 chair: '',94 status: 'Producer #1 leaves',95 active: 0,96 current_consumer: "",97 current_producer: "",98 status_producer: 0,99 status_consumer: 2100 },101 {102 producer: 0,103 consumer: 2,104 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #3'],105 mutex: 1,106 empty: 1,107 fill: 1,108 chair: 'Producer #2',109 status: 'Producer #2 arrives, decrements the empty and locks the mutex',110 active: 0,111 current_consumer: "",112 current_producer: "2",113 status_producer: 0,114 status_consumer: 2115 },116 {117 producer: 1,118 consumer: 2,119 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #3'],120 mutex: 1,121 empty: 1,122 fill: 1,123 chair: 'Producer #2',124 status: 'Producer #2 produces the item.',125 active: 0,126 current_consumer: "",127 current_producer: "2",128 status_producer: 1,129 status_consumer: 2130 },131 {132 producer: 0,133 consumer: 2,134 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #3'],135 mutex: 0,136 empty: 1,137 fill: 2,138 chair: 'Producer #2',139 status: 'Producer #2 releases the mutex and increments the fill',140 active: 0,141 current_consumer: "",142 current_producer: "2",143 status_producer: 0,144 status_consumer: 2145 },146 {147 producer: 2,148 consumer: 2,149 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],150 mutex: 0,151 empty: 1,152 fill: 2,153 chair: '',154 status: 'Producer #2 leaves',155 active: 0,156 current_consumer: "",157 current_producer: "",158 status_producer: 2,159 status_consumer: 2160 },161 {162 producer: 2,163 consumer: 0,164 consumers: ['Consumer #1', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],165 mutex: 1,166 empty: 1,167 fill: 1,168 chair: 'Consumer #2',169 status: 'Consumer #2 arrives, decrements the fill and lock the mutex',170 active: 1,171 current_consumer: "2",172 current_producer: "",173 status_producer: 2,174 status_consumer: 0175 },176 {177 producer: 2,178 consumer: 1,179 consumers: ['Consumer #1', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],180 mutex: 1,181 empty: 1,182 fill: 1,183 chair: 'Consumer #2',184 status: 'Consumer #2 consumes the item',185 active: 1,186 current_consumer: "",187 current_producer: "",188 status_producer: 2,189 status_consumer: 1190 },191 {192 producer: 2,193 consumer: 0,194 consumers: ['Consumer #1','Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],195 mutex: 0,196 empty: 2,197 fill: 1,198 chair: 'Consumer #2',199 status: 'Consumer #2 releases the mutex, increments the empty.',200 active: 1,201 current_consumer: "2",202 current_producer: "",203 status_producer: 2,204 status_consumer: 0205 },206 {207 producer: 2,208 consumer: 2,209 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],210 mutex: 0,211 empty: 2,212 fill: 1,213 chair: '',214 status: 'Consumer #2 leaves.',215 active: 1,216 current_consumer: "",217 current_producer: "",218 status_producer: 2,219 status_consumer: 2220 },221 {222 producer: 0,223 consumer: 2,224 consumers: ['Consumer #1','Consumer #2', 'Consumer #3', 'Producer #2', 'Producer #3'],225 mutex: 1,226 empty: 1,227 fill: 1,228 chair: 'Producer #1',229 status: 'Producer #1 arrives, decrements the empty and locks the mutex',230 active: 0,231 current_consumer: "",232 current_producer: "1",233 status_producer: 0,234 status_consumer: 2235 },236 {237 producer: 1,238 consumer: 2,239 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #2', 'Producer #3'],240 mutex: 1,241 empty: 1,242 fill: 1,243 chair: 'Producer #1',244 status: 'Producer #1 produces the item',245 active: 0,246 current_consumer: "",247 current_producer: "",248 status_producer: 1,249 status_consumer: 2250 },251 {252 producer: 0,253 consumer: 2,254 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #2', 'Producer #3'],255 mutex: 0,256 empty: 1,257 fill: 2,258 chair: 'Producer #1',259 status: 'Producer #1 releases the mutex and increments the fill.',260 active: 0,261 current_consumer: "",262 current_producer: "1",263 status_producer: 0,264 status_consumer: 2265 },266 {267 producer: 2,268 consumer: 2,269 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],270 mutex: 0,271 empty: 1,272 fill: 2,273 chair: '',274 status: 'Producer #1 leaves.',275 active: 0,276 current_consumer: "",277 current_producer: "",278 status_producer: 2,279 status_consumer: 2280 },281 {282 producer: 2,283 consumer: 0,284 consumers: [ 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],285 mutex: 1,286 empty: 1,287 fill: 1,288 chair: 'Consumer #1',289 status: 'Consumer #1 arrives, drcrements the fill and locks the mutex.',290 active: 1,291 current_consumer: "1",292 current_producer: "",293 status_producer: 2,294 status_consumer: 0295 },296 {297 producer: 2,298 consumer: 0,299 consumers: ['Consumer #2', 'Producer #1', 'Producer #2', 'Producer #3'],300 mutex: 1,301 empty: 1,302 fill: 1,303 chair: 'Consumer #1',304 status: 'Consumer #3 arrives, tries to consume',305 active: 1,306 current_consumer: "1",307 current_producer: "",308 status_producer: 2,309 status_consumer: 0310 },311 {312 producer: 2,313 consumer: 0,314 consumers: [ 'Consumer #2', 'Producer #1', 'Producer #2', 'Producer #3'],315 mutex: 1,316 empty: 1,317 fill: 1,318 chair: 'Consumer #1',319 status: 'As consumer #1 is consuming, consumer #3 gets blocked .',320 active: 1,321 current_consumer: "1",322 current_producer: "",323 status_producer: 2,324 status_consumer: 0325 },326 {327 producer: 2,328 consumer: 1,329 consumers: [ 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],330 mutex: 1,331 empty: 1,332 fill: 1,333 chair: 'Consumer #1',334 status: 'Consumer #1 consumes the item',335 active: 1,336 current_consumer: "1",337 current_producer: "",338 status_producer: 2,339 status_consumer: 1340 },341 {342 producer: 2,343 consumer: 0,344 consumers: ['Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],345 mutex: 0,346 empty: 2,347 fill: 1,348 chair: 'Consumer #1',349 status: 'Consumer #1 releases the mutex, increments the empty.',350 active: 1,351 current_consumer: "1",352 current_producer: "",353 status_producer: 2,354 status_consumer: 0355 },356 {357 producer: 2,358 consumer: 2,359 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],360 mutex: 0,361 empty: 2,362 fill: 1,363 chair: '',364 status: 'Consumer #1 leaves.',365 active: 0,366 current_consumer: "",367 current_producer: "",368 status_producer: 2,369 status_consumer: 2370 },371 {372 producer: 2,373 consumer: 0,374 consumers: ['Consumer #1', 'Consumer #2', 'Producer #1', 'Producer #2', 'Producer #3'],375 mutex: 1,376 empty: 2,377 fill: 0,378 chair: 'Consumer #3',379 status: 'Consumer #3 arrives, drcrements the fill and locks the mutex.',380 active: 1,381 current_consumer: "3",382 current_producer: "",383 status_producer: 2,384 status_consumer: 0385 },386 {387 producer: 2,388 consumer: 1,389 consumers: ['Consumer #1', 'Consumer #2', 'Producer #1', 'Producer #2', 'Producer #3'],390 mutex: 1,391 empty: 2,392 fill: 0,393 chair: 'Consumer #3',394 status: 'Consumer #3 consumes the data.',395 active: 1,396 current_consumer: "3",397 current_producer: "",398 status_producer: 2,399 status_consumer: 1400 },401 {402 producer: 2,403 consumer: 0,404 consumers: ['Consumer #1', 'Consumer #2', 'Producer #1', 'Producer #2', 'Producer #3'],405 mutex: 1,406 empty: 3,407 fill: 0,408 chair: 'Consumer #3',409 status: 'Consumer #3 releases the mutex, increments the empty.',410 active: 1,411 current_consumer: "3",412 current_producer: "",413 status_producer: 2,414 status_consumer: 0415 },416 {417 producer: 2,418 consumer: 2,419 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],420 mutex: 0,421 empty: 3,422 fill: 0,423 chair: '',424 status: 'Consumer #3 leaves',425 active: 1,426 current_consumer: "",427 current_producer: "",428 status_producer: 2,429 status_consumer: 2430 },431 {432 producer: 2,433 consumer: 0,434 consumers: [ 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],435 mutex: 0,436 empty: 3,437 fill: 0,438 chair: '',439 status: 'Consumer #1 arrives and tries to drcrements the fill.',440 active: 1,441 current_consumer: "",442 current_producer: "",443 status_producer: 2,444 status_consumer: 0445 },446 {447 producer: 2,448 consumer: 0,449 consumers: [ 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],450 mutex: 0,451 empty: 3,452 fill: 0,453 chair: '',454 status: 'As there are no items to consume for Consumer #1, action to consume gets blocked',455 active: 1,456 current_consumer: "",457 current_producer: "",458 status_producer: 2,459 status_consumer: 0460 },461 {462 producer: 2,463 consumer: 2,464 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],465 mutex: 0,466 empty: 3,467 fill: 0,468 chair: '',469 status: 'Consumer #1 leaves',470 active: 1,471 current_consumer: "",472 current_producer: "",473 status_producer: 2,474 status_consumer: 2475 },476 {477 producer: 0,478 consumer: 2,479 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2'],480 mutex: 1,481 empty: 2,482 fill: 0,483 chair: 'Producer #3',484 status: 'Producer #3 arrives, decrements the empty and locks the mutex',485 active: 0,486 current_consumer: "",487 current_producer: 3,488 status_producer: 0,489 status_consumer: 2490 },491 {492 producer: 1,493 consumer: 2,494 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2'],495 mutex: 1,496 empty: 2,497 fill: 0,498 chair: 'Producer #3',499 status: 'Producer #3 produces the item.',500 active: 0,501 current_consumer: "",502 current_producer: "3",503 status_producer: 1,504 status_consumer: 2505 },506 {507 producer: 0,508 consumer: 2,509 consumers: ['Consumer #1', 'Consumer #2', 'Producer #1', 'Producer #2', 'Producer #3'],510 mutex: 0,511 empty: 2,512 fill: 1,513 chair: 'Producer #3',514 status: 'Producer #3 releases the mutex and increments the fill.',515 active: 0,516 current_consumer: "",517 current_producer: "3",518 status_producer: 0,519 status_consumer: 2520 },521 {522 producer: 2,523 consumer: 2,524 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],525 mutex: 0,526 empty: 2,527 fill: 1,528 chair: '',529 status: 'Producer #3 leaves.',530 active: 0,531 current_consumer: "",532 current_producer: "",533 status_producer: 2,534 status_consumer: 2535 },536 {537 producer: 0,538 consumer: 2,539 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #3'],540 mutex: 1,541 empty: 1,542 fill: 1,543 chair: 'Producer #2',544 status: 'Producer #2 arrives, decrements the empty and locks the mutex',545 active: 0,546 current_consumer: "",547 current_producer: "2",548 status_producer: 0,549 status_consumer: 2550 },551 {552 producer: 1,553 consumer: 2,554 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #3'],555 mutex: 1,556 empty: 1,557 fill: 1,558 chair: 'Producer #2',559 status: 'Producer #2 produces the item.',560 active: 0,561 current_consumer: "",562 current_producer: "2",563 status_producer: 1,564 status_consumer: 2565 },566 {567 producer: 0,568 consumer: 2,569 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #3'],570 mutex: 0,571 empty: 1,572 fill: 2,573 chair: 'Producer #2',574 status: 'Producer #2 releases the mutex and increments the fill.',575 active: 0,576 current_consumer: "",577 current_producer: "2",578 status_producer: 0,579 status_consumer: 2580 },581 {582 producer: 2,583 consumer: 2,584 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],585 mutex: 0,586 empty: 1,587 fill: 2,588 chair: '',589 status: 'Producer #2 leaves.',590 active: 0,591 current_consumer: "",592 current_producer: "",593 status_producer: 2,594 status_consumer: 2595 },596 {597 producer: 0,598 consumer: 2,599 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #2', 'Producer #3'],600 mutex: 1,601 empty: 0,602 fill: 2,603 chair: 'Producer #1',604 status: 'Producer #1 arrives, decrements the empty and locks the mutex',605 active: 0,606 current_consumer: "",607 current_producer: "1",608 status_producer: 0,609 status_consumer: 2610 },611 {612 producer: 1,613 consumer: 2,614 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #2', 'Producer #3'],615 mutex: 1,616 empty: 0,617 fill: 2,618 chair: 'Producer #1',619 status: 'Producer #1 produces the item.',620 active: 0,621 current_consumer: "",622 current_producer: "1",623 status_producer: 1,624 status_consumer: 2625 },626 {627 producer: 0,628 consumer: 2,629 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3','Producer #2', 'Producer #3'],630 mutex: 0,631 empty: 0,632 fill: 3,633 chair: 'Producer #1',634 status: 'Producer #1 releases the mutex and increments the fill.',635 active: 0,636 current_consumer: "",637 current_producer: "1",638 status_producer: 0,639 status_consumer: 2640 },641 {642 producer: 2,643 consumer: 2,644 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],645 mutex: 0,646 empty: 0,647 fill: 3,648 chair: '',649 status: 'Producer #1 leaves.',650 active: 0,651 current_consumer: "",652 current_producer: "",653 status_producer: 2,654 status_consumer: 2655 },656 {657 producer: 0,658 consumer: 2,659 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #3'],660 mutex: 0,661 empty: 0,662 fill: 3,663 chair: '',664 status: 'Producer #2 arrives, tries to decrement empty.As the buffer is full, request gets blocked.',665 active: 0,666 current_consumer: "",667 current_producer: "",668 status_producer: 0,669 status_consumer: 2670 },671 {672 producer: 2,673 consumer: 2,674 consumers: ['Consumer #1', 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2','Producer #3'],675 mutex: 0,676 empty: 0,677 fill: 3,678 chair: '',679 status: 'Producer #2 leaves',680 active: 0,681 current_consumer: "",682 current_producer: "",683 status_producer: 2,684 status_consumer: 2685 },686 {687 producer: 2,688 consumer: 0,689 consumers: ['Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3',],690 mutex: 1,691 empty: 0,692 fill: 2,693 chair: 'Consumer #1',694 status: 'Consumer #1 arrives, drcrements the fill and locks the mutex.',695 active: 1,696 current_consumer: "1",697 current_producer: "",698 status_producer: 2,699 status_consumer: 0700 },701 {702 producer: 2,703 consumer: 1,704 consumers: [ 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],705 mutex: 1,706 empty: 0,707 fill: 2,708 chair: 'Consumer #1',709 status: 'Consumer #1 consumes the data.',710 active: 1,711 current_consumer: "1",712 current_producer: "",713 status_producer: 2,714 status_consumer: 1715 },716 {717 producer: 2,718 consumer: 0,719 consumers: [ 'Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],720 mutex: 0,721 empty: 1,722 fill: 2,723 chair: 'Consumer #1',724 status: 'Consumer #1 releases the mutex, increments the empty.',725 active: 1,726 current_consumer: "1",727 current_producer: "",728 status_producer: 2,729 status_consumer: 0730 },731 {732 producer: 2,733 consumer: 2,734 consumers: [ 'Consumer #1','Consumer #2', 'Consumer #3', 'Producer #1', 'Producer #2', 'Producer #3'],735 mutex: 0,736 empty: 1,737 fill: 2,738 chair: '',739 status: 'Consumer #1 leaves',740 active: 0,741 current_consumer: "",742 current_producer: "",743 status_producer: 2,744 status_consumer: 2745 }]746 // Loads the nth step of the visualization747 var loadStep = function(n) {748 // Update state table values749 $producer.text(function() {750 if (steps[n-1]['producer'] == 0) {751 return 'Waiting';752 }753 else if (steps[n-1]['producer'] == 1) {754 return 'Producing';755 }756 else {757 return 'Idle';758 }759 });760 $consumer.text(function() {761 if (steps[n-1]['consumer'] == 0) {762 return 'Waiting';763 }764 else if (steps[n-1]['consumer'] == 1) {765 return 'Consuming';766 }767 else {768 return 'Idle';769 }770 });771 $mutex.text(function() {772 if (steps[n-1]['mutex'] == 0) {773 return 'Unlocked';774 }775 else {776 return 'Locked';777 }778 });779 $empty.text(steps[n-1]['empty']);780 $fill.text(steps[n-1]['fill']);781 $status.text(steps[n-1]['status']);782 $buffer.text(function() {783 if (steps[n-1]['chair']) {784 return steps[n-1]['chair'];785 }786 else {787 return '\xa0';788 }789 });790 // Fill the buffer with currently executing791 // If a buffer is empty, put a space792 var consumers = steps[n-1]['consumers'];793 for (var i = 0; i < persons; i++) {794 $('#chair' + (i+1)).text(function() {795 if (consumers[i]) {796 return consumers[i]; 797 }798 else {799 return '\xa0';800 }801 });802 }803 // Toggles the producer function's semaphore label804 if (steps[n-1]['status_producer'] == 0) {805 $('#producer-status').attr('class', 'label label-warning');806 $('#producer-status').text('Waiting');807 }808 else if(steps[n-1]['status_producer'] == 1) {809 $('#producer-status').attr('class', 'label label-success');810 $('#producer-status').text('Producing');811 }812 else {813 $('#producer-status').attr('class', 'label label-default');814 $('#producer-status').text('None');815 }816 if (steps[n-1]['current_producer']) {817 $('#producer-current').show();818 $('#producer-current').text('producer #' + steps[n-1]['current_producer'])819 }820 else {821 $('#producer-current').hide();822 }823 // Shows the id of the current consumer function being displayed824 if (steps[n-1]['current_consumer']) {825 $('#consumer-current').show();826 $('#consumer-current').text('consumer #' + steps[n-1]['current_consumer'])827 }828 else {829 $('#consumer-current').hide();830 }831 // Toggles the consumer's semaphore label832 if (steps[n-1]['status_consumer'] == 0) {833 $('#consumer-status').attr('class', 'label label-warning');834 $('#consumer-status').text('Waiting');835 }836 else if (steps[n-1]['status_consumer'] == 1) {837 $('#consumer-status').attr('class', 'label label-success');838 $('#consumer-status').text('Consuming');839 }840 else {841 $('#consumer-status').attr('class', 'label label-default');842 $('#consumer-status').text('None');843 }844 // Toggles the active thread label845 if (steps[n-1]['active'] == 0) {846 $('#producer-active').show();847 $('#consumer-active').hide();848 }849 else {850 $('#producer-active').hide();851 $('#consumer-active').show();852 }853 // Update step number in navigation buttons854 $stepn.text(step + '/' + steps.length);855 }856 // Resets visualization to the first step857 var resetVisualization = function() {858 step = 1;859 loadStep(1);860 }861 // Previous and next step button handlers862 $stepnext.click(function() {863 if (step < steps.length) {864 step += 1;865 loadStep(step);866 }867 });868 $stepprev.click(function() {869 if (step > 1) {870 step -= 1;871 loadStep(step);872 }873 });874 // Reset visualization after document loads875 resetVisualization();...
eventConsumerList.ts
Source:eventConsumerList.ts
1import CrusadeEventConsumer from "../../../affect/eventConsumer/crusadeEventConsumer"2import DamageSourceEventConsumer from "../../../affect/eventConsumer/damageSourceEventConsumer"3import DetectTouchEventConsumer from "../../../affect/eventConsumer/detectTouchEventConsumer"4import EnduranceEventConsumer from "../../../affect/eventConsumer/enduranceEventConsumer"5import FlyEventConsumer from "../../../affect/eventConsumer/flyEventConsumer"6import ForgetEventConsumer from "../../../affect/eventConsumer/forgetEventConsumer"7import HasteEventConsumer from "../../../affect/eventConsumer/hasteEventConsumer"8import HolySilenceEventConsumer from "../../../affect/eventConsumer/holySilenceEventConsumer"9import OrbOfTouchEventConsumer from "../../../affect/eventConsumer/orbOfTouchEventConsumer"10import ProtectionEventConsumer from "../../../affect/eventConsumer/protectionEventConsumer"11import SanctuaryEventConsumer from "../../../affect/eventConsumer/sanctuaryEventConsumer"12import WithstandDeathEventConsumer from "../../../affect/eventConsumer/withstandDeathEventConsumer"13/*tslint:disable*/14import AutoLookWhenPlayerMobMovesEventConsumer from "../../../client/eventConsumer/autoLookWhenPlayerMobMovesEventConsumer"15import ClientDisconnectRemoveClientEventConsumer from "../../../client/eventConsumer/clientDisconnectRemoveClientEventConsumer"16import ClientDisconnectRemoveMobEventConsumer from "../../../client/eventConsumer/clientDisconnectRemoveMobEventConsumer"17/*tslint:enable*/18import LoggedInEventConsumer from "../../../client/eventConsumer/loggedInEventConsumer"19import SendMessageToMobEventConsumer from "../../../client/eventConsumer/sendMessageToMobEventConsumer"20import SocialEventConsumer from "../../../client/eventConsumer/socialEventConsumer"21import ItemCreatedEventConsumer from "../../../item/eventConsumer/itemCreatedEventConsumer"22import ItemDestroyedEventConsumer from "../../../item/eventConsumer/itemDestroyedEventConsumer"23import FavoredWeaponEffectEventConsumer from "../../../item/eventConsumer/weaponEffect/favoredWeaponEffectEventConsumer"24import FlamingWeaponEffectEventConsumer from "../../../item/eventConsumer/weaponEffect/flamingWeaponEffectEventConsumer"25import FrostWeaponEffectEventConsumer from "../../../item/eventConsumer/weaponEffect/frostWeaponEffectEventConsumer"26/* tslint:disable */27import ShockingWeaponEffectEventConsumer from "../../../item/eventConsumer/weaponEffect/shockingWeaponEffectEventConsumer"28import VampiricWeaponEffectEventConsumer from "../../../item/eventConsumer/weaponEffect/vampiricWeaponEffectEventConsumer"29/* tslint:enable */30import VorpalWeaponEffectEventConsumer from "../../../item/eventConsumer/weaponEffect/vorpalWeaponEffectEventConsumer"31import AddCorpseToRoomOnDeathEventConsumer from "../../../mob/eventConsumer/addCorpseToRoomOnDeathEventConsumer"32import AggressiveMobEventConsumer from "../../../mob/eventConsumer/aggressiveMobEventConsumer"33import DamageModifierEventConsumer from "../../../mob/eventConsumer/damageModifierEventConsumer"34import DeathTimerEventConsumer from "../../../mob/eventConsumer/deathTimerEventConsumer"35import FightStarterEventConsumer from "../../../mob/eventConsumer/fightStarterEventConsumer"36import FollowMobEventConsumer from "../../../mob/eventConsumer/followMobEventConsumer"37import MobCreatedEventConsumer from "../../../mob/eventConsumer/mobCreatedEventConsumer"38import MobScavengesRoomEventConsumer from "../../../mob/eventConsumer/mobScavengesRoomEventConsumer"39import PetFollowsOwnerEventConsumer from "../../../mob/eventConsumer/petFollowsOwnerEventConsumer"40import WimpyEventConsumer from "../../../mob/eventConsumer/wimpyEventConsumer"41import DrowMageBonusEventConsumer from "../../../mob/race/eventConsumer/drow/drowMageBonusEventConsumer"42import ElfForestRegenBonusEventConsumer from "../../../mob/race/eventConsumer/elf/elfForestRegenBonusEventConsumer"43import ElfIronVulnEventConsumer from "../../../mob/race/eventConsumer/elf/elfIronVulnEventConsumer"44import HalflingMvBonusEventConsumer from "../../../mob/race/eventConsumer/halfling/halflingMvBonusEventConsumer"45import OgreBashBonusEventConsumer from "../../../mob/race/eventConsumer/ogre/ogreBashBonusEventConsumer"46import OgreSizeMismatchVulnEventConsumer from "../../../mob/race/eventConsumer/ogre/ogreSizeMismatchVulnEventConsumer"47/*tslint:disable*/48import BludgeonDamageTypeEventConsumer from "../../../mob/skill/eventConsumer/damageType/bludgeonDamageTypeEventConsumer"49/*tslint:enable*/50import CleaveDamageTypeEventConsumer from "../../../mob/skill/eventConsumer/damageType/cleaveDamageTypeEventConsumer"51import DodgeEventConsumer from "../../../mob/skill/eventConsumer/dodgeEventConsumer"52import SecondAttackEventConsumer from "../../../mob/skill/eventConsumer/extraAttack/secondAttackEventConsumer"53import ThirdAttackEventConsumer from "../../../mob/skill/eventConsumer/extraAttack/thirdAttackEventConsumer"54import FastHealingEventConsumer from "../../../mob/skill/eventConsumer/fastHealingEventConsumer"55import ImproveInvokedSkillsEventConsumer from "../../../mob/skill/eventConsumer/improveInvokedSkillsEventConsumer"56import ParryEventConsumer from "../../../mob/skill/eventConsumer/parryEventConsumer"57import ShieldBlockEventConsumer from "../../../mob/skill/eventConsumer/shieldBlockEventConsumer"58import AddExperienceFromKillEventConsumer from "../../../player/eventConsumer/addExperienceFromKillEventConsumer"59import AutoLootCorpseEventConsumer from "../../../player/eventConsumer/autoLootCorpseEventConsumer"60import AutoSacCorpseEventConsumer from "../../../player/eventConsumer/autoSacCorpseEventConsumer"61import CollectBountyOnKillEventConsumer from "../../../player/eventConsumer/collectBountyOnKillEventConsumer"62import FatalityMessagesEventConsumer from "../../../player/eventConsumer/fatalityMessagesEventConsumer"63import IncrementDeathCountsEventConsumer from "../../../player/eventConsumer/incrementDeathCountsEventConsumer"64import MobArrivesInRoomEventConsumer from "../../../player/eventConsumer/mobArrivesInRoomEventConsumer"65import MobLeavesRoomEventConsumer from "../../../player/eventConsumer/mobLeavesRoomEventConsumer"66import ResetPlayerMobOnDeathEventConsumer from "../../../player/eventConsumer/resetPlayerMobOnDeathEventConsumer"67import SaveEventConsumer from "../../../player/eventConsumer/saveEventConsumer"68import RoomMessageEventConsumer from "../../../room/eventConsumer/roomMessageEventConsumer"69export default [70 // affects71 SanctuaryEventConsumer,72 CrusadeEventConsumer,73 ForgetEventConsumer,74 HasteEventConsumer,75 DamageSourceEventConsumer,76 ProtectionEventConsumer,77 WithstandDeathEventConsumer,78 DetectTouchEventConsumer,79 HolySilenceEventConsumer,80 OrbOfTouchEventConsumer,81 EnduranceEventConsumer,82 FlyEventConsumer,83 // mob actions84 AggressiveMobEventConsumer,85 PetFollowsOwnerEventConsumer,86 MobScavengesRoomEventConsumer,87 WimpyEventConsumer,88 FightStarterEventConsumer,89 MobCreatedEventConsumer,90 DamageModifierEventConsumer,91 FollowMobEventConsumer,92 DeathTimerEventConsumer,93 AddCorpseToRoomOnDeathEventConsumer,94 FatalityMessagesEventConsumer,95 ResetPlayerMobOnDeathEventConsumer,96 // player97 MobArrivesInRoomEventConsumer,98 MobLeavesRoomEventConsumer,99 RoomMessageEventConsumer,100 SendMessageToMobEventConsumer,101 ClientDisconnectRemoveMobEventConsumer,102 ClientDisconnectRemoveClientEventConsumer,103 LoggedInEventConsumer,104 AutoLookWhenPlayerMobMovesEventConsumer,105 SocialEventConsumer,106 CollectBountyOnKillEventConsumer,107 AddExperienceFromKillEventConsumer,108 ImproveInvokedSkillsEventConsumer,109 IncrementDeathCountsEventConsumer,110 AutoLootCorpseEventConsumer,111 AutoSacCorpseEventConsumer,112 SaveEventConsumer,113 // race114 ElfIronVulnEventConsumer,115 ElfForestRegenBonusEventConsumer,116 OgreSizeMismatchVulnEventConsumer,117 OgreBashBonusEventConsumer,118 HalflingMvBonusEventConsumer,119 DrowMageBonusEventConsumer,120 // item121 ItemDestroyedEventConsumer,122 ItemCreatedEventConsumer,123 // weapon effects124 FlamingWeaponEffectEventConsumer,125 FrostWeaponEffectEventConsumer,126 VampiricWeaponEffectEventConsumer,127 VorpalWeaponEffectEventConsumer,128 ShockingWeaponEffectEventConsumer,129 FavoredWeaponEffectEventConsumer,130 // skills131 DodgeEventConsumer,132 FastHealingEventConsumer,133 SecondAttackEventConsumer,134 ThirdAttackEventConsumer,135 ShieldBlockEventConsumer,136 ParryEventConsumer,137 BludgeonDamageTypeEventConsumer,138 CleaveDamageTypeEventConsumer,...
consumers.js
Source:consumers.js
1const initialState = {};2const consumers = (state = initialState, action) =>3{4 switch (action.type)5 {6 case 'ADD_CONSUMER':7 {8 const { consumer } = action.payload;9 return { ...state, [consumer.id]: consumer };10 }11 case 'REMOVE_CONSUMER':12 {13 const { consumerId } = action.payload;14 const newState = { ...state };15 delete newState[consumerId];16 return newState;17 }18 case 'SET_CONSUMER_PAUSED':19 {20 const { consumerId, originator } = action.payload;21 const consumer = state[consumerId];22 let newConsumer;23 if (originator === 'local')24 newConsumer = { ...consumer, locallyPaused: true };25 else26 newConsumer = { ...consumer, remotelyPaused: true };27 return { ...state, [consumerId]: newConsumer };28 }29 case 'SET_CONSUMER_RESUMED':30 {31 const { consumerId, originator } = action.payload;32 const consumer = state[consumerId];33 let newConsumer;34 if (originator === 'local')35 newConsumer = { ...consumer, locallyPaused: false };36 else37 newConsumer = { ...consumer, remotelyPaused: false };38 return { ...state, [consumerId]: newConsumer };39 }40 case 'SET_CONSUMER_CURRENT_LAYERS':41 {42 const { consumerId, spatialLayer, temporalLayer } = action.payload;43 const consumer = state[consumerId];44 const newConsumer =45 {46 ...consumer,47 currentSpatialLayer : spatialLayer,48 currentTemporalLayer : temporalLayer49 };50 return { ...state, [consumerId]: newConsumer };51 }52 case 'SET_CONSUMER_PREFERRED_LAYERS':53 {54 const { consumerId, spatialLayer, temporalLayer } = action.payload;55 const consumer = state[consumerId];56 const newConsumer =57 {58 ...consumer,59 preferredSpatialLayer : spatialLayer,60 preferredTemporalLayer : temporalLayer61 };62 return { ...state, [consumerId]: newConsumer };63 }64 case 'SET_CONSUMER_PRIORITY':65 {66 const { consumerId, priority } = action.payload;67 const consumer = state[consumerId];68 const newConsumer = { ...consumer, priority };69 return { ...state, [consumerId]: newConsumer };70 }71 case 'SET_CONSUMER_TRACK':72 {73 const { consumerId, track } = action.payload;74 const consumer = state[consumerId];75 const newConsumer = { ...consumer, track };76 return { ...state, [consumerId]: newConsumer };77 }78 case 'SET_CONSUMER_SCORE':79 {80 const { consumerId, score } = action.payload;81 const consumer = state[consumerId];82 if (!consumer)83 return state;84 const newConsumer = { ...consumer, score };85 return { ...state, [consumerId]: newConsumer };86 }87 case 'CLEAR_CONSUMERS':88 {89 return initialState;90 }91 default:92 return state;93 }94};...
Using AI Code Generation
1import { Consumer } from 'storybook-root-decorator';2import { withInfo } from '@storybook/addon-info';3import { withKnobs, text } from '@storybook/addon-knobs';4import { storiesOf } from '@storybook/react';5import React from 'react';6import MyComponent from '../src';7storiesOf('MyComponent', module)8 .addDecorator(withInfo)9 .addDecorator(withKnobs)10 .add('with text', () => (11 {({ theme }) => (12 theme={theme}13 text={text('Text', 'Hello Storybook')}14 )}15 ));16MIT © [siddharthkp](
Using AI Code Generation
1import { Consumer } from "storybook-root-decorator";2import { ThemeProvider } from "styled-components";3export default class Test extends React.Component {4 render() {5 return (6 {theme => (7 <ThemeProvider theme={theme}>8 )}9 );10 }11}12import { addDecorator } from "@storybook/react";13import { withRootDecorator } from "storybook-root-decorator";14export default {15};16addDecorator(withRootDecorator({ theme: require("./theme") }));17MIT © [Karthik Nair](
Using AI Code Generation
1import { Consumer } from 'storybook-root';2const Test = () => (3 {({ theme, toggleTheme }) => (4 style={{5 }}6 <button onClick={toggleTheme}>Toggle Theme</button>7 )}8);9MIT © [aakashsharma06](
Using AI Code Generation
1import { Consumer } from 'storybook-root-decorator';2import { storiesOf } from '@storybook/react';3import { withKnobs } from '@storybook/addon-knobs';4import { withRoot } from 'storybook-root-decorator';5import React from 'react';6import { withInfo } from '@storybook/addon-info';7import { withReadme } from 'storybook-readme';8import Readme from './README.md';9import { withDocsCustom } from 'storybook-readme';10import { withDocs } from 'storybook-readme';11import { withA11y } from '@storybook/addon-a11y';12import { withTests } from '@storybook/addon-jest';13import results from '../../../../.jest-test-results.json';14import { withConsole } from '@storybook/addon-console';15import { withSmartKnobs } from 'storybook-addon-smart-knobs';16import { withViewport } from '@storybook/addon-viewport';17import { withBackgrounds } from '@storybook/addon-backgrounds';18import { withState } from '@dump247/storybook-state';19import { withPropsTable } from 'storybook-addon-react-docgen';20import { withOptions } from '@storybook/addon-options';21import { withCssResources } from '@storybook/addon-cssresources';22import { withLinks } from '@storybook/addon-links';23import { withPerformance } from 'storybook-addon-performance';24import { withContexts } from '@storybook/addon-contexts/react';25import { withActions } from '@storybook/addon-actions';26import { withStorysource } from '@storybook/addon-storysource';27import { withGraphQL } from 'storybook-addon-graphql';28import { withI18n } from 'storybook-addon-i18n';29import { withNotes } from '@storybook/addon-notes';30import { withPaddings } from 'storybook-addon-paddings';31import { withCentered } from '@storybook/addon-centered/react';32import { withFigma } from 'storybook-addon-figma';33import { withEmotion } from 'storybook-addon-emotion-theme';34import { withRedux } from 'storybook-addon-redux';35import { withReduxDecorator } from 'storybook-addon-redux-decorator';36import { withStorybookTheme } from 'storybook-addon-storybook-theme';37import { withStorybookThemeSelector } from 'storybook-addon-storybook-theme-selector';38import { withTheme } from 'storybook-addon-theme';39import { withThemes } from 'storybook
Using AI Code Generation
1import { Consumer } from 'storybook-root';2const Component = () => (3 {({ theme, toggleTheme }) => (4 <button onClick={toggleTheme}>5 {theme === 'light' ? 'Switch to dark' : 'Switch to light'}6 )}7);8You can see this in action in the [demo](
Using AI Code Generation
1import { Consumer } from 'storybook-root-config';2 {({ theme, setTheme, setLocale, locale }) => (3 <div>Current theme: {theme}</div>4 <div>Current locale: {locale}</div>5 <button onClick={() => setTheme('light')}>Light theme</button>6 <button onClick={() => setTheme('dark')}>Dark theme</button>7 <button onClick={() => setLocale('en')}>English</button>8 <button onClick={() => setLocale('fr')}>French</button>9 )}10</Consumer>;
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!