This file contains hidden or 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
| { | |
| 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', | |
| }, |
This file contains hidden or 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 { 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 })); |
This file contains hidden or 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 { types } from './arcs'; | |
| const INITIAL_STATE = { | |
| readResult: null, | |
| readError: null, | |
| isLoading: false, | |
| }; | |
| function todoReducer(state = INITIAL_STATE, action) { | |
| if (action.type === types.READ.REQUEST) { |
This file contains hidden or 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 { 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' }, | |
| }); |
This file contains hidden or 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 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); |
This file contains hidden or 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 { policies, createApiActions } from 'redux-arc'; | |
| function anyPolicy() { | |
| return done => (action, error, response) => { | |
| done(action, error, response); | |
| }; | |
| } | |
| anyPolicy.applyPoint = 'beforeRequest'; | |
| policies.register('anyPolicy', anyPolicy); |
This file contains hidden or 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 { 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'; |
This file contains hidden or 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 { createApiActions } from 'redux-arc'; | |
| import './createOrUpdate'; | |
| const { creators, types } = createApiActions('todo', { | |
| save: { | |
| url: 'path/to/to-do', | |
| method: 'post', | |
| policies: ['createOrUpdate'], | |
| }, | |
| }); |
This file contains hidden or 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
| require('angular'); | |
| require('angular-resource'); | |
| // ...other dependencies |
This file contains hidden or 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
| window.moment = require('moment'); | |
| window.$ = require('jquery'); | |
| window.jquery = window.$; | |
| window.jQuery = window.$; |