callback
Callback functions in Java
Is there a way to pass a call back function in a Java method? The behavior I’m trying to mimic is a .Net Delegate being passed to a function. I’ve seen people suggesting creating a separate object but that seems overkill, however I am aware that sometimes overkill is the only way to do things. … Read more
Defining TypeScript callback type
I’ve got the following class in TypeScript: class CallbackTest { public myCallback; public doWork(): void { //doing some work… this.myCallback(); //calling callback } } I am using the class like this: var test = new CallbackTest(); test.myCallback = () => alert(“done”); test.doWork(); The code works, so it displays a messagebox as expected. My question is: … Read more
Subscribe is deprecated: Use an observer instead of an error callback
When I run the linter it says: subscribe is deprecated: Use an observer instead of an error callback Code from this angular app: this.userService.updateUser(data).pipe( tap(() => {bla bla bla}) ).subscribe( this.handleUpdateResponse.bind(this), this.handleError.bind(this) ); Don’t know exactly what should I use and how… Thanks! 8 Answers 8
How to remove all callbacks from a Handler?
I have a Handler from my sub-Activity that was called by the main Activity. This Handler is used by sub-classes to postDelay some Runnables, and I can’t manage them. Now, in the onStop event, I need to remove them before finishing the Activity (somehow I called finish(), but it still call again and again). Is … Read more
When to use React setState callback
When a react component state changes, the render method is called. Hence for any state change, an action can be performed in the render methods body. Is there a particular use case for the setState callback then? 5 Answers 5
jQuery pass more parameters into callback
Is there a way to pass more data into a callback function in jQuery? I have two functions and I want the callback to the $.post, for example, to pass in both the resulting data of the AJAX call, as well as a few custom arguments function clicked() { var myDiv = $(“#my-div”); // ERROR: … Read more
Rails: #update_attribute vs #update_attributes
obj.update_attribute(:only_one_field, ‘Some Value’) obj.update_attributes(field1: ‘value’, field2: ‘value2’, field3: ‘value3’) Both of these will update an object without having to explicitly tell ActiveRecord to update. Rails API says: update_attribute Updates a single attribute and saves the record without going through the normal validation procedure. This is especially useful for boolean flags on existing records. The regular … Read more
Callback after all asynchronous forEach callbacks are completed
As the title suggests. How do I do this? I want to call whenAllDone() after the forEach-loop has gone through each element and done some asynchronous processing. [1, 2, 3].forEach( function(item, index, array, done) { asyncFunction(item, function itemDone() { console.log(item + ” done”); done(); }); }, function allDone() { console.log(“All done”); whenAllDone(); } ); Possible … Read more
What is the purpose of willSet and didSet in Swift?
Swift has a property declaration syntax very similar to C#’s: var foo: Int { get { return getFoo() } set { setFoo(newValue) } } However, it also has willSet and didSet actions. These are called before and after the setter is called, respectively. What is their purpose, considering that you could just have the same … Read more