Bacon.js and awaiting AJAX response - bacon.js

I've been trying to get something like the following working:
var showAjaxIndicator = ajaxRequest.awaiting(ajaxResponse)
What I'm seeing however is that showAjaxIndicator will finish on true -- I do not see a final false when the request has finished / ended.
Here's a JSFiddle of what I'm doing: http://jsfiddle.net/umx2sjsj/2/
What am I missing here?

I think your problem is with Bacon.once - it works synchronously which is different from normal streams. This is often the problem when you are trying stuff out in jsfiddle.
I forked your fiddle to a new one with Bacon.later(0, call) instead of Bacon.once(call), this solves the problem.
JsFiddle: http://jsfiddle.net/wbf8v39k/

Related

Cypress contains and cy.wait()

I've got some problem with Cypress and wait command:
I am using similar to this code:
const counter = cy.get('something')
counter.contains('0') //OK
const container = cy.xpath('something multiple').children()
container.click({multiple:true})
//cy.wait(200)
counter.contains('3') //NOK
Only when I am using cy.wait() this code works. I've tried to use the internaltimeout for this code and
it's not working. Only works when using cy.wait.
It is not recommended to save Elements in variables, please use Alise instead.
cy.get('something').as('counter');
cy.get('#counter') .....
Read the documentation for your reference:
https://docs.cypress.io/guides/core-concepts/variables-and-aliases.html
#HatemHatamleh is correct about not using the return value.
With cy.*() commands you are defining command execution steps, which will run separately from the JS in the tests.
Inserting cy.wait() kind-of works because it allows time for the commands to execute, but it's not at all the correct thing to do as it can fail depending on cpu load, async calls, etc.
Think of commands as a separate "thread", try to define them with chaining, but when that's not possible use alias' as #HatemHatamleh suggests.

How to pass the background response value of the to another feature json in function value using Karate

I have got the response in the background to one of the request and passing to the function for polling purpose and need to run until specific condition met. In that function, I need to pass the values to the calling feature JSON file
while (true) {
var result = karate.call('extractProgress.feature') packageid; -- package id
is response of another request
I followed the similar way as mentioned but in that not passing any parameter.
https://github.com/intuit/karate/blob/933d3803987a736cc1a38893e7039c4b5e5132fc/karate-demo/src/test/java/demo/polling/polling.feature
But i am getting the below error
feature(com.intuit.karate.testng.KarateTestngTest):
java.lang.RuntimeException: javascript evaluation failed: packageid,
ReferenceError: "packageid" is not defined in at line number 1
Input for call inside js should be given as
karate.call("<featureFile>",yourInputVaraible);
refer this on doc
https://github.com/intuit/karate#the-karate-object
It sounds wrong to me, maybe you have a typo.
Also please read the docs carefully. Only JSON is supported as a call argument.
The best way for you to get support is to follow this process, else no one can help you with the limited info you seem to be providing in your questions.
https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

DataTables FixedColumn Destroy not working

I've got a strange issue with DataTables and destroy. I am using version 1.10.3 (but also tried 1.10.7) and fixedColumns Plugin (3.0). When I want to destroy the table I get an error in the plugin:
Uncaught TypeError: $(...).fn is not a function
My init looks like this:
fulltable = $('#auditplan_table_fs').dataTable();
and the destroy
fulltable.fnDestroy();
but I've also tried to initalize via .DataTable() and destroy via .api().destroy() or .destroy() which leads to the same result. Any possible solution would be appreciated.
UPDATE:
As it seems it isn't a problem with FixedColumns, here is some more information. I'm calling the dataTable in an ajax success like this:
$('#auditplan_table_fs').append(responseData.findinglist.html);
fulltable = $('#auditplan_table_fs').dataTable({
scrollY: newheight,
scrollX: true,
scrollCollapse: true,
"bSort": false,
paging: false
});
new $.fn.dataTable.FixedColumns(fulltable);
In a document change function (when I select some values from a dropdown) I try to destroy the table like I posted before and then call the ajax function again.
The fulltable variable is defined in my document ready, the assignment happens, as already told, in my success function. When I print out the variable right before the destroy, everything seems to be fine.
UPDATE: It seems to be a bug in fixedColumns itself. I found out I am using 3.0.0 and the newest version is 3.0.4. With this one, I passed the first error and come up with a new one. I now get stuck in Line 1107:
Uncaught TypeError: Cannot read property 'anCells' of undefined
I suppose it has to do something with my init in an ajax call.
LAST UPDATE: Ok, I was to fast. It was only a caching problem. With the new version, everything is working fine.
If you do:
jQuery
DataTables
jQuery
The second jQuery will overwrite the first one (which has DataTables attached to it). Thus, you would end up with a jQuery object that doesn't have DataTables available.
Bit frustrating that jQuery doesn't give an error about being loaded twice as it bites a lot of people
Reference

How to flush current output in RApache?

I'm testing using RApache as an SSE (Server Sent Events) and similar (long poll, comet, etc.) back-end. I seem to be stuck on how to flush my output. Is it possible?
Here is my test R script:
setContentType("text/plain")
repeat{
cat(format(Sys.time()),"\n")
#sendBin(paste(format(Sys.time()),"\n"))
flush(stdout())
Sys.sleep(1)
}
My Rapache.conf entry is:
<Location /rtest/sse>
Options -MultiViews
SetHandler r-handler
RFileHandler /var/www/local/rtest/sse.r
</Location>
And I test it using either wget or curl:
wget -O - http://localhost/rtest/sse
curl http://localhost/rtest/sse
Both just sit there, meaning nothing is being sent.
Using sendBin() made no change, and neither did using flush().
If I change repeat to for(i in 1:5) then it sits there for 5 seconds and then shows 5 timestamps (spaced one second apart). So, I believe everything else is working fine and this is purely a buffering issue.
UPDATE: Looking at this with fresh eyes after 5 months, I think I could have described the problem more clearly: the problem is that RApache appears to be buffering all the output, and not sending anything until the R script exits. To be useful for streaming it has to send data out of Apache and on to the client each time flush() is called, i.e. while the R script is still running.
So, my question is: is there a way to get RApache to behave like that?
UPDATE 2 I tried adding flush.console() before or after the flush(stdout()) but no difference. I also tried setStatus(status=200L) at the top. And I tried SERVER$no_cache=T;SERVER$no_local_copy=T; at the top of the script. Again it made no difference. (Yes, none of those should have helped, but it never hurts to try!)
Here is a link to how PHP implements flush when it is running as an Apache module:
http://git.php.net/?p=php-src.git;a=blob;f=sapi/apache2handler/sapi_apache2.c#l290
I think the key point is that there is a call to ap_rflush(r). I'm guessing that RApache is not making the ap_rflush() call.
You are passing the wrong MIME type. Try changing with
setContentType("text/event-stream")
EDIT1:
this is the attempt, (still unsuccessful) I mentioned in the comment below, to implement SSE in Rook.
<%
res$header('Content-Type', 'text/event-stream')
res$header('Cache-Control', 'no-cache')
res$header('Connection', 'keep-alive')
A <- 1
sendMessage <- function(){
while(A<=4){
cat("id: ", Sys.time(), "\n", "data: hello\n\n", sep="")
A <- A+1
flush(stdout())
Sys.sleep(1)
}
}
-%>
<% sendMessage() %>
the while loop condition was supposed to be always TRUE but I'm having your same problem so I had to do a finite loop...
The good new is I DO have data reaching the browser. I can tell by looking, in developer tools, at the Content-Length in the Response Header section. it says 114 for the above code and you change, say, "Hello" in "Hello!" it'll say 118.
The js code is: (you'll need JQuery as well)
$(document).ready(function(){
$("button").click(function(){
var source = new EventSource("../R/sse.Rhtml");
source.onopen = function(event){
console.log("readyState: " + source.readyState);
}
source.onmessage = function(event){
$("#div").append(event.data);
};
source.onerror = function(event){
console.log(event);
};
});
});
So, in essence
1) The connection is open (readyState 1)
2) Buffering is still there
3) Data (after buffering) reaches the browser but an error happens in receiving them properly.
EIDT2:
it's interesting to note that brew()ing the above .Rhtml file the output is not buffered. There must be a configuration the in the web server (both the R internal and Apache) that buffer the data flows.
As a side note, flush is not even needed, cat's output defaults to stout(). So the options are:
Web server configuration
The R equivalent of the PHP ob_flush(); which is always used in any PHP implementation I've seen. this is example

Backbone using GET instead of PUT or POST

I'm having some issues with a Backbone project that I am working on.
I have the following model:
class App.Models.Purchaseorder extends Backbone.Model
url: ->
base = 'api/purchaseorders'
if this.isNew()
base
else
base + '/' + this.id;
urlRoot: 'api/purchaseorders'
When I run the following in the console:
po = new App.Models.Purchaseorders;
po.set({'po_number': '1234', 'locale': 'Home', 'po_date': '3/22/2012'});
it appears to set the attributes correctly. However, if I run
po.save()
I would expect it to do a POST request to the api/purchaseorders URL. When I debug through the save() and sync() functions in the Backbone JS, it looks like it is indeed running a POST, but at the last minute, it looks as if it is really doing a GET http://i.imgur.com/dQK88.png
I am a little confused as to why this would be happening. I am having similar issues when trying to do an update -- which should be doing a PUT. I am assuming something is funky in the model, but I have no clue what it could be.
Any help would be greatly appreciated.
Thanks!
I tested the code you have in the question (had to call new App.Models.Purchaseorder, without the s, though FYI) and it does a POST as expected.
What version of Backbone and Underscore are you using?
Here's a fiddle.