Skip to content

Instantly share code, notes, and snippets.

@KirillSuhodolov
KirillSuhodolov / callbacks.rb
Last active October 6, 2017 23:07
How I Learned to Stop Worrying and Love the Command Pattern
# looks like command to Create/Update/Delete(Publish, Reject and etc) and Query object
class Post < ActiveRecord::Base
before_validate :build_from_template # if update don't run
before_create :check_content_uniq # extremely long time also don't run on update
after_update :send_notification # sometimes don't run
after_create :add_editor # sometimes don't run, can touch another record that has callbacks too :D
after_save :broadcast # sometimes don't run
after_create :run_indexing # sometimes don't run
private
@KirillSuhodolov
KirillSuhodolov / actions remoteData.js
Last active February 16, 2016 04:00
Redux remote data flow implementation example
import rest from 'helpers/rest';
function initiateEntityRequest(requestType, entityName, requestParams) {
return {
type: `REQUEST_ENTITY_${R.toUpper(requestType)}_${R.toUpper(entityName)}`,
requestParams,
requestType,
entityName,
isRemoteDataAction: true,
isPending: true,