Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jamesplease's full-sized avatar
🍕
yum

James Please jamesplease

🍕
yum
  • USA
View GitHub Profile
import {Resource, State} from 'simple-resource-components';
return (
<Resource names={['request', 'movie']}>
<div className="movieTitle">
<State for="movie" type="loading" component={LoadingComponent}/>
</div>
<div className="requestDetail">
<State for={['request', 'movie']} type="loading" component={LoadingComponent}/>
</div>
@jamesplease
jamesplease / multi.sql
Last active March 19, 2017 19:02
Upsert in Postgres. Will create nonexistent rows so not so useful for relationship updates
INSERT INTO the_table (id, column_1, column_2)
VALUES (1, 'A', 'X'), (2, 'B', 'Y'), (3, 'C', 'Z')
ON CONFLICT (id) DO UPDATE
SET column_1 = excluded.column_1,
column_2 = excluded.column_2;
{
"person": {
"name": "Please",
"age": 24
}
}
import { xhrStatuses } from 'redux-simple-resource';
function findResourceById({ state, resourceName, idAttribute = 'id', id }) {
return state[resourceName].resources.filter(r => r[idAttribute] === id);
}
function checkReadManyStatus({ state, resources, status, every, includeNull }) {
const check = every ? 'every' : 'some';
let arrayResources = resources instanceof Array ? resources : [resources];
return resources
export class App extends Component {
render() {
const { store } = this.props;
return (
<Provider store={store} key="provider">
<Route for="dashboard" component={DashboardPage}/>
<Route for="notFound" component={NotFoundPage}/>
</Provider>
);
combineStatuses({
state,
every: true,
statuses: [
{
action: 'read',
resourceName: 'movies',
id: 23
}
]
@jamesplease
jamesplease / 1.README.md
Last active June 22, 2017 15:23
Canceling XHR requests

tl;dr

Always cancel your XHR requests before firing a new one. It solves lots of bugs.

How to do it

The native XHR object has an abort method. Use a library that either gives you access to the xhr object, or wraps it with some other system for aborting.

Then,

asdasd