before_destroy callback not stopping record from being deleted

In Rails 5 you have to throw :abort otherwise it won’t work. (even returning false) Also, you should add prepend: true to the callback, to make sure it runs before the dependent: :destroy on the parent models. Something like this should work: class Something < ApplicationRecord before_destroy :can_destroy?, prepend: true private def can_destroy? if model.something? … Read more

Pros & cons of a callback (std::function/std::bind) vs an interface (abstract class)

I strongly prefer the first way for several reasons: Representing concepts/functionality via interfaces/class hierarchies makes the code base less generic, flexible, and then more difficult to mantain or scale in the future. That kind of design imposes a set of requirements on the type (the type implementing the required functionality) which makes it difficult to … Read more

What is “done” callback function in Passport Strategy Configure “use” function

done is a method called internally by the strategy implementation. Then it navigates you, as you can see, to one of the success / error / fail methods (again, by the implementation. there are more options). Each of these options may calls to the next, where in your snippet code is the following: function(req, res) … Read more

How can I run a JavaScript callback when an image is loaded?

.complete + callback This is a standards compliant method without extra dependencies, and waits no longer than necessary: var img = document.querySelector(‘img’) function loaded() { alert(‘loaded’) } if (img.complete) { loaded() } else { img.addEventListener(‘load’, loaded) img.addEventListener(‘error’, function() { alert(‘error’) }) } Source: http://www.html5rocks.com/en/tutorials/es6/promises/

How to check if a method argument of a directive is specified in AngularJS?

Using ‘&?’ returns undefined if the attribute has not been set. ‘&’ = callback function is defined always. ‘&?’ = callback function is defined only when attribute is defined in html template. bindToController: { callback: ‘&?’ }, controller: function() { if (this.callback === undefined) { // attribute “callback” was not defined } } Note: Works … Read more

How to pass callback in Flutter

This is a more general answer for future viewers. Callback types There are a few different types of predefined callbacks: final VoidCallback myVoidCallback = () {}; final ValueGetter<int> myValueGetter = () => 42; final ValueSetter<int> myValueSetter = (value) {}; final ValueChanged<int> myValueSetter = (value) {}; Notes: VoidCallback is an anonymous function that takes no arguments … Read more