How to resumeOnError (or similar) in RxJS5 - rxjs5

I would like to use the onErrorResumeNext feature of RxJS, i.e. to continue to receive events even if an error is received (instead of terminating).
But I can see in the following doc that there is no correspondance in RxJS5: https://github.com/ReactiveX/RxJS/blob/master/MIGRATION.md.
Is there a workaround to use such feature?
Thanks!

I've been looking for that operator too! I came up with a solution for my needs that I hope will help yours. It's not the best solution most likely, but I hope it can help until a better solution can be found by some others on here, or until this operator is added back in 5.0 (hopefully!) :)
var Observable = Rx.Observable;
var source1 = Observable.create(function(observer){
observer.error();
});
var source2 = Observable.create(function(observer){
observer.next('Continuing on');
observer.complete();
});
var stream = source1.catch(function(data){
return source2;
});
stream.subscribe(function(data){
console.log(data);
});
JS Bin Example: https://jsbin.com/qadozoveta/edit?html,js,console

You can use the following in rxjs5 still.
Observable.onErrorResumeNext(observable1$, observable2$, observable3$...)
.subscribe(() => { ... })
onErrorResumeNext source code

Related

Problems with multiple dropzone instances

I try to insert two dropzones (http://www.dropzonejs.com/), but I always get "Uncaught Error: Dropzone already attached."
Here is my Code. Can anybody help me.
$(document).ready(function () {
Dropzone.autoDiscover = false;
$("#DropzoneTarget_1").dropzone({url: "...."});
$("#DropzoneTarget_2").dropzone({url: "...."});
});
Thanx and greeds
I experienced the same issue if running the same code multiple times.
Prevent this error by destroying the Dropzone object instance, so only 1 instance exists at a time.
if (myDropzone1 != undefined) {
Dropzone.forElement("#DropzoneTarget_1").destroy();
}
var myDropzone1 = $("#DropzoneTarget_1").dropzone({url: "...."});
Maybe you have 'dropzone' class on yours '#DropzoneTarget_1' and '#DropzoneTarget_2'. Remove it and your code will work.
If you need default styles just config yours dropzones with
Dropzone.options.dropzoneTarget1 = {/*option:value*/}
Dropzone.options.dropzoneTarget2 = {/*option:value*/}
Remove "dropzone" class didnĀ“t work, but this solved my problem
$(document).ready(function () {
Dropzone.autoDiscover = false;
$(".dropzone").each(function () {
new Dropzone($(this).get(0), {url: "...."});
});
});
Thanks for your help.

Is this correct about Jasmine's word order?

In my newbie understanding, Jasmine provide this syntax below:
describe('FooBar', function(){
it('should blah-blah', function(){
expect('actual').toEqual('expect');
});
});
expect('actual').toEqual('expect');
This order and words causes my confusion. Is my understanding correct?
Yes, you are correct. To rephrase:
...
expect("result").toEqual("expected");
...

Jquery Event Listener for javascript objects

I apologize if this has been asked before but, is there a way to add an event listener/handler to a Javascript object? Preferably using JQuery.
Such as:
var foo;
$(foo).bind('change', function() {
alert("Foo has changed!");
});
I have tried this, but nothing seems to happen. Does this only work with DOM elements?
EDIT:
I need an event fired every time that the audio or video tags throw an error. Originally, I was using an interval to check whether or not the error, 'media.error', object was null, but this uses excess processing power and I would like to avoid it.
EDIT 2: Apparently I was going about it wrong, easiest way I found was to add the "onerror" property to the video/audio tag.
I agree with Cheeso that it's more important for you to state what you actually want to do, however one workaround for your specific question could be to store your variable within an object and only provide access through getter / setter, then you can do what you want in the setter. e.g.
function data() {
var foo = 0;
this.setFoo = function(newVal) {
foo = newVal;
alert(foo);
};
}
var theData = new data();
theData.setFoo(5);
Yes, that's correct. You cannot make a "variable watcher". There is no event fired for variables when they are changed.
What are you really trying to do?
You could try:
http://higginsforpresident.net/js/static/jq.pubsub.js
See
http://weblog.bocoup.com/publishsubscribe-with-jquery-custom-events
Or use a framework like backbone/underscore or knockout.js.
HTML/Elements/audio
var foo;
$(foo).bind('error', function() {
//your code here
});

making jQuery plug-in autoNumeric format fields by time page loads

I've been messing around with autoNumeric, a plug-in for jQuery that formats currency fields.
I'd like to wire the plug-in so that all currency fields are formatted by the time the user sees the page, e.g., on load.
Currently, the default that I can't seem to get around is that fields are formatted upon blur, key-up or other action in the fields themselves.
I've been experimenting with the plug-in code and it looks like it will take this relative newcomer some time to resolve this, if at all.
Anybody on this?
Lille
Triggering 'focusout' event formats the field. Triggering 'change' does not work in the most recent version (1.7.4).
$('input.money').autoNumeric({aNeg: '-'}).trigger('focusout');
autoNumeric does all formatting after 'onchange' event fires. So all that you need is to programmatically fire this event. Like this:
$('input.money').autoNumeric({aNeg: '-'}).trigger('change');
Hope this helps!
I just ran into this problem myself. I had to make it more general, but this worked for me:
$('input.auto-numeric').ready(function(){
var format_options = {
aSign: '$'
};
$('input.auto-numeric').each(function(){
$(this).autoNumeric(format_options);
if($(this).attr('id')){
$(this).val($.fn.autoNumeric.Format($(this).attr('id'), $(this).val(), format_options));
}
});
});
This should work.
jQuery(function($) {
$('input.auto').ready(function(){
$('input.auto').autoNumeric();
var inputID = uniqueID; // use the jQuery.get() function to retrieve data
var formatValue = '1234.00'; // use the jQuery.get() function to retrieve data
if(jQuery().autoNumeric){
$('#id').val($.fn.autoNumeric.Format(inputID, formatValue));
}
else{
alert('plugin not available');
}
});
});
Bob
This is what I eventually did:
$(document).ready(function(){
$('input.auto').autoNumeric();
$('input.auto').each(function(){
var element = this
if(element.value !=""){
$('#'+element.id).val($.fn.autoNumeric.Format(element.id, element.value));
}
}
);
});
Another way of forcing formatting is using 'update' like
$(".input-numeric").autoNumeric('update');
In the current version 2.* and onward, this is done by default thanks to the formatOnPageLoad option that is set to true.
It's that simple ;)

Using SortableRows and know when rows have been moved

I want to take advantage of the sortableRows property of the jqGrid. How do I detect when a row has been moved. I have studied the documentation and looked for examples but haven't found much. I do believe it is something like
jQuery("#grid").sortableRows({connectWith:'#gird',
ondrop: function(){ alert("row moved") }});
but that does not work. I can move the rows, but don't seemed to have trapped the event. Is there something wrong with my syntax or my approach in general.
Basically, I need to know that the rows have been rearranged so I can be sure they get saved with their new order.
Thanks
jqGrid uses the ui-sortable plugin to sort rows: http://jqueryui.com/demos/sortable/.
In
jQuery("#grid").sortableRows( options )
"options" is the passed to the sortable plugin.
options = { update : function(e,ui){} }
is what you want.
Attach the sortstop event handler to your grid:
jQuery("#grid").bind('sortstop', function(event, ui) { alert("row moved") });
I did a quick test and that worked for me.
jQuery('#'+grid_id).jqGrid('sortableRows', {
update: function (event, ui) {
var newOrder = $('#'+grid_id).jqGrid("getDataIDs");
//do whatever you want with new roworder
//please keep in mind this will give only page visible rows
}
});

Resources