This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationComponent < ViewComponent::Base | |
private | |
def fetch_with_fallback(hash, key, fallback) | |
hash.fetch(key) do | |
ErrorReporting.capture_exception(%(key not found: "#{key}")) | |
fallback | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION comments_count_update() | |
RETURNS TRIGGER AS $$ | |
BEGIN | |
-- Increase count on insert | |
IF (TG_OP = 'INSERT') THEN | |
UPDATE posts SET comments_count = comments_count + 1 | |
WHERE posts.id = NEW.post_id; | |
RETURN NEW; | |
-- Decrease count on delete | |
ELSIF (TG_OP = 'DELETE') THEN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The most complex part of the modal system | |
// There are lot of small details heres | |
// I extracted this from a real project | |
// Notice: Hooks hide a lot of complexity | |
import { IModalOpen } from './types'; | |
import { closeModal } from './triggers'; | |
import { useEffect, useMemo, useRef, useState } from 'react'; | |
import { useEventBus } from '../eventBus'; | |
import { InsideModalProvider } from './context'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
import mitt from 'mitt'; | |
interface IEventsMap { | |
modalOpen: { | |
content: React.ReactNode; | |
url?: string; | |
}; | |
modalClose: null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Controller < ActionController::Base | |
include DevelopmentLogging if Rails.env.development? | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# Complex counter counter caches | |
# | |
# Usage: | |
# | |
# In parent model | |
# class Post < ApplicationRecord | |
# ExplicitCounterCache.define(self, votes_count, -> { votes.active }) | |
# ExplicitCounterCache.define(self, comments_count, -> { votes.visible }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# Note(rstankov): | |
# | |
# **Don't use for `connection`s, only for `field` attributes** | |
# | |
# Preload associations. | |
# | |
# Supports all preload formats from [ActiveRecord::Base.includes](https://api.rubyonrails.org/v5.2.4/classes/ActiveRecord/QueryMethods.html#method-i-includes). | |
# |
NewerOlder