Skip to content

Instantly share code, notes, and snippets.

# Put this in the controller
def filters_for_this_action
_process_action_callbacks.select do |filter|
ifs = filter.options[:if].first || 'true'
unlesses = filter.options[:unless].first || 'false'
eval(ifs) && !eval(unlesses)
end.map { |filter| [filter.kind, filter.filter] }
end
@jameskerr
jameskerr / reduxModel.ts
Last active November 23, 2020 19:16
Redux Model
/* This could be a way to reduce (haha) the redux boilerplate. */
import {createStore} from "redux"
function createReduxModel(prefix, config) {
const actionType = (name) => `${prefix}_${name.toUpperCase()}_SET`
class Model {
constructor(store) {
for (const [name] of Object.entries(config)) {
@jameskerr
jameskerr / react-debut.tsx
Created September 9, 2023 03:11
React Debut: A component for animating elements in an out as they mount and unmount.
import {CSSTransition} from "react-transition-group"
import {forwardRef, useImperativeHandle, useRef, useState} from "react"
import {call} from "src/util/call"
export function useDebut(args: {enter?: () => any; exit: () => any}) {
const ref = useRef<any>()
const api = {
props: {
ref,
onExit: args.exit,