Problem arising from the transition between Q library versions 0.9.6 and 0.9.7

My experience with the q library was successful in processing ajax data sequentially. Each ajax call is followed by a.then( function(){} ) to ensure proper sequencing.

During the processing of individual data entries, I display the ajax result on screen using a deferred object that notifies me when the text has been entered into a div (reaching 100% completion).

Everything worked smoothly with q v. 0.9.6 but encountered a TypeError {} issue with v. 0.9.7. It seems that the deferred object fails to propagate progress for some reason. The changelog didn't provide much insight: q changelog.

I have simplified and prepared two versions of the code, one working - 0.9.6, and the other not working - 0.9.7. Both examples share the same code, differing only in the version of the q library used.

Furthermore, I have provided details of the code in the CSS section for clarity.

If this question seems trivial, I apologize in advance.


Due to JSFiddle link restrictions, here is the code excerpt:

Libraries utilized:

  • jQuery
  • ajaxFake by ANas Nakawa
  • Teletype (used for typing text into a div)
  • yodaProgress (custom graphical progress bar with .progress(step 0.00 - 1.00) and .isDone() functions)
  • q v. 0.9.6 / q v. 0.9.7

Html:

<div id="progress_1"></div>

Javascript:

$(document).ready(function() {

    // Declaration for DEFERRED object
    var mainObject = {
    }

    // Fake ajax Data
    $.ajax.fake.registerWebservice('blah', function (data) {
        return {
            result: 'My fake ajax result should be typed into the div!', 
        };
    });

    // 1. START
    var nextTick = Q.when();

    // 2. PROCESS 3 ITEMS SEQUENTIALLY
    for (var i = 0, length = 3; i < length; i ++) {
        nextTick = nextTick.then(
            processAjaxCall,
            function(error)     { console.log("This is an error 2.");   },
            function(progress)  { console.log("This is a progress 2."); }
        );

    }

    // 3. FINALLY DO THIS
    nextTick.fin(
        function(result)    { console.log("This is a final result 3.");     },
        function(error)     { console.log("This is an error 3.");   },
        function(progress)  { console.log("This is a progress 3.");}
    );


    // Function to process each item sequentially
    function processAjaxCall () {
        // Code implementation here
    }


    // Additional functions referenced

});

Explanation:

  Explanation of the functional code.

  Clarification of operation under different version scenarios.
  
  Remember, the purpose of this code is illustrative.

P.S. Upon inspecting the TypeError object in Chrome, it indicates "Object has no 'when()' method," providing a starting point for further investigation. Prior to this insight, the message displayed was simply 'TypeError {}'. Understanding the significant operational differences requires additional research.

Thank you!

Answer №1

Yay, problem solved!

It seems that the deferred object structure underwent some internal changes with the 0.9.7 release. Interestingly, the changelog only mentions these alterations in the "0.9.6" section.

In version 0.9.6, when I inspected the console for:

var deferred = Q.defer();
deferred.promise.__proto__ 

I noticed the presence of the when() function. Surprisingly, the deferred.promise is not exactly a Promise object but something different.

However, in version 0.9.7, when I ran the same code:

var deferred = Q.defer();
deferred.promise.__proto__ 

I received back a Promise object containing a then() method and no 'when()` method anymore.

So, it appears that the changelog was misleading or maybe I just need to check my sanity.

If I navigate to the q library's GitHub repo, and go to "Tags" -> "0.9.6" -> "CHANGES.md" file, the beginning of the document highlights the "0.9.5" section. This suggests that the author wanted to show the changes FROM 0.9.5 that are present in 0.9.6.

This approach could make sense since the master branch details changes under 0.9.7, indicating they are once again modifications FROM 0.9.7 to the subsequent version (presumably 0.9.8).

Lesson learned: don't always rely on the numbers in a changelog! :p

A big thank you to everyone who contributed to this solution!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for Making Changes to a Polyline on Google Maps

I am currently utilizing the Directions Service provided by Google Maps V3 API, and I have a specific requirement to shorten the length of one of the steps by 1 meter (let's assume it's the final step). Issue: The directionResult can be viewed h ...

Are there more efficient methods than having to include require('mongoose') in each models file?

Is it possible to only require mongoose once in the main app.js file and then pass it to other files without loading it again? Will the script do extra work every time the same module is required? var mongoose = require('mongoose'); I'm wo ...

Click-triggered Animation of Glyphicon

I'm attempting to create an animation for a glyphicon-refresh icon that rotates when clicked. I've been trying to achieve this effect using CSS3, but haven't had much success. Below is the code I've used: <a id="update" href="#"> ...

Add a file to your Node.js project with Vue.js integration

I am trying to figure out how I can include another JavaScript file in a similar way to PHP's include function. I'm not interested in the export function, as that only allows you to use variables from other files. Currently, I am using vue init ...

The jQuery selector is unable to locate the IMG element using its unique ID

I'm experiencing an issue with a webpage that includes the following code snippet: <img class="img-qrcode" id="img_123.000.00.01" src="http://localhost:7777/data/code_img\123.000.00.01.png" alt="./data/code_img\123.000.00.01. ...

What is the best way to incorporate a description box for each city on the svg map that appears when you hover your mouse over it?

I am looking to display detailed descriptions for each city in the same consistent location on my map. With multiple pieces of information to include for each city, I want to ensure that the description box is positioned at the bottom of the map. Can any ...

A loop variable in Javascript is a function that iterates

var x = 99; while (true) { function lyrics(person) { return x + " " + "lines of code in the file " + x + " " + person + (x-1) + " lines of code" + "!"; } console.log(lyrics("John strikes one out, clears it all out ;")); x -= 1; if (x ...

Preventing a draggable item from being dropped into a sortable container when the maximum count has been reached

Check out the following code snippet: <link rel="stylesheet" href="//code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.0/jquer ...

Changing the hover background color and text color of Material UI Button

I recently developed a custom Appbar component using React.js that includes 3 buttons. I'm looking to enhance the user experience by changing the color scheme when users hover over these buttons. Currently, the background color is set to #3c52b2 and t ...

Verify whether the included file is being utilized by ajax or php

I have developed a unique system in which PHP or AJAX is used to build the HTML dynamically. Since the structure of the generated HTML remains consistent, I decided to create an include file that can be accessed by both PHP and JavaScript functions. My que ...

Every time I attempt to reference the camera position in three.js, I am only able to access the initial position and not the present location

I am currently modifying a path file in THREEJS for a 3D art gallery project. My goal is to ensure that the camera always faces perpendicular to the path it follows, rather than allowing users to adjust the camera target with the mouse as in the original f ...

Numerous Axios GET calls made by various components

I am facing an issue where I have two different components rendering on the main screen. Both of them make multiple axios.get requests to fetch data. However, upon initial page load, only the last component successfully retrieves the data while the first c ...

What is the best way to assign values to an array within a loop?

I've been struggling to figure out how to set the value of an array inside a loop... Below, you can see that I'm fetching some data from a database and iterating through it. The process I'm attempting to describe can be summarized as follo ...

Craft a dynamic countdown timer that blinks using CSS

I am attempting to design a blinking countdown timer that starts at 5 seconds and disappears when it reaches 0. CSS: .blinky { transition: 1s opacity; -moz-transition: 1s opacity; -webkit-transition: 1s opacity; } HTML: <div id="count ...

The final input is the only one that functions

I am currently working on a large form, but I am encountering a major issue with it. In certain sections of the form, only the last input field seems to be functional. For example: [...] <div class="main_data"> <span class="info">main dat ...

Next.js - Anticipated that the server HTML would include a corresponding <div> within <div> tag

For a live demonstration, please click here In my current project, I am experimenting with creating a simple layout that adjusts based on the user's screen size. Specifically, on mobile devices, only the latest posts should be displayed. On desktops, ...

Could someone review my coding syntax in JavaScript for utilizing indexOf, split, and looping through multiple inputs to paste the splits?

As someone who is self-taught and codes part-time as a hobby, I am currently working on building a JavaScript/jQuery tool. This tool will allow users to copy rows or columns from Excel and paste them into an online HTML form consisting of a grid of <tex ...

React beautiful dnd and Material UI list encountering compatibility problem

I recently encountered an issue while using react beautiful dnd to create a rearrangeable Material UI List. Everything was working correctly, except for the ListItemSecondaryAction within the list. When dragging a list item, the ListItemText and ListItemIc ...

In JavaScript, it is not possible to retrieve the maximum or minimum value of an array

Hey there! I'm having some trouble finding the minimum and maximum values in an array. Can you help me figure out what's going on with my code? var repeated, studentsArray = [], marksArray = []; while (repeated !== 'n' && r ...

Ways to retrieve a converted document using the Microsoft Graph API

I'm encountering an issue when trying to save a PDF file received from the Microsoft Graph API. The call I am making looks like this: const convertConfig = { headers: { Authorization: <my token> } }; convertConfig.headers['C ...