...by native event listeners: let $element = $('.foo') $element.on('change', event => console.log('I will be called')) $element[0].addEventListener('change', event => console.log("I WON'T be called")) $element.trigger('change')
...event listeners (Element#addEventListener()): let $element = $('.foo') $element.on('change', event => console.log('I will be called')) $element[0].addEventListener('change', event => console.log('I will also be called')) let event = new CustomEvent...
...let the page jump to the top when the link is clicked, unless you call preventDefault on the event. This is probably not what you want. Do something with js...
...the array of methods. @user.methods.grep /name/ # => [:name, :first_name, :last_name] You can also call #private_methods or #public_methods. To find only relevant methods, it is suggested to subtract...
...that RequestStore just uses Thread.current under the hood and injects a Rack middleware that calls RequestStore.clear! after each request. If you use RequestStore in a non-request context where (like...
JavaScript objects can have getter and setter functions that are called when a property is read from or written to. For example, if you'd like an object that has...
...Performance considerations Read and write accesses have the same performance characteristics of regular function calls, so it's slower than a dumb property...
...You can configure the maximum number of connections for each Rails process. This is called the size of your connection pool. The default pool size is 5. You can configure...
...mechanisms above, you can explicitely release the connection from your thread. To do so, call clear_active_connections! before your thread terminates: Thread.new do begin User.first # first database access makes...
...Make sure no developer has gone into a rabbit hole and is afraid to call for help Give everyone an idea what's currently going on
...convert your CoffeeScript source to modern JavaScript. Install decaffeinate globally: npm install -g decaffeinate Call decaffeinate on each .coffee file, relaxing some options to get the most modern (and concise...
...an ActionDispatch::Request::Session object. class MyMiddlware def initialize(app) @app = app end def call(env) status, headers, body = @app.call(env) session = env['rack.session'] Rails.logger.info("Value of session['foo'] is...
...that table object will have the cryptic type Cucumber::Ast::Table. Don't immediately call table.raw to convert it into an array of arrays! Cucumber::Ast::Table has a lot...
...with a confusing stacktrace that looks like you have an error in your render call. If this happens to you, temporarily remove the annotation to see the correct error.
...to .test("null"). Globally matching regex objects remember the last index they matched. Multiple calls to test() will advance this pointer: matcher = new RegExp("foo", "g") // <- "global" flag matcher.test("foobar...
To catch all possible exceptions from a network call, we need to rescue many error classes like this: rescue SocketError, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EHOSTUNREACH, OpenSSL::SSL...
Example This means, that we are able to overwrite these methods or call the parent version with super depending in which order and in which way they were...
...to warn the user about unsaved changes. To trigger the alert, you have to call preventDefault() on the event. Note The beforeunload event is only dispatched when the user navigation...
...alert in Chrome < 119 You might want to return any string from the event callback as this was the mechanism to trigger the alert in older browsers You cannot use...
When changing code in mailers, updating the corresponding mailer preview can be forgotten very easily. Mailer previews can be tested...
...to express "Do this, and once you're done, do that". In contrast to callbacks, promises are easily chainable. From the readme of Q, an early implementer of the pattern...
...The callback approach is called an “inversion of control”. A function that accepts a callback instead of a return value is saying, “Don’t call me, I’ll call you...
A list of clever debugging tricks. TOC: Advanced Conditional Breakpoints monitor() class Calls Call and Debug a Function Pause Execution on URL Change Debugging Property Reads Use copy() Debugging HTML/CSS
...n\e[31mKilling Capybara session!\e[0m\n" ::Reaper.browser_died! raise end end end Call the reaper To restart the Chrome process after 50 tests, Now call StabilizeHeadlessChrome::Reaper when...
...by adding this to your Capfile: Dir.glob('lib/capistrano/tasks/*.rake').each do |r| # `import r` calls Rake.application.add_import(r), which imports the file only # *after* this file has been processed, so...
...the process to have it show its progress so far. From another terminal, simply call (be root or use sudo): pkill -USR1 dd This makes dd write something like this...
...without a dev server When you don't have a dev server running and call any helper that accesses asset paths (e.g. javascript_pack_tag or image_tag), Rails will...
...a way to mitigate the damage. When you tell Webpacker to compile You can call bin/webpack explicitely to compile files to public/packs. When deploying with Capistrano this is done automatically...
Debouncing a method call delays its execution until after a specified time has passed. If it's called again before that time has passed, its execution is delayed again.
...Here is a small JavaScript function that you can use for that: function debounce(callback, delay) { let timer return function(...args) { clearTimeout(timer) timer = setTimeout(() => { callback.apply(this, args) }, delay) } }
...module directives in place (require / export) Webpack replaces require and export directives with function calls to a Webpack-provided module registry. Webpack bundles everything into a single large file