Skip to content

Instantly share code, notes, and snippets.

View viniciusdacal's full-sized avatar

Vinicius Dacal viniciusdacal

View GitHub Profile
{
type: ['TODO_ADD_REQUEST', 'TODO_ADD_RESPONSE']
meta: {
url: 'path/to/to-do',
method: 'post',
},
payload: {
description: 'Create post about ARC',
date: '2017-08-01',
},
import { createApiActions } from 'redux-arc';
const { creators, types } = createApiActions('todo', {
read: { url: 'path/to/to-do/:id', method: 'get' },
update: { url: 'path/to/to-do/:id', method: 'put' },
otherDynamicUrl: { url: 'path/to/to-do/:id/:anotherParam', method: 'get' },
});
store.dispatch(creators.read({ id: 1 }));
import { types } from './arcs';
const INITIAL_STATE = {
readResult: null,
readError: null,
isLoading: false,
};
function todoReducer(state = INITIAL_STATE, action) {
if (action.type === types.READ.REQUEST) {
import { createApiActions } from 'redux-arc';
const { creators, types } = createApiActions('todo', {
add: { url: 'path/to/to-do' method: 'post' },
list: { url: 'path/to/to-do' method: 'get' },
read: { url: 'path/to/to-do/:id' method: 'get' },
update: { url: 'path/to/to-do/:id' method: 'put' },
delete: { url: 'path/to/to-do/:id' method: 'delete' },
});
import axios from 'axios';
import { createAsyncMiddleware } from 'redux-arc';
const asyncTask = store => done => (options) => {
const { method, url, payload } = options;
const params = method === 'get' ? { params: payload } : payload;
axios[method](url, params).then(done);
};
const asyncMiddleware = createAsyncMiddleware(asyncTask);
import { policies, createApiActions } from 'redux-arc';
function anyPolicy() {
return done => (action, error, response) => {
done(action, error, response);
};
}
anyPolicy.applyPoint = 'beforeRequest';
policies.register('anyPolicy', anyPolicy);
import { policies } from 'redux-arc';
import cloneDeep from 'lodash.clonedeep';
function createOrUpdate() {
return done => (action, error, response) => {
const newAction = cloneDeep(action);
if (newAction.payload.id) {
newAction.meta.url = `${newAction.meta.url}/${newAction.payload.id}`;
newAction.meta.method = 'put';
import { createApiActions } from 'redux-arc';
import './createOrUpdate';
const { creators, types } = createApiActions('todo', {
save: {
url: 'path/to/to-do',
method: 'post',
policies: ['createOrUpdate'],
},
});
@viniciusdacal
viniciusdacal / vendors.js
Created October 10, 2017 18:52
ng-react-vendors
require('angular');
require('angular-resource');
// ...other dependencies
window.moment = require('moment');
window.$ = require('jquery');
window.jquery = window.$;
window.jQuery = window.$;