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

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